1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "AnimationFactory.h"
25 #include "Interface.h"
28 AnimationFactory::AnimationFactory(const char* ResRef
)
29 : FactoryObject( ResRef
, IE_BAM_CLASS_ID
)
36 AnimationFactory::~AnimationFactory(void)
38 for (unsigned int i
= 0; i
< frames
.size(); i
++) {
39 core
->GetVideoDriver()->FreeSprite( frames
[i
] );
44 // FIXME: track down where sprites are being leaked
46 fprintf(stderr
, "AnimationFactory %s has refcount %d\n", ResRef
, datarefcount
);
47 //assert(datarefcount == 0);
53 void AnimationFactory::AddFrame(Sprite2D
* frame
)
55 frames
.push_back( frame
);
58 void AnimationFactory::AddCycle(CycleEntry cycle
)
60 cycles
.push_back( cycle
);
63 void AnimationFactory::LoadFLT(unsigned short* buffer
, int count
)
68 //FLTable = new unsigned short[count];
69 FLTable
= (unsigned short *) malloc(count
* sizeof( unsigned short ) );
70 memcpy( FLTable
, buffer
, count
* sizeof( unsigned short ) );
73 void AnimationFactory::SetFrameData(unsigned char* FrameData
)
75 this->FrameData
= FrameData
;
79 Animation
* AnimationFactory::GetCycle(unsigned char cycle
)
81 if (cycle
>= cycles
.size()) {
84 int ff
= cycles
[cycle
].FirstFrame
;
85 int lf
= ff
+ cycles
[cycle
].FramesCount
;
86 Animation
* anim
= new Animation( cycles
[cycle
].FramesCount
);
88 for (int i
= ff
; i
< lf
; i
++) {
89 frames
[FLTable
[i
]]->acquire();
90 anim
->AddFrame( frames
[FLTable
[i
]], c
++ );
95 /* returns the required frame of the named cycle, cycle defaults to 0 */
96 Sprite2D
* AnimationFactory::GetFrame(unsigned short index
, unsigned char cycle
) const
98 if (cycle
>= cycles
.size()) {
101 int ff
= cycles
[cycle
]. FirstFrame
, fc
= cycles
[cycle
].FramesCount
;
105 Sprite2D
* spr
= frames
[FLTable
[ff
+index
]];
110 Sprite2D
* AnimationFactory::GetFrameWithoutCycle(unsigned short index
) const
112 if(index
>= frames
.size()) {
115 Sprite2D
* spr
= frames
[index
];
120 Sprite2D
* AnimationFactory::GetPaperdollImage(ieDword
*Colors
,
121 Sprite2D
*&Picture2
, unsigned int type
) const
123 if (frames
.size()<2) {
127 Video
* video
= core
->GetVideoDriver();
128 Picture2
= video
->DuplicateSprite(frames
[1]);
133 Palette
* palette
= Picture2
->GetPalette();
134 palette
->SetupPaperdollColours(Colors
, type
);
135 Picture2
->SetPalette(palette
);
139 Picture2
->XPos
= (short)frames
[1]->XPos
;
140 Picture2
->YPos
= (short)frames
[1]->YPos
- 80;
143 Sprite2D
* spr
= core
->GetVideoDriver()->DuplicateSprite(frames
[0]);
145 Palette
* palette
= spr
->GetPalette();
146 palette
->SetupPaperdollColours(Colors
, type
);
147 spr
->SetPalette(palette
);
151 spr
->XPos
= (short)frames
[0]->XPos
;
152 spr
->YPos
= (short)frames
[0]->YPos
;
154 //don't free pixels, createsprite stores it in spr
159 void AnimationFactory::IncDataRefCount()
164 void AnimationFactory::DecDataRefCount()
166 assert(datarefcount
> 0);