////////////////////////////////////////////////////////////////////////////////
//ddd
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// AnimThing.cpp
// Project: Nostril (aka Postal)
//
// History:
//		02/18/97 JMI	Started.
//
//		02/19/97	JMI	Added ability to send any message to any CThing when done
//							with animation.
//
//		02/20/97	JMI	Tweaked positioning; I think it's more correct.
//
//		02/20/97 MJR	Added mini-runtime-editor.
//
//		02/21/97	JMI	After tweaking the position, I hosed the sprite priority.
//							Fixed.  Now it's beauteous if you place a dude just a
//							bit in front of a looping explosion.
//
//		02/24/97	JMI	No longer sets the m_type member of the m_sprite b/c it
//							is set by m_sprite's constructor.
//
//		02/24/97	JMI	Changed m_pthingSendMsg to m_u16IdSendMsg.
//
//		02/25/97	JMI	Forgot to call FreeResources() in GetResources().
//
//		03/13/97	JMI	Load now takes a version number.
//
//		03/27/97	JMI	Now EditModify() returns failure if there's no resource
//							name.  GetResources() should've taken care of this via
//							rspGetResource() failing, but it seems to crash in Release
//							mode, so now EditModify() checks.
//
//		04/10/97 BRH	Updated this to work with the new multi layer attribute
//							maps.
//
//		05/29/97	JMI	Removed ASSERT on m_pRealm->m_pAttribMap which no longer
//							exists.
//
//		06/29/97	JMI	Converted EditRect(), EditRender(), and/or Render() to
//							use Map3Dto2D().
//							Also, now determines priority via 2D mapped Y.
//
//		07/27/97	JMI	Now determines priority totally based on Z.
//							Also, now uses CRealm::Make2dResPath() on res names.
//
//////////////////////////////////////////////////////////////////////////////
//
// This CThing-derived class will play an animation to its finish and then
// destroy itself.  It's a mini Postal movie player.
//
//////////////////////////////////////////////////////////////////////////////
#define ANIMTHING_CPP

#include "RSPiX.h"
#include <math.h>

#include "AnimThing.h"
#include "dude.h"
#include "game.h"

#include "pvr.h"

extern PVR::cRenderMgr *g_pvrRenderer;

////////////////////////////////////////////////////////////////////////////////
// Macros/types/etc.
////////////////////////////////////////////////////////////////////////////////

#define GUI_FILE_NAME "res/editor/EditAnim.gui"

#define GUI_ID_RESOURCE 3
#define GUI_ID_OPTIONS 4
#define GUI_ID_DONTLOOP 5
#define GUI_ID_DOLOOP 6

////////////////////////////////////////////////////////////////////////////////
// Variables/data
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Load object (should call base class version!)
////////////////////////////////////////////////////////////////////////////////
int16_t CAnimThing::Load(	// Returns 0 if successfull, non-zero otherwise
	RFile *pFile,			// In:  File to load from
	bool bEditMode,			// In:  True for edit mode, false otherwise
	int16_t sFileCount,		// In:  File count (unique per file, never 0)
	uint32_t ulFileVersion) // In:  Version of file format to load.
{
	int16_t sResult = CThing::Load(pFile, bEditMode, sFileCount, ulFileVersion);
	if (sResult == 0)
	{
		switch (ulFileVersion)
		{
		default:
		case 1:
			pFile->Read(&m_dX);
			pFile->Read(&m_dY);
			pFile->Read(&m_dZ);
			pFile->Read(m_szResName);
			pFile->Read(&m_sLoop);
			break;
		}

		// Make sure there were no file errors or format errors . . .
		if (!pFile->Error() && sResult == 0)
		{
			// Get resources
			sResult = GetResources();
		}
		else
		{
			sResult = -1;
			TRACE("CAnimThing::Load(): Error reading from file!\n");
		}
	}

	return sResult;
}

////////////////////////////////////////////////////////////////////////////////
// Startup object
////////////////////////////////////////////////////////////////////////////////
int16_t CAnimThing::Startup(void) // Returns 0 if successfull, non-zero otherwise
{
	m_lAnimPrevTime = m_pRealm->m_time.GetGameTime();
	m_lAnimTime = 0;
	m_sprite.m_cFrameToken = g_pvrRenderer->IssueFrameToken();	
	return 0;
}

////////////////////////////////////////////////////////////////////////////////
// Shutdown object
////////////////////////////////////////////////////////////////////////////////
int16_t CAnimThing::Shutdown(void) // Returns 0 if successfull, non-zero otherwise
{
	return 0;
}

////////////////////////////////////////////////////////////////////////////////
// Suspend object
////////////////////////////////////////////////////////////////////////////////
void CAnimThing::Suspend(void)
{
	m_sSuspend++;
}

////////////////////////////////////////////////////////////////////////////////
// Resume object
////////////////////////////////////////////////////////////////////////////////
void CAnimThing::Resume(void)
{
	m_sSuspend--;

	// If we're actually going to start updating again, we need to reset
	// the time so as to ignore any time that passed while we were suspended.
	// This method is far from precise, but I'm hoping it's good enough.
	if (m_sSuspend == 0)
	{
		m_lAnimPrevTime = m_pRealm->m_time.GetGameTime();
	}
}

////////////////////////////////////////////////////////////////////////////////
// Update object
////////////////////////////////////////////////////////////////////////////////
void CAnimThing::Update(void)
{
	if (!m_sSuspend)
	{
		if (m_lAnimTime >= m_paachannel->TotalTime() && m_sLoop == FALSE)
		{
			// If there's a thing to send a message to . . .
			if (m_u16IdSendMsg != CIdBank::IdNil)
			{
				// Send the message.
				SendThingMessage(&m_msg, m_u16IdSendMsg);
			}

			// Done.
			delete this;
			return;
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// Render object
////////////////////////////////////////////////////////////////////////////////
int16_t sEdit;
double dScale = 1.0;
double dScaleInc = 0.025;

void CAnimThing::Render(void)
{
	// Get current time diff.
	int32_t lCurTime = m_pRealm->m_time.GetGameTime();
	m_lAnimTime += lCurTime - m_lAnimPrevTime;
	m_lAnimPrevTime = lCurTime;

	CAlphaAnim *paa = (CAlphaAnim *)m_paachannel->GetAtTime(m_lAnimTime);
	if (paa != NULL && m_paachannel->id > 0)
	{
		// No special flags
		m_sprite.m_sInFlags = 0;

		// Map from 3d to 2d coords
		//		m_sprite.m_sX2 = m_dX + paa->m_sX;
		//		m_sprite.m_sY2 = m_dZ - (m_dY - paa->m_sY);
		Map3Dto2D(
			m_dX,
			m_dY,
			m_dZ,
			&(m_sprite.m_sX2),
			&(m_sprite.m_sY2));

		// Offset by hotspot.
		m_sprite.m_sX2 += paa->m_sX;
		m_sprite.m_sY2 += paa->m_sY;

		// Priority is based on our position in 3D realm coords.
		m_sprite.m_sPriority = m_dZ;

		// Copy the color info and the alpha channel to the Alpha Sprite
		m_sprite.hasAlphaChannel = true;

		m_sprite.tileId = paa->tileId;
		m_sprite.startU = paa->startU;
		m_sprite.startV = paa->startV;
		m_sprite.endU = paa->endU;
		m_sprite.endV = paa->endV;
		m_sprite.imageWidth = paa->width;
		m_sprite.imageHeight = paa->height;

		// todo: clean up & magic numbers
		switch (m_paachannel->id)
		{
		case 3: // Blood pool
			m_sprite.m_sLayer = PVR::cRenderMgr::LayerBg;
			m_sprite.texture = g_pvrRenderer->m_TextureRepository.Get(PVR_TEXTURE_PARTICLES_AAN);
			break;
		case 2:
		case 5:
		case 6:
			// Layer should be based on info we get from attribute map.
			m_sprite.m_sLayer = CRealm::GetLayerViaAttrib(m_pRealm->GetLayer((int16_t)m_dX, (int16_t)m_dZ));
			m_sprite.texture = g_pvrRenderer->m_TextureRepository.Get(PVR_TEXTURE_PARTICLES_AAN);
			break;
		case 4: // Large fire
		case 7: // Tinyfire
		case 9: // Small fire		
			m_sprite.m_sLayer = CRealm::GetLayerViaAttrib(m_pRealm->GetLayer((int16_t)m_dX, (int16_t)m_dZ));
			m_sprite.texture = g_pvrRenderer->m_TextureRepository.Get(PVR_TEXTURE_FIRE_AAN);
			break;
		default:			
			break;
		}

		// todo: clean up
		if (m_sprite.m_sAlphaLevel == 255)
		{
			m_sprite.m_sAlphaLevel = 254;
		}

		// Update sprite in scene
		if (!m_sprite.m_bTokenFrameExcluded)
		{
			m_pRealm->m_scene.UpdateSprite(&m_sprite);
		}		
	}
}

int16_t CAnimThing::Setup( // Returns 0 if successfull, non-zero otherwise
	int16_t sX,			   // In:  New x coord
	int16_t sY,			   // In:  New y coord
	int16_t sZ)			   // In:  New z coord
{
	int16_t sResult = 0;

	// Use specified position
	m_dX = (double)sX;
	m_dY = (double)sY;
	m_dZ = (double)sZ;

	m_lAnimPrevTime = m_pRealm->m_time.GetGameTime();

	// Load resources
	sResult = GetResources();

	m_sprite.m_cFrameToken = g_pvrRenderer->IssueFrameToken();
	m_sprite.m_cFrameTokenLevel = 1;
	m_sprite.m_cFrameTokenLevelExclude = 2;

	return sResult;
}

////////////////////////////////////////////////////////////////////////////////
// Get all required resources
////////////////////////////////////////////////////////////////////////////////
int16_t CAnimThing::GetResources(void) // Returns 0 if successfull, non-zero otherwise
{
	int16_t sResult = 0;

	// Safe to call even if no resource.
	FreeResources();

	sResult = rspGetResource(
		&g_resmgrGame,
		m_pRealm->Make2dResPath(m_szResName),
		&m_paachannel);

	if (sResult == 0)
	{

		// todo: clean up
		switch (m_paachannel->id)
		{
		// blood splatter
		case 2:
			for (int i = 0; i < m_paachannel->NumItems(); i++)
			{

				CAlphaAnim *tmp = (CAlphaAnim *)m_paachannel->GetItem(i);

				tmp->tileId = 0;

				switch (i)
				{
				// Frame 1
				case 0:
					tmp->startU = 0.136f;
					tmp->startV = 0.179f;
					tmp->endU = 0.152f;
					tmp->endV = 0.199f;
					tmp->tileId = 0;
					tmp->width = 4;
					tmp->height = 5;
					break;

				// Frame 2
				case 1:
					tmp->startU = 0.16f;
					tmp->startV = 0.179f;
					tmp->endU = 0.210f;
					tmp->endV = 0.234f;
					tmp->tileId = 0;
					tmp->width = 13;
					tmp->height = 14;
					break;

				// Frame 3
				case 2:
					tmp->startU = 0.210f;
					tmp->startV = 0.179f;
					tmp->endU = 0.296f;
					tmp->endV = 0.257f;
					tmp->tileId = 0;
					tmp->width = 19;
					tmp->height = 20;
					break;

				// Frame 4
				case 3:
					tmp->startU = 0.316f;
					tmp->startV = 0.179f;
					tmp->endU = 0.39f;
					tmp->endV = 0.25f;
					tmp->tileId = 0;
					tmp->width = 19;
					tmp->height = 19;
					break;

				// Frame 5
				case 4:
					tmp->startU = 0.414f;
					tmp->startV = 0.183f;
					tmp->endU = 0.417f;
					tmp->endV = 0.421f;
					tmp->tileId = 0;
					tmp->width = 2;
					tmp->height = 3;
					break;

				default:					
					break;
				}
			}
			break;

		// blood pools
		case 3:
			for (int i = 0; i < m_paachannel->NumItems(); i++)
			{

				CAlphaAnim *tmp = (CAlphaAnim *)m_paachannel->GetItem(i);

				tmp->tileId = 0;

				switch (i)
				{
				// Frame 1
				case 0:
					tmp->startU = 0.152f;
					tmp->startV = 0.339f;
					tmp->endU = 0.593f;
					tmp->endV = 0.351f;
					tmp->tileId = 0;
					tmp->width = 15;
					tmp->height = 9;
					break;

				// Frame 2
				case 1:
					tmp->startU = 0.207f;
					tmp->startV = 0.179f;
					tmp->endU = 0.261f;
					tmp->endV = 0.351f;
					tmp->tileId = 0;
					tmp->width = 15;
					tmp->height = 9;
					break;

				// Frame 3
				case 2:
					tmp->startU = 0.281f;
					tmp->startV = 0.320f;
					tmp->endU = 0.335f;
					tmp->endV = 0.351f;
					tmp->tileId = 0;
					tmp->width = 15;
					tmp->height = 9;
					break;

				// Frame 4
				case 3:
					tmp->startU = 0.355f;
					tmp->startV = 0.320f;
					tmp->endU = 0.410f;
					tmp->endV = 0.351f;
					tmp->tileId = 0;
					tmp->width = 15;
					tmp->height = 9;
					break;

				// Frame 5
				case 4:
					tmp->startU = 0.429f;
					tmp->startV = 0.320f;
					tmp->endU = 0.484f;
					tmp->endV = 0.351f;
					tmp->tileId = 0;
					tmp->width = 15;
					tmp->height = 9;
					break;
				}
			}
		break;

		// Large fire
		case 4:
			for (int i = 0; i < m_paachannel->NumItems(); i++)
			{

				CAlphaAnim *tmp = (CAlphaAnim *)m_paachannel->GetItem(i);
				tmp->tileId = 0;
				switch (i)
				{
				// Frame 1
				case 0:
					tmp->startU = 0.0f;
					tmp->startV = 0.0f;
					tmp->endU = 0.273f;
					tmp->endV = 0.312f;
					tmp->tileId = 0;
					tmp->width = 70;
					tmp->height = 80;
					break;

				// Frame 2
				case 1:
					tmp->startU = 0.273f;
					tmp->startV = 0.0f;
					tmp->endU = 0.542f;
					tmp->endV = 0.265f;
					tmp->tileId = 0;
					tmp->width = 70;
					tmp->height = 68;
					break;

				// Frame 3
				case 2:
					tmp->startU = 0.542f;
					tmp->startV = 0.0f;
					tmp->endU = 0.824f;
					tmp->endV = 0.261f;
					tmp->tileId = 0;
					tmp->width = 72;
					tmp->height = 67;
					break;

				// Frame 4
				case 3:
					tmp->startU = 0.0f;
					tmp->startV = 0.343f;
					tmp->endU = 0.292f;
					tmp->endV = 0.625f;
					tmp->tileId = 0;
					tmp->width = 75;
					tmp->height = 72;
					break;

				// Frame 5
				case 4:
					tmp->startU = 0.292f;
					tmp->startV = 0.312f;
					tmp->endU = 0.593f;
					tmp->endV = 0.625f;
					tmp->tileId = 0;
					tmp->width = 77;
					tmp->height = 80;
					break;

				// Frame 6
				case 5:
					tmp->startU = 0.589f;
					tmp->startV = 0.343f;
					tmp->endU = 0.867f;
					tmp->endV = 0.625f;
					tmp->tileId = 0;
					tmp->width = 71;
					tmp->height = 72;
					break;

				// Frame 7
				case 6:
					tmp->startU = 0.0f;
					tmp->startV = 0.625f;
					tmp->endU = 0.308f;
					tmp->endV = 0.898f;
					tmp->tileId = 0;
					tmp->width = 79;
					tmp->height = 70;
					break;

				// Frame 8
				case 7:
					tmp->startU = 0.304f;
					tmp->startV = 0.625f;

					tmp->endU = 0.582f;
					tmp->endV = 0.906f;

					tmp->tileId = 0;
					tmp->width = 77;
					tmp->height = 70;
					break;

				// Fream 9
				case 8:
					tmp->startU = 0.582f;
					tmp->startV = 0.625f;
					tmp->endU = 0.882f;
					tmp->endV = 0.917f;
					tmp->tileId = 0;
					tmp->width = 77;
					tmp->height = 75;
					break;

				// tile 2
				// Frame 10
				case 9:
					tmp->startU = 0.0f;
					tmp->startV = 0.0f;
					tmp->endU = 0.292f;
					tmp->endV = 0.304f;
					tmp->tileId = 1;
					tmp->width = 75;
					tmp->height = 78;
					break;

				// Frame 11
				case 10:
					tmp->startU = 0.289f;
					tmp->startV = 0.0f;
					tmp->endU = 0.578f;
					tmp->endV = 0.300f;
					tmp->tileId = 1;
					tmp->width = 74;
					tmp->height = 77;
					break;

				// Frame 12
				case 11:
					tmp->startU = 0.574f;
					tmp->startV = 0.0f;
					tmp->endU = 0.867f;
					tmp->endV = 0.308f;
					tmp->tileId = 1;
					tmp->width = 75;
					tmp->height = 79;
					break;

				// Frame 13
				case 12:
					tmp->startU = 0.0;
					tmp->startV = 0.308f;
					tmp->endU = 0.296f;
					tmp->endV = 0.648f;
					tmp->tileId = 1;
					tmp->width = 76;
					tmp->height = 87;
					break;

				// Frame 14
				case 13:
					tmp->startU = 0.292f;
					tmp->startV = 0.304f;
					tmp->endU = 0.582f;
					tmp->endV = 0.605f;
					tmp->tileId = 1;
					tmp->width = 74;
					tmp->height = 77;
					break;
				}
			}
			break;

		// ricochet
		case 5:
			for (int i = 0; i < m_paachannel->NumItems(); i++)
			{

				CAlphaAnim *tmp = (CAlphaAnim *)m_paachannel->GetItem(i);

				tmp->tileId = 0;

				switch (i)
				{
				// Frame 1
				case 0:
					tmp->startU = 0.656f;
					tmp->startV = 0.39f;
					tmp->endU = 0.699f;
					tmp->endV = 0.433f;
					tmp->tileId = 0;
					tmp->width = 11;
					tmp->height = 12;
					break;

				// Frame 2
				case 1:
					tmp->startU = 0.578f;
					tmp->startV = 0.390f;
					tmp->endU = 0.632f;
					tmp->endV = 0.437f;
					tmp->tileId = 0;
					tmp->width = 15;
					tmp->height = 13;
					break;

				// Frame 3
				case 2:
					tmp->startU = 0.503f;
					tmp->startV = 0.390f;
					tmp->endU = 0.554f;
					tmp->endV = 0.460f;
					tmp->tileId = 0;
					tmp->width = 14;
					tmp->height = 19;
					break;

				// Frame 4
				case 3:
					tmp->startU = 0.414f;
					tmp->startV = 0.390f;
					tmp->endU = 0.484f;
					tmp->endV = 0.503f;
					tmp->tileId = 0;
					tmp->width = 19;
					tmp->height = 13;
					break;

				// Frame 5
				case 4:
					tmp->startU = 0.343f;
					tmp->startV = 0.390f;
					tmp->endU = 0.394f;
					tmp->endV = 0.480f;
					tmp->tileId = 0;
					tmp->width = 14;
					tmp->height = 24;
					break;

				// Frame 6
				case 5:
					tmp->startU = 0.261f;
					tmp->startV = 0.390f;
					tmp->endU = 0.324f;
					tmp->endV = 0.484f;
					tmp->tileId = 0;
					tmp->width = 17;
					tmp->height = 25;
					break;
				}
			}
			break;

		// muzzle flare
		case 6:
			for (int i = 0; i < m_paachannel->NumItems(); i++)
			{

				CAlphaAnim *tmp = (CAlphaAnim *)m_paachannel->GetItem(i);

				tmp->tileId = 0;

				switch (i)
				{
				// Frame 1
				case 0:
					tmp->startU = 0.191f;
					tmp->startV = 0.39f;
					tmp->endU = 0.234f;
					tmp->endV = 0.425f;
					tmp->tileId = 0;
					tmp->width = 11;
					tmp->height = 9;
					break;

				// Frame 2
				case 1:
					tmp->startU = 0.132f;
					tmp->startV = 0.390f;
					tmp->endU = 0.175f;
					tmp->endV = 0.437f;
					tmp->tileId = 0;
					tmp->width = 11;
					tmp->height = 9;
					break;
				}
			}
			break;

		// Small fire
		case 9:
		
		

		
	for (int i = 0; i < m_paachannel->NumItems(); i++)
			{

				CAlphaAnim *tmp = (CAlphaAnim *)m_paachannel->GetItem(i);
									
				tmp->tileId = 1;
				
				switch (i)
				{
					// Frame 1
					//     
					case 0:					
					tmp->startU = 0.58203125 ;
					tmp->startV = 0.30859375;
					tmp->endU = 0.68359375;
					tmp->endV = 0.51953125;					
					tmp->width = 26;
					tmp->height = 54;					
					break;

					// Frame 2
					//      
					case 1:
					tmp->startU = 0.68359375;
					tmp->startV = 0.30859375;
					tmp->endU = 0.77734375;
					tmp->endV = 0.4765625;					
					tmp->width = 24;
					tmp->height = 43;					
					break;

					// Frame 3
					//    24 48
					case 2:
					tmp->startU = 0.7734375; 
					tmp->startV = 0.30859375;
					tmp->endU = 0.8671875;					
					tmp->endV = 0.49609375;					
					tmp->width = 24;
					tmp->height = 48;
					break;

					// Frame 4
					//     25 54
					case 3:
					tmp->startU = 0.8671875;						
					tmp->startV = 0.30859375; 
					tmp->endU =0.96484375;
					tmp->endV = 0.51953125;					
					tmp->width = 25;
					tmp->height = 54;
					break;

					// Frame 5
					//     28 49
					case 4:
					tmp->startU = 0.58203125; 
					tmp->startV = 0.51953125;
					tmp->endU =0.69140625;
					tmp->endV = 0.7109375;					
					tmp->width = 28;
					tmp->height = 49;
					break;

					// Frame 6
					//     23 45
					case 5:
					tmp->startU = 0.69140625; 
					tmp->startV = 0.51953125f;
					tmp->endU = 0.78125;
					tmp->endV = 0.6953125f;					
					tmp->width = 23;
					tmp->height = 45;				
					break;
					

					// Frame 7
					//    23 33
					case 6:
					tmp->startU =  0.78125f;
					tmp->startV = 0.51953125f;
					tmp->endU = 0.87109375f;
					tmp->endV = 0.6484375f;					
					tmp->width = 23;
					tmp->height = 33;
					break;


					// Frame 8
					//    21 37
					case 7:
					tmp->startU = 0.87109375f;
					tmp->startV =  0.51953125f;
					tmp->endU = 0.953125f;
					tmp->endV = 0.6640625;					
					tmp->width = 21;
					tmp->height = 37;
					break;


					// Frame 9
					//    23 37
					case 8:
					tmp->startU = 0.37109375;
					tmp->startV = 0.7109375f;
					tmp->endU = 0.4609375f;
					tmp->endV =0.85546875;					
					tmp->width = 23;
					tmp->height = 37;
					break;

					// Frame 10
					//     24 40
					case 9:
					tmp->startU =0.4609375f;
					tmp->startV = 0.7109375f;
					tmp->endU = 0.5546875f;
					tmp->endV = 0.8671875f;					
					tmp->width = 24;
					tmp->height = 40;
					break;

					// Frame 11
					//      28 44
					case 10:
					tmp->startU = 0.5546875f;
					tmp->startV = 0.7109375f;
					tmp->endU =0.6640625f;
					tmp->endV = 0.8828125f;					
					tmp->width = 28;
					tmp->height = 44;
					break;


					// Frame 12
					//    30 51
					case 11:
					tmp->startU = 0.6640625f;
					tmp->startV = 0.7109375f;
					tmp->endU = 0.78125f;
					tmp->endV = 0.91015625f;					
					tmp->width = 30;
					tmp->height = 51;
					break;
					
					// Frame 13
					//     30 54					
					case 12:
					tmp->startU = 0.78125f;
					tmp->startV = 0.68359375f;
					tmp->endU = 0.8984375f;
					tmp->endV = 0.89453125f;					
					tmp->width = 30;
					tmp->height = 54;
					break;

					// Frame 14
					//    24 47
					case 13:
					tmp->startU = 0.8984375f;
					tmp->startV = 0.7109375f;
					tmp->endU = 0.9921875f;
					tmp->endV = 0.89453125f;					
					tmp->width = 24;
					tmp->height = 47;
					break;
			
				}												
			}			
		}

		m_lAnimTime = 0;
		m_lAnimPrevTime = m_pRealm->m_time.GetGameTime();

		if (m_sLoop != FALSE)
		{
			m_paachannel->SetLooping(RChannel_LoopAtStart | RChannel_LoopAtEnd);
		}
		else
		{
			m_paachannel->SetLooping(0);
		}
	}
	else
	{
		TRACE("GetResources(): Failed to load resource \"%s\".\n",
			  m_pRealm->Make2dResPath(m_szResName));
	}

	return sResult;
}

////////////////////////////////////////////////////////////////////////////////
// Free all resources
////////////////////////////////////////////////////////////////////////////////
int16_t CAnimThing::FreeResources(void) // Returns 0 if successfull, non-zero otherwise
{
	int16_t sResult = 0;

	if (m_paachannel != NULL)
	{
		rspReleaseResource(&g_resmgrGame, &m_paachannel);
		/*if (m_pRealm->m_flags.bPurgeResOnShutdown)
			{
				rspReleaseAndPurgeResource(&g_resmgrGame, &m_paachannel);
			}
			else
			{
				rspReleaseResource(&g_resmgrGame, &m_paachannel);
			}		*/
	}

	return sResult;
}

////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////
