//===========================================================================// // File: model.tst // // Project: MUNGA Brick: Entity Manager // // Contents: Implementation details of the entity class // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 12/28/94 JMA Initial coding. // //---------------------------------------------------------------------------// // Copyright (C) 1994, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #include "model.thh" //############################################################################# // Shared Data Support // Derivation TestEntity::ClassDerivations(Entity::ClassDerivations,"TestEntity"); TestEntity::SharedData TestEntity::DefaultData( TestEntity::ClassDerivations, TestEntity::MessageHandlers, TestEntity::AttributeIndex, (Entity::MakeHandler)TestEntity::Make ); //############################################################################# // Message Support // const Receiver::HandlerEntry TestEntity::MessageHandlerEntries[]= { { TestEntity::TestMessageID, (TestEntity::Handler)&TestEntity::TestMessageHandler } }; TestEntity::MessageHandlerSet TestEntity::MessageHandlers( ELEMENTS(TestEntity::MessageHandlerEntries), TestEntity::MessageHandlerEntries, Entity::MessageHandlers ); void TestEntity::TestMessageHandler(TestEntity::Message *) { localOrigin = Point3D(2.0,2.0,2.0); }; void TestEntity::Tester() { TestEntity::Message message( TestEntity::TestMessageID, sizeof(TestEntity::Message) ); Dispatch(&message); } //############################################################################# // Attribute Support // const TestEntity::IndexEntry TestEntity::AttributePointers[]= { { TestEntity::VelocityVectorAttributeID, (Entity::AttributePointer)&TestEntity::velocityVector } }; TestEntity::AttributeIndexSet TestEntity::AttributeIndex( ELEMENTS(TestEntity::AttributePointers), TestEntity::AttributePointers, Entity::AttributeIndex ); //############################################################################# // Model Support // Logical TestEntity::Model(Scalar time_slice) { Vector3D diff; diff.Multiply(velocityVector,time_slice); localOrigin.translation += diff; localToWorld = localOrigin.translation; return diff.LengthSquared() >= 0.009f; } //############################################################################# // Construction and Destruction // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // TestEntity::TestEntity( TestEntity::MakeMessage *creation_message, TestEntity::SharedData &virtual_data ): Entity(creation_message,virtual_data) { SetValidFlag(); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // TestEntity* TestEntity::Make(TestEntity::MakeMessage *creation_message) { return new TestEntity(creation_message); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // TestEntity::~TestEntity() { } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Logical Entity::TestClass() { DEBUG_STREAM << "Starting Entity test...\n"; // //------------------ // Test construction //------------------ // TestEntity::MakeMessage message1( TestEntity::MakeMessageID, sizeof(TestEntity::MakeMessage), TestEntity::TrivialEntityClassID, 0, TestEntity::DefaultFlags, LinearOrigin::Identity ); TestEntity *test_entity = TestEntity::Make(&message1); Register_Object(test_entity); // //------------------------ // Test attribute pointers //------------------------ // test_entity->localOrigin = Point3D(1.0f,1.0f,1.0f); LinearOrigin *origin = (LinearOrigin*)test_entity->GetAttributePointer(LocalOriginAttributeID); Test(origin->translation == Point3D(1.0f,1.0f,1.0f)); test_entity->velocityVector = Vector3D(0.0f,0.0f,1.0f); Vector3D *velocity = (Vector3D*)test_entity-> GetAttributePointer(TestEntity::VelocityVectorAttributeID); Test(*velocity == Vector3D(0.0f,0.0f,1.0f)); // //--------------------- // Test Model execution //--------------------- // test_entity->RunSimulation(0.1f); Test(origin->translation == Point3D(1.0f,1.0f,1.0f)); test_entity->SetSimulation((Model::Simulation)&TestEntity::Model); Test(!test_entity->RunSimulation(0.05f)); Test(origin->translation == Point3D(1.0f,1.0f,1.05f)); // //------------------------------- // Test Update message generation //------------------------------- // t = test_entity->creationTime; t += 0.1f; UpdateMessage *update = test_entity->Execute(t); Test(update); Test(update->localOrigin.translation == Point3D(1.0f,1.0f,1.15f)); Unregister_Object(update); delete update; // //----------------- // Test destruction //----------------- // Unregister_Object(test_entity); delete test_entity; return True; }