00001 // ///////////////////////////////////////////////////////////////////////////// 00002 // 00003 // Name: EntityComponent.cpp 00004 // Author: Michael Bartsch (ZCCdark203) 00005 // 00006 // Desc : Abstraction base class for adding new functionalities to 00007 // entities. 00008 // 00009 // License: Copyright (C) 2009 Michael Bartsch and Contributors 00010 // 00011 // This program is free software: you can redistribute it 00012 // and/or modify it under the terms of the zlib/libpng License. 00013 // See main.cpp for conditions of distribution and use. 00014 // 00015 // ///////////////////////////////////////////////////////////////////////////// 00016 00017 // Include files 00018 #include "EntityComponent.h" 00019 00020 00021 // EntityComponent class 00022 // Static variables. 00023 u32 EntityComponent::mIDCount = 0; 00024 00025 // EntityComponent constructor. 00026 EntityComponent::EntityComponent(Entity *parent) 00027 { 00028 // Get new unique ID. 00029 mID = mIDCount++; 00030 00031 // Check if we got a valid pointer. 00032 if(parent != NULL) 00033 { 00034 if(parent->addComponent(this)) 00035 { 00036 pParent = parent; 00037 parent->grab(); 00038 } 00039 00040 else pParent = NULL; 00041 } 00042 00043 else pParent = NULL; 00044 } 00045 00046 // EntityComponent deconstructor. 00047 EntityComponent::~EntityComponent() 00048 { 00049 if(pParent != NULL) 00050 pParent->drop(); 00051 } 00052 00053 // Gets the ID of the component. 00054 u32 EntityComponent::getID() const 00055 { 00056 return mID; 00057 } 00058 00059 // Sets the name of the component. 00060 void EntityComponent::setName(const std::string &name) 00061 { 00062 mName = name; 00063 } 00064 00065 // Gets the name of the component. 00066 const std::string& EntityComponent::getName() const 00067 { 00068 return mName; 00069 } 00070 00071 // Gets the parent of this component. 00072 const Entity* EntityComponent::getParent() 00073 { 00074 return pParent; 00075 } 00076 00077 // End of File