Update of /cvsroot/gemrb/gemrb/gemrb/plugins/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29914/plugins/Core Modified Files: Actor.cpp Animation.cpp Animation.h Button.cpp CharAnimations.cpp CharAnimations.h Map.cpp Map.h Palette.cpp Log Message: move palette from animation into AreaAnimation/CharAnimations Index: Animation.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Animation.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Animation.h 28 Jan 2006 19:56:34 -0000 1.25 --- Animation.h 29 Jan 2006 13:40:19 -0000 1.26 *************** *** 29,34 **** #include <vector> - class Palette; - #ifdef WIN32 --- 29,32 ---- *************** *** 59,63 **** Region animArea; ieDword Flags; - Palette *palette; Animation(int count); ~Animation(void); --- 57,60 ---- *************** *** 68,77 **** /** Gets the i-th frame */ Sprite2D* GetFrame(unsigned int i); - /** Sets the Animation Palette */ - void SetPalette(Palette* pal, bool local); /** Mirrors all the frames vertically */ void MirrorAnimation(); - /** Calls CalculateAlpha on all frames */ - void BlendAnimation(); /** sets frame index */ void SetPos(unsigned int index); --- 65,70 ---- Index: CharAnimations.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/CharAnimations.h,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** CharAnimations.h 6 Jan 2006 18:06:25 -0000 1.38 --- CharAnimations.h 29 Jan 2006 13:40:19 -0000 1.39 *************** *** 28,31 **** --- 28,33 ---- #include <vector> + class Palette; + #ifdef WIN32 *************** *** 121,124 **** --- 123,127 ---- public: ieDword *Colors; //these are the custom color indices + Palette* palette; unsigned int AvatarsRowNum; unsigned char ArmorType, WeaponType, RangedType; *************** *** 131,135 **** static void ReleaseMemory(); void SetArmourLevel(int ArmourLevel); ! void SetupColors(Animation *anim); void SetColors(ieDword *Colors); --- 134,138 ---- static void ReleaseMemory(); void SetArmourLevel(int ArmourLevel); ! void SetupColors(); void SetColors(ieDword *Colors); Index: Palette.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Palette.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Palette.cpp 28 Jan 2006 19:56:33 -0000 1.1 --- Palette.cpp 29 Jan 2006 13:40:19 -0000 1.2 *************** *** 46,49 **** --- 46,50 ---- { Palette* pal = new Palette(col, alpha); + Release(); return pal; } Index: CharAnimations.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/CharAnimations.cpp,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** CharAnimations.cpp 28 Jan 2006 19:56:34 -0000 1.75 --- CharAnimations.cpp 29 Jan 2006 13:40:19 -0000 1.76 *************** *** 91,118 **** { Colors = arg; ! int partCount = GetPartCount(); ! for (int StanceID = 0; StanceID < MAX_ANIMS; StanceID++) { ! for (int Orient = 0; Orient < MAX_ORIENT; Orient++) { ! if (Anims[StanceID][Orient]) { ! for (int Part = 0; Part < partCount; Part++) { ! SetupColors(Anims[StanceID][Orient][Part]); ! } ! } ! } ! } } ! void CharAnimations::SetupColors(Animation *anim) { ! if (!anim->palette) { ! //this palette must be freed using videodriver ! anim->palette=core->GetVideoDriver()->GetPalette(anim->GetFrame(0)); ! } ! ! // CHECKME: currently creating a new palette for every animation, ! // while it might be possible to share a palette between animations ! Palette* pal = anim->palette->Copy(); ! anim->SetPalette(pal, true); ! pal->Release(); if (!Colors) { --- 91,101 ---- { Colors = arg; ! SetupColors(); } ! void CharAnimations::SetupColors() { ! if (!palette) ! return; if (!Colors) { *************** *** 125,129 **** for (unsigned int i = 0; i < Colors[6]; i++) { Color* NewPal = core->GetPalette( Colors[i]&255, size ); ! memcpy( &anim->palette->col[dest], NewPal, size*sizeof( Color ) ); dest +=size; free( NewPal ); --- 108,112 ---- for (unsigned int i = 0; i < Colors[6]; i++) { Color* NewPal = core->GetPalette( Colors[i]&255, size ); ! memcpy( &palette->col[dest], NewPal, size*sizeof( Color ) ); dest +=size; free( NewPal ); *************** *** 144,148 **** DataStream* s = core->GetResourceMgr()->GetResource( PaletteResRef, IE_BMP_CLASS_ID ); bmp->Open( s, true); ! bmp->GetPalette(0, 256, anim->palette->col); core->FreeInterface( bmp ); } --- 127,131 ---- DataStream* s = core->GetResourceMgr()->GetResource( PaletteResRef, IE_BMP_CLASS_ID ); bmp->Open( s, true); ! bmp->GetPalette(0, 256, palette->col); core->FreeInterface( bmp ); } *************** *** 156,181 **** Color* ArmorPal = core->GetPalette( Colors[5]&255, 12 ); Color* HairPal = core->GetPalette( Colors[6]&255, 12 ); ! memcpy( &anim->palette->col[0x04], MetalPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x10], MinorPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x1C], MajorPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x28], SkinPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x34], LeatherPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x40], ArmorPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x4C], HairPal, 12 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x58], &MinorPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x60], &MajorPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x68], &MinorPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x70], &MetalPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x78], &LeatherPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x80], &LeatherPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0x88], &MinorPal[1], 8 * sizeof( Color ) ); int i; //moved here to be compatible with msvc6.0 for (i = 0x90; i < 0xA8; i += 0x08) ! memcpy( &anim->palette->col[i], &LeatherPal[1], 8 * sizeof( Color ) ); ! memcpy( &anim->palette->col[0xB0], &SkinPal[1], 8 * sizeof( Color ) ); for (i = 0xB8; i < 0xFF; i += 0x08) ! memcpy( &anim->palette->col[i], &LeatherPal[1], 8 * sizeof( Color ) ); free( MetalPal ); free( MinorPal ); --- 139,164 ---- Color* ArmorPal = core->GetPalette( Colors[5]&255, 12 ); Color* HairPal = core->GetPalette( Colors[6]&255, 12 ); ! memcpy( &palette->col[0x04], MetalPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x10], MinorPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x1C], MajorPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x28], SkinPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x34], LeatherPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x40], ArmorPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x4C], HairPal, 12 * sizeof( Color ) ); ! memcpy( &palette->col[0x58], &MinorPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0x60], &MajorPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0x68], &MinorPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0x70], &MetalPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0x78], &LeatherPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0x80], &LeatherPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0x88], &MinorPal[1], 8 * sizeof( Color ) ); int i; //moved here to be compatible with msvc6.0 for (i = 0x90; i < 0xA8; i += 0x08) ! memcpy( &palette->col[i], &LeatherPal[1], 8 * sizeof( Color ) ); ! memcpy( &palette->col[0xB0], &SkinPal[1], 8 * sizeof( Color ) ); for (i = 0xB8; i < 0xFF; i += 0x08) ! memcpy( &palette->col[i], &LeatherPal[1], 8 * sizeof( Color ) ); free( MetalPal ); free( MinorPal ); *************** *** 223,226 **** --- 206,210 ---- { Colors = NULL; + palette = NULL; nextStanceID = 0; autoSwitchOnEnd = false; *************** *** 511,519 **** return 0; } //animation is affected by game flags a->gameAnimation = true; a->SetPos( 0 ); - SetupColors( a ); //setting up the sequencing of animation cycles --- 495,512 ---- return 0; } + + if (!palette) { + // This is the first time we're loading an Animation. + // We copy the palette of its first frame into our own palette + palette=core->GetVideoDriver()->GetPalette(a->GetFrame(0))->Copy(); + + // ...and setup the colours properly + SetupColors(); + } + //animation is affected by game flags a->gameAnimation = true; a->SetPos( 0 ); //setting up the sequencing of animation cycles Index: Button.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Button.cpp,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** Button.cpp 28 Jan 2006 19:56:34 -0000 1.96 --- Button.cpp 29 Jan 2006 13:40:19 -0000 1.97 *************** *** 44,50 **** font = core->GetButtonFont(); normal_palette = NULL; ! Palette* fontpal = font->GetPalette(); ! disabled_palette = fontpal->Copy(); ! fontpal->Release(); for (int i = 0; i < 256; i++) { disabled_palette->col[i].r = ( disabled_palette->col[i].r * 2 ) / 3; --- 44,48 ---- font = core->GetButtonFont(); normal_palette = NULL; ! disabled_palette = font->GetPalette()->Copy(); for (int i = 0; i < 256; i++) { disabled_palette->col[i].r = ( disabled_palette->col[i].r * 2 ) / 3; Index: Map.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Map.cpp,v retrieving revision 1.225 retrieving revision 1.226 diff -C2 -d -r1.225 -r1.226 *** Map.cpp 28 Jan 2006 19:56:34 -0000 1.225 --- Map.cpp 29 Jan 2006 13:40:19 -0000 1.226 *************** *** 734,738 **** video->BlitSpriteTinted( anim->NextFrame(), a->Pos.x + screen.x, a->Pos.y + screen.y, ! tint, anim->palette, &screen ); } a = GetNextAreaAnimation(aniidx,gametime); --- 734,738 ---- video->BlitSpriteTinted( anim->NextFrame(), a->Pos.x + screen.x, a->Pos.y + screen.y, ! tint, a->palette, &screen ); } a = GetNextAreaAnimation(aniidx,gametime); *************** *** 2254,2257 **** --- 2254,2258 ---- animation=NULL; animcount=0; + palette=NULL; } *************** *** 2264,2267 **** --- 2265,2269 ---- } free(animation); + core->GetVideoDriver()->FreePalette(palette); } *************** *** 2276,2286 **** DataStream* s = core->GetResourceMgr()->GetResource( Pal, IE_BMP_CLASS_ID ); bmp->Open( s, true ); ! Palette* pal = new Palette(); ! bmp->GetPalette( 0, 256, pal->col ); core->FreeInterface( bmp ); ! for (int i=0;i<animcount;i++) { ! animation[i]->SetPalette( pal, true ); } ! pal->Release(); } --- 2278,2300 ---- DataStream* s = core->GetResourceMgr()->GetResource( Pal, IE_BMP_CLASS_ID ); bmp->Open( s, true ); ! core->GetVideoDriver()->FreePalette(palette); ! palette = new Palette(); ! bmp->GetPalette( 0, 256, palette->col ); core->FreeInterface( bmp ); ! } ! ! void AreaAnimation::BlendAnimation() ! { ! if (!palette) { ! // CHECKME: what should we do here? Currently copying palette ! // from first frame of first animation ! ! if (animcount == 0 || !animation[0]) return; ! Sprite2D* spr = animation[0]->GetFrame(0); ! if (!spr) return; ! palette = core->GetVideoDriver()->GetPalette(spr)->Copy(); } ! ! palette->CreateShadedAlphaChannel(); } Index: Map.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Map.h,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** Map.h 28 Jan 2006 19:56:34 -0000 1.103 --- Map.h 29 Jan 2006 13:40:19 -0000 1.104 *************** *** 152,158 **** --- 152,160 ---- ieResRef BAM; //not only for saving back (StaticSequence depends on this) ieResRef PaletteRef; + Palette* palette; AreaAnimation(); ~AreaAnimation(); void SetPalette(ieResRef PaletteRef); + void BlendAnimation(); bool Schedule(ieDword gametime); }; Index: Animation.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Animation.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Animation.cpp 28 Jan 2006 19:56:34 -0000 1.40 --- Animation.cpp 29 Jan 2006 13:40:19 -0000 1.41 *************** *** 24,28 **** #include "Interface.h" #include "Video.h" - #include "Palette.h" #include "Map.h" #include "Game.h" --- 24,27 ---- *************** *** 50,54 **** y = 0; autofree = false; - palette = NULL; Flags = A_ANI_ACTIVE; fps = 15; --- 49,52 ---- *************** *** 69,73 **** } free(frames); - video->FreePalette(palette); } --- 67,70 ---- *************** *** 205,231 **** } - void Animation::SetPalette(Palette* pal, bool local) - { - Video *video = core->GetVideoDriver(); - if (local) { - if (pal) { - video->FreePalette(palette); - pal->IncRef(); - palette = pal; - } else { - // if pal == NULL, copy palette from first frame - if (!palette) { - palette = video->GetPalette( frames[0] ); - // palette's refcount has been increased by GetPalette - } - } - } else { - //no idea if this part will ever be used - for (size_t i = 0; i < indicesCount; i++) { - video->SetPalette( frames[i], pal ); - } - } - } - void Animation::MirrorAnimation() { --- 202,205 ---- *************** *** 248,266 **** } - void Animation::BlendAnimation() - { - // CHECKME: this means that if this Animation doesn't yet have a palette, - // it will set the palette of the first frame for the entire animation. - // Is this allowed? - // If not: do we need to make local copies of the palettes for all frames? - // (Palette might then need a flag 'blended' to make sure we don't make - // too many copies.) - - // make sure we have a palette (see CHECKME) - SetPalette(0, true); - - palette->CreateShadedAlphaChannel(); - } - void Animation::AddAnimArea(Animation* slave) { --- 222,225 ---- Index: Actor.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Actor.cpp,v retrieving revision 1.163 retrieving revision 1.164 diff -C2 -d -r1.163 -r1.164 *** Actor.cpp 28 Jan 2006 19:56:33 -0000 1.163 --- Actor.cpp 29 Jan 2006 13:40:19 -0000 1.164 *************** *** 1273,1279 **** if (TranslucentShadows) { ! video->BlitSpriteTransShadow( nextFrame, cx + screen.x, cy + screen.y, tint, sc, anim->palette, &screen ); } else { ! video->BlitSpriteCovered( nextFrame, cx + screen.x, cy + screen.y, tint, sc, anim->palette, &screen ); } } --- 1273,1279 ---- if (TranslucentShadows) { ! video->BlitSpriteTransShadow( nextFrame, cx + screen.x, cy + screen.y, tint, sc, ca->palette, &screen ); } else { ! video->BlitSpriteCovered( nextFrame, cx + screen.x, cy + screen.y, tint, sc, ca->palette, &screen ); } } *************** *** 1311,1315 **** return false; } ! void Actor::ResolveStringConstant(ieResRef Sound, unsigned int index) { --- 1311,1315 ---- return false; } ! void Actor::ResolveStringConstant(ieResRef Sound, unsigned int index) { |