//===========================================================================//
// File:	cmpnnt.cc                                                           //
// Project: MUNGA           Brick: Entity												  //
// Contents: 																					  //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 12/14/94  ECH  Initial coding.                                            //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc.                //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "AdeptHeaders.hpp"

#include "VideoComponentWeb.hpp"
#include "ShapeComponent.hpp"

//#############################################################################
//###########################  VideoComponentWeb  #############################
//#############################################################################

VideoComponentWeb::ClassData*
	VideoComponentWeb::DefaultData = NULL;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::InitializeClass()
{
	Verify(!DefaultData);
	DefaultData =
		new ClassData(
			VideoComponentWebClassID,
			"Adept::VideoComponentWeb",
			RendererComponentWeb::DefaultData
		);
	Register_Object(DefaultData);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::TerminateClass()
{
	Unregister_Object(DefaultData);
	delete DefaultData;
	DefaultData = NULL;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
VideoComponentWeb::VideoComponentWeb(
	ClassData *class_data,
	Entity *entity,
	Renderer *renderer,
	const ResourceID &script_id,
	VideoComponentWeb *parent_web
):
	RendererComponentWeb(class_data, entity, renderer, script_id, parent_web)
{
	Check_Object(renderer);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
VideoComponentWeb::~VideoComponentWeb()
{
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::SetInterest(bool rendered)
{
	Check_Object(this);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::TestInstance()
{
	Verify(IsDerivedFrom(DefaultData));
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::CleanDamage()
{
	Check_Object(this);

	ChainIteratorOf<Component*> chillins(&ownedComponents);
	Component *component;
	while ((component = chillins.ReadAndNext()) != NULL)
	{
		if (component->GetClassID() == ShapeComponentClassID)
		{
			ShapeComponent *shape = Cast_Object(ShapeComponent*, component);
			shape->CleanDamage();
		}
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::ApplyDamage(
		const Stuff::LinearMatrix4D &damage_spot,
		Stuff::Scalar radius
	)
{
	Check_Object(this);
	Check_Object(&damage_spot);

	ChainIteratorOf<Component*> chillins(&ownedComponents);
	Component *component;
	while ((component = chillins.ReadAndNext()) != NULL)
	{
		if (component->GetClassID() == ShapeComponentClassID)
		{
			ShapeComponent *shape = Cast_Object(ShapeComponent*, component);
			shape->ApplyDamage(damage_spot, radius);
		}
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	VideoComponentWeb::ApplyDamageDecal(
		const Stuff::LinearMatrix4D &damage_spot,
		Stuff::Scalar radius,
		MidLevelRenderer::MLRTexture *texture
	)
{
	Check_Object(this);
	Check_Object(&damage_spot);

	ChainIteratorOf<Component*> chillins(&ownedComponents);
	Component *component;
	while ((component = chillins.ReadAndNext()) != NULL)
	{
		if (component->GetClassID() == ShapeComponentClassID)
		{
			ShapeComponent *shape = Cast_Object(ShapeComponent*, component);
			shape->ApplyDamageDecal(damage_spot, radius, texture);
		}
	}
}
