//**************************************************************************** //* MODULE: Gel/Components //* FILENAME: EmptyComponent.cpp //* OWNER: ??? //* CREATION DATE: ??? //**************************************************************************** // The CEmptyComponent class is an skeletal version of a component // It is intended that you use this as the basis for creating new // components. // To create a new component called "Watch", (CWatchComponent): // - copy emptycomponent.cpp/.h to watchcomponent.cpp/.h // - in both files, search and replace "Empty" with "Watch", preserving the case // - in WatchComponent.h, update the CRCD value of CRC_WATCH // - in CompositeObjectManager.cpp, in the CCompositeObjectManager constructor, add: // RegisterComponent(CRC_WATCH, CWatchComponent::s_create); // - and add the include of the header // #include // - Add it to build\gel.mkf, like: // $(NGEL)/components/WatchComponent.cpp\ // - Fill in the OWNER (yourself) and the CREATION DATE (today's date) in the .cpp and the .h files // - Insert code as needed and remove generic comments // - remove these comments // - add comments specfic to the component, explaining its usage #include #include #include #include #include namespace Obj { /******************************************************************/ /* */ /* */ /******************************************************************/ // s_create is what is registered with the component factory // object, (currently the CCompositeObjectManager) // s_create returns a CBaseComponent*, as it is to be used // by factor creation schemes that do not care what type of // component is being created // ** after you've finished creating this component, be sure to // ** add it to the list of registered functions in the // ** CCompositeObjectManager constructor CBaseComponent* CEmptyComponent::s_create() { return static_cast< CBaseComponent* >( new CEmptyComponent ); } /******************************************************************/ /* */ /* */ /******************************************************************/ // All components set their type, which is a unique 32-bit number // (the CRC of their name), which is used to identify the component CEmptyComponent::CEmptyComponent() : CBaseComponent() { SetType( CRC_EMPTY ); } /******************************************************************/ /* */ /* */ /******************************************************************/ CEmptyComponent::~CEmptyComponent() { } /******************************************************************/ /* */ /* */ /******************************************************************/ // InitFromStructure is passed a Script::CStruct that contains a // number of parameters to initialize this component // this currently is the contents of a node // but you can pass in anything you like. void CEmptyComponent::InitFromStructure( Script::CStruct* pParams ) { // ** Add code to parse the structure, and initialize the component } /******************************************************************/ /* */ /* */ /******************************************************************/ /* It's commented out here. You will also need to comment in the definition in emptycomponent.h void CEmptyComponent::Finalize() { // Virtual function, can be overridden to provided finialization to // a component after all components have been added to an object // Usually this consists of getting pointers to other components // Note: It is GUARENTEED (at time of writing) that // Finalize() will be called AFTER all components are added // and BEFORE the CCompositeObject::Update function is called // Example: // mp_suspend_component = GetSuspendComponentFromObject( GetObject() ); } */ /******************************************************************/ /* */ /* */ /******************************************************************/ // RefreshFromStructure is passed a Script::CStruct that contains a // number of parameters to initialize this component // this currently is the contents of a node // but you can pass in anything you like. void CEmptyComponent::RefreshFromStructure( Script::CStruct* pParams ) { // Default to just calline InitFromStructure() // but if that does not handle it, then will need to write a specific // function here. // The user might only want to update a single field in the structure // and we don't want to be asserting becasue everything is missing InitFromStructure(pParams); } /******************************************************************/ /* */ /* */ /******************************************************************/ // The component's Update() function is called from the CCompositeObject's // Update() function. That is called every game frame by the CCompositeObjectManager // from the s_logic_code function that the CCompositeObjectManager registers // with the task manger. void CEmptyComponent::Update() { // ** You would put in here the stuff that you would want to get run every frame // ** for example, a physics type component might update the position and orientation // ** and update the internal physics state } /******************************************************************/ /* */ /* */ /******************************************************************/ // Given the "Checksum" of a script command, then possibly handle it // if it's a command that this component will handle CBaseComponent::EMemberFunctionResult CEmptyComponent::CallMemberFunction( uint32 Checksum, Script::CStruct* pParams, Script::CScript* pScript ) { switch ( Checksum ) { /* // @script | DoSomething | does some functionality case 0xbb4ad101: // DoSomething DoSomething(); break; // @script | ValueIsTrue | returns a boolean value case 0x769260f7: // ValueIsTrue { return ValueIsTrue() ? CBaseComponent::MF_TRUE : CBaseComponent::MF_FALSE; } break; */ default: return CBaseComponent::MF_NOT_EXECUTED; } // the "default" case of the switch statement handles // unrecognized functions; if we make it down here, // that means that the component already handled it // somehow return CBaseComponent::MF_TRUE; } /******************************************************************/ /* */ /* */ /******************************************************************/ void CEmptyComponent::GetDebugInfo(Script::CStruct *p_info) { #ifdef __DEBUG_CODE__ Dbg_MsgAssert(p_info,("NULL p_info sent to CEmptyComponent::GetDebugInfo")); // Add any script components to the p_info structure, // and they will be displayed in the script debugger (qdebug.exe) // you will need to add the names to debugger_names.q, if they are not existing checksums /* Example: p_info->AddInteger(CRCD(0x7cf2a233,"m_never_suspend"),m_never_suspend); p_info->AddFloat(CRCD(0x519ab8e0,"m_suspend_distance"),m_suspend_distance); */ // we call the base component's GetDebugInfo, so we can add info from the common base component CBaseComponent::GetDebugInfo(p_info); #endif } /******************************************************************/ /* */ /* */ /******************************************************************/ }