//===========================================================================//
// File: EntityClassData.cpp                                                 //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 11/29/94  JMA  Initial coding.                                            //
// 08/25/97  JMA  Infrastructure changes												  //
// 08/25/97  ECH	Infrastructure changes												  //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-97, Virtual World Entertainment, Inc.                  //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#include "AdeptHeaders.hpp"
#include "EntityClassData.hpp"

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Entity__ClassData::Entity__ClassData(
	RegisteredClass::ClassID class_id,
	const char* class_name,
	Replicator::ClassData *parent_class,
	int message_count,
	const Receiver::MessageEntry *message_handlers,
	Entity::Factory entity_factory,
	Entity::CreateMessage::Factory message_factory,
	Entity::ExecutionStateEngine::ClassData *execution_class,
	Entity::GameModel::Factory model_factory,
	Entity::GameModel::Factory obb_factory,
	Entity::GameModel::ReadAndVerifier verifier,
	Entity::GameModel::ModelWrite model_write_to_text,
	Entity::GameModel::ModelSave model_save_to_text
):
	Replicator__ClassData(
		class_id,
		class_name,
		parent_class,
		message_count,
		message_handlers,
		(Replicator::Factory)entity_factory,
		(Replicator::CreateMessage::Factory)message_factory
	),
	executionStateClass(execution_class),
	modelFactory(model_factory),
	obbFactory(obb_factory),
	modelVerifier(verifier),
	modelWriteToText(model_write_to_text),
	modelSaveToText(model_save_to_text),
	creationCount(0)
{
	//
	//----------------------------
	// Look for our parent's tables
	//----------------------------
	//
	Entity__ClassData *inheritance;
	if (class_id != EntityClassID)
	{
		//
		// Copy the inherited entries
		//
		inheritance = Cast_Pointer(Entity__ClassData*, parent_class);
		Check_Object(inheritance);
		attributeTable.CopyFrom(&inheritance->attributeTable);
		gameModelAttributeTable.CopyFrom(&inheritance->gameModelAttributeTable);
		return;
	}
	Verify(parent_class->GetClassID() == ReplicatorClassID);

	//
	//----------------------
	// Create the null entry
	//----------------------
	//
	AttributeEntry *attribute_entry = 
		new AttributeEntry(
			Entity::AnyAttributeID,
			"AnyAttributeID",
			NullClassID,
			NULL
		);
	Register_Object(attribute_entry);
	attributeTable.AddAttributeEntry(attribute_entry);

	//
	//----------------------
	// Create the null entry
	//----------------------
	//
	ModelAttributeEntry *model_attribute_entry = 
		new ModelAttributeEntry(
			Entity__GameModel::AnyAttributeID,
			"AnyAttributeID",
			NullClassID,
			NULL
		);
	Register_Object(model_attribute_entry);
	gameModelAttributeTable.AddAttributeEntry(model_attribute_entry);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
Entity__ClassData::~Entity__ClassData()
{
	SPEW((
		GROUP_ADEPT_ENTITY,
		"Entity__ClassData::~Entity__ClassData - %s created %d objects",
		className,
		creationCount
	));
}

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