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.
22 #include "AnimationFactory.h"
23 #include "Interface.h"
26 AnimationFactory::AnimationFactory(const char* ResRef
)
27 : FactoryObject( ResRef
, IE_BAM_CLASS_ID
)
34 AnimationFactory::~AnimationFactory(void)
36 for (unsigned int i
= 0; i
< frames
.size(); i
++) {
37 core
->GetVideoDriver()->FreeSprite( frames
[i
] );
42 // FIXME: track down where sprites are being leaked
44 fprintf(stderr
, "AnimationFactory %s has refcount %d\n", ResRef
, datarefcount
);
45 //assert(datarefcount == 0);
51 void AnimationFactory::AddFrame(Sprite2D
* frame
)
53 frames
.push_back( frame
);
56 void AnimationFactory::AddCycle(CycleEntry cycle
)
58 cycles
.push_back( cycle
);
61 void AnimationFactory::LoadFLT(unsigned short* buffer
, int count
)
66 //FLTable = new unsigned short[count];
67 FLTable
= (unsigned short *) malloc(count
* sizeof( unsigned short ) );
68 memcpy( FLTable
, buffer
, count
* sizeof( unsigned short ) );
71 void AnimationFactory::SetFrameData(unsigned char* FrameData
)
73 this->FrameData
= FrameData
;
77 Animation
* AnimationFactory::GetCycle(unsigned char cycle
)
79 if (cycle
>= cycles
.size()) {
82 int ff
= cycles
[cycle
].FirstFrame
;
83 int lf
= ff
+ cycles
[cycle
].FramesCount
;
84 Animation
* anim
= new Animation( cycles
[cycle
].FramesCount
);
86 for (int i
= ff
; i
< lf
; i
++) {
87 frames
[FLTable
[i
]]->acquire();
88 anim
->AddFrame( frames
[FLTable
[i
]], c
++ );
93 /* returns the required frame of the named cycle, cycle defaults to 0 */
94 Sprite2D
* AnimationFactory::GetFrame(unsigned short index
, unsigned char cycle
)
96 if (cycle
>= cycles
.size()) {
99 int ff
= cycles
[cycle
]. FirstFrame
, fc
= cycles
[cycle
].FramesCount
;
103 Sprite2D
* spr
= frames
[FLTable
[ff
+index
]];
108 Sprite2D
* AnimationFactory::GetFrameWithoutCycle(unsigned short index
)
110 if(index
>= frames
.size()) {
113 Sprite2D
* spr
= frames
[index
];
118 Sprite2D
* AnimationFactory::GetPaperdollImage(ieDword
*Colors
,
119 Sprite2D
*&Picture2
, unsigned int type
)
121 if (frames
.size()<2) {
125 Video
* video
= core
->GetVideoDriver();
126 Picture2
= video
->DuplicateSprite(frames
[1]);
131 Palette
* palette
= Picture2
->GetPalette();
132 palette
->SetupPaperdollColours(Colors
, type
);
133 Picture2
->SetPalette(palette
);
137 Picture2
->XPos
= (short)frames
[1]->XPos
;
138 Picture2
->YPos
= (short)frames
[1]->YPos
- 80;
141 Sprite2D
* spr
= core
->GetVideoDriver()->DuplicateSprite(frames
[0]);
143 Palette
* palette
= spr
->GetPalette();
144 palette
->SetupPaperdollColours(Colors
, type
);
145 spr
->SetPalette(palette
);
149 spr
->XPos
= (short)frames
[0]->XPos
;
150 spr
->YPos
= (short)frames
[0]->YPos
;
152 //don't free pixels, createsprite stores it in spr
157 void AnimationFactory::IncDataRefCount()
162 void AnimationFactory::DecDataRefCount()
164 assert(datarefcount
> 0);