mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-27 23:35:45 +00:00
(Mostly) updated verve implementation.
This commit is contained in:
parent
e0627973fb
commit
5a7f0f0b23
538 changed files with 68727 additions and 49 deletions
76
Engine/source/Verve/Core/ITreeNode.h
Normal file
76
Engine/source/Verve/Core/ITreeNode.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_ITREENODE_H_
|
||||
#define _VT_ITREENODE_H_
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class ITreeNode
|
||||
{
|
||||
public:
|
||||
|
||||
ITreeNode *mParentNode;
|
||||
ITreeNode *mChildNode;
|
||||
|
||||
ITreeNode *mSiblingPrevNode;
|
||||
ITreeNode *mSiblingNextNode;
|
||||
|
||||
public:
|
||||
|
||||
ITreeNode( void ) :
|
||||
mParentNode( 0 ),
|
||||
mChildNode( 0 ),
|
||||
mSiblingPrevNode( 0 ),
|
||||
mSiblingNextNode( 0 )
|
||||
{
|
||||
// Void.
|
||||
};
|
||||
|
||||
virtual ~ITreeNode( void )
|
||||
{
|
||||
// Void.
|
||||
};
|
||||
|
||||
virtual void clear( void ) = 0; // Clear the Node.
|
||||
|
||||
virtual ITreeNode *getRoot( void ) = 0; // Get Root Node.
|
||||
virtual ITreeNode *getParent( void ) = 0; // Get Parent Node.
|
||||
virtual ITreeNode *getChild( void ) = 0; // Get Child Node.
|
||||
virtual ITreeNode *getLastChild( void ) = 0; // Get Last Child Node.
|
||||
|
||||
virtual ITreeNode *getPrevSibling( void ) = 0; // Get Previous Sibling Node.
|
||||
virtual ITreeNode *getNextSibling( void ) = 0; // Get Next Sibling Node.
|
||||
|
||||
virtual void addTo( ITreeNode *pNode ) = 0; // Add Node to target node.
|
||||
virtual void remove( void ) = 0; // Remove this Node from the tree.
|
||||
virtual void moveTo( ITreeNode* node ) = 0; // Move to specified Node.
|
||||
|
||||
virtual void onAttach( void ) = 0; // Attach Callback.
|
||||
virtual void onDetach( void ) = 0; // Detach Callback.
|
||||
|
||||
virtual bool inTree( void ) = 0; // Is Node in a tree?
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_ITREENODE_H_
|
||||
137
Engine/source/Verve/Core/Persistence/VPersistence.cpp
Normal file
137
Engine/source/Verve/Core/Persistence/VPersistence.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/Persistence/VPersistence.h"
|
||||
|
||||
#include "Verve/Core/VController.h"
|
||||
#include "Verve/Core/VObject.h"
|
||||
|
||||
namespace VPersistence
|
||||
{
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VController
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <>
|
||||
bool write( TiXmlElement *pElement, VController *pObject )
|
||||
{
|
||||
// Write Properties.
|
||||
if ( !writeProperties( pElement, pObject ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write Data Table.
|
||||
if ( !pObject->writeDataTable( pElement ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write Objects.
|
||||
return writeObjects( pElement, pObject );
|
||||
}
|
||||
|
||||
template <>
|
||||
bool read( TiXmlElement *pElement, VController *pObject )
|
||||
{
|
||||
// Read Properties.
|
||||
if ( !readProperties( pElement, pObject ) )
|
||||
{
|
||||
// Invalid Properties.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read Data Table.
|
||||
if ( !pObject->readDataTable( pElement ) )
|
||||
{
|
||||
// Invalid Data Table.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read Objects.
|
||||
if ( !readObjects( pElement, pObject ) )
|
||||
{
|
||||
// Invalid Read.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Valid Read.
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <>
|
||||
bool write( TiXmlElement *pElement, VObject *pObject )
|
||||
{
|
||||
// Create Element.
|
||||
TiXmlElement *objectElement = new TiXmlElement( "VObject" );
|
||||
pElement->LinkEndChild( objectElement );
|
||||
|
||||
// Attributes.
|
||||
objectElement->SetAttribute( "Type", pObject->getClassName() );
|
||||
|
||||
// Write Properties.
|
||||
if ( !writeProperties( objectElement, pObject ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write Objects.
|
||||
return writeObjects( objectElement, pObject );
|
||||
}
|
||||
|
||||
template <>
|
||||
bool read( TiXmlElement *pElement, VObject *pObject )
|
||||
{
|
||||
// Read Properties.
|
||||
if ( !readProperties( pElement, pObject ) )
|
||||
{
|
||||
// Invalid Properties.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set Name Unique.
|
||||
pObject->setLabelUnique( pObject->getLabel() );
|
||||
|
||||
// Read Objects.
|
||||
if ( !readObjects( pElement, pObject ) )
|
||||
{
|
||||
// Invalid Objects.
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
// Callback.
|
||||
Con::executef( pObject, "onRead" );
|
||||
#endif
|
||||
|
||||
// Valid Read.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
286
Engine/source/Verve/Core/Persistence/VPersistence.h
Normal file
286
Engine/source/Verve/Core/Persistence/VPersistence.h
Normal file
|
|
@ -0,0 +1,286 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VPERSISTENCE_H_
|
||||
#define _VT_VPERSISTENCE_H_
|
||||
|
||||
#ifndef TINYXML_INCLUDED
|
||||
#include "tinyxml/tinyxml.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SIMOBJECT_H_
|
||||
#include "console/simObject.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_VOBJECT_H_
|
||||
#include "Verve/Core/VObject.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace VPersistence
|
||||
{
|
||||
static const char *VSFVersionString = "0.0.0a";
|
||||
|
||||
// This object is used to filter fields which belong to SimObject's.
|
||||
// There is no need to serialize these fields, so they are skipped
|
||||
// entirely.
|
||||
static SimObject DummySimObject;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
template <class T> bool writeFile( const char* pFileName, T *pObject )
|
||||
{
|
||||
// Create Doc.
|
||||
TiXmlDocument xmlDocument;
|
||||
TiXmlDeclaration *xmlDeclaration = new TiXmlDeclaration( "1.0", "", "" );
|
||||
xmlDocument.LinkEndChild( xmlDeclaration );
|
||||
|
||||
// Create Root.
|
||||
TiXmlElement *xmlRoot = new TiXmlElement( "VerveControllerSequence" );
|
||||
xmlDocument.LinkEndChild( xmlRoot );
|
||||
|
||||
// Write Version.
|
||||
xmlRoot->SetAttribute( "Version", VSFVersionString );
|
||||
|
||||
// Write Object.
|
||||
if ( !write( xmlRoot, pObject ) )
|
||||
{
|
||||
Con::errorf( "VPersistence::writeFile() - Unable to Write Object." );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save File.
|
||||
return xmlDocument.SaveFile( pFileName );
|
||||
};
|
||||
|
||||
template <class T> bool write( TiXmlElement *pElement, T *pObject );
|
||||
|
||||
template <class T> bool writeProperties( TiXmlElement *pElement, T *pObject )
|
||||
{
|
||||
const AbstractClassRep::FieldList &fieldList = pObject->getFieldList();
|
||||
const AbstractClassRep::Field *field = NULL;
|
||||
|
||||
// Create Property Root.
|
||||
TiXmlElement *propertyRoot = new TiXmlElement( "Properties" );
|
||||
pElement->LinkEndChild( propertyRoot );
|
||||
|
||||
const S32 fieldCount = fieldList.size();
|
||||
for ( S32 i = 0; i < fieldCount; i++ )
|
||||
{
|
||||
field = &fieldList[i];
|
||||
|
||||
if ( field->type >= AbstractClassRep::ARCFirstCustomField )
|
||||
{
|
||||
// Ignore Special Fields.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the Field Name.
|
||||
const char *fieldName = field->pFieldname;
|
||||
// SimObject Field?
|
||||
if ( DummySimObject.findField( fieldName ) != NULL )
|
||||
{
|
||||
// Skip SimObject Fields.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the Field Value.
|
||||
const char *fieldValue = ( *field->getDataFn )( pObject, Con::getData( field->type, ( void * ) ( ( ( const char * )pObject ) + field->offset ), 0, field->table, field->flag ) );
|
||||
|
||||
if ( fieldValue )
|
||||
{
|
||||
// Create Element.
|
||||
TiXmlElement *propertyElement = new TiXmlElement( fieldName );
|
||||
|
||||
// Apply Value.
|
||||
propertyElement->InsertEndChild( TiXmlText( fieldValue ) );
|
||||
|
||||
// Add.
|
||||
propertyRoot->LinkEndChild( propertyElement );
|
||||
}
|
||||
}
|
||||
|
||||
// Valid Write.
|
||||
return true;
|
||||
};
|
||||
|
||||
template <class T> bool writeObjects( TiXmlElement *pElement, T *pObject )
|
||||
{
|
||||
for ( ITreeNode *node = pObject->mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
// Write Group.
|
||||
if ( !write( pElement, ( VObject* )node ) )
|
||||
{
|
||||
// Invalid Write.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Valid Write.
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
template <class T> bool readFile( const char* pFileName, T *pObject )
|
||||
{
|
||||
TiXmlDocument xmlDocument;
|
||||
if ( !xmlDocument.LoadFile( pFileName ) )
|
||||
{
|
||||
Con::errorf( "VPersistence::readFile() - Unable to load file '%s'.", pFileName );
|
||||
return false;
|
||||
}
|
||||
|
||||
TiXmlElement *rootElement = xmlDocument.RootElement();
|
||||
if ( !rootElement )
|
||||
{
|
||||
Con::errorf( "VPersistence::readFile() - Invalid Document '%s'.", pFileName );
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *docVersion = rootElement->Attribute( "Version" );
|
||||
if ( !docVersion || dStrcmp( VSFVersionString, docVersion ) != 0 )
|
||||
{
|
||||
Con::errorf( "VPersistence::readFile() - Invalid file version." );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read Object.
|
||||
if ( !read( rootElement, pObject ) )
|
||||
{
|
||||
// Invalid Read.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Valid.
|
||||
return true;
|
||||
};
|
||||
|
||||
template <class T> bool read( TiXmlElement *pElement, T *pObject );
|
||||
|
||||
template <class T> bool readProperties( TiXmlElement *pElement, T *pObject )
|
||||
{
|
||||
TiXmlElement *propertyRoot = pElement->FirstChildElement( "Properties" );
|
||||
if ( propertyRoot )
|
||||
{
|
||||
for ( TiXmlElement *child = propertyRoot->FirstChildElement(); child != NULL; child = child->NextSiblingElement() )
|
||||
{
|
||||
// Get Field Data.
|
||||
const char *fieldName = child->Value();
|
||||
const char *fieldValue = child->GetText();
|
||||
|
||||
if ( !fieldValue )
|
||||
{
|
||||
// Clear Value.
|
||||
pObject->setField( fieldName, "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Apply Field Value.
|
||||
if ( !pObject->setField( fieldName, fieldValue ) )
|
||||
{
|
||||
// Invalid.
|
||||
Con::warnf( "VPersistence::readProperties() - Invalid property '%s'", fieldName );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Valid Read.
|
||||
return true;
|
||||
};
|
||||
|
||||
template <class T> bool readObjects( TiXmlElement *pElement, T *pObject )
|
||||
{
|
||||
for ( TiXmlElement *child = pElement->FirstChildElement( "VObject" ); child != NULL; child = child->NextSiblingElement( "VObject" ) )
|
||||
{
|
||||
// Get Object Type.
|
||||
const char *type = child->Attribute( "Type" );
|
||||
if ( !type || !AbstractClassRep::findClassRep( type ) )
|
||||
{
|
||||
// Invalid Type.
|
||||
Con::errorf( "VController::readObjects() - Invalid object type specified '%s'.", ( ( type ) ? type : "NULL" ) );
|
||||
|
||||
// Invalid Read.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create Object.
|
||||
VObject *object = dynamic_cast<VObject*>( ConsoleObject::create( type ) );
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
// Register SimObject.
|
||||
if ( !object->registerObject() )
|
||||
{
|
||||
// Delete.
|
||||
delete object;
|
||||
|
||||
// Invalid Read.
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Add Reference.
|
||||
object->addTo( pObject );
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
// Valid Method?
|
||||
if ( object->isMethod( "onAdd" ) )
|
||||
{
|
||||
// Callback.
|
||||
const char *retValue = Con::executef( object, "onAdd" );
|
||||
if ( !dAtob( retValue ) )
|
||||
{
|
||||
// Delete.
|
||||
object->deleteObject();
|
||||
|
||||
// Invalid Read.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Read Object.
|
||||
if ( !read( child, object ) )
|
||||
{
|
||||
#ifdef VT_EDITOR
|
||||
// Delete.
|
||||
object->deleteObject();
|
||||
#else
|
||||
// Delete.
|
||||
delete object;
|
||||
#endif
|
||||
|
||||
// Invalid Read.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Valid Read.
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VPERSISTENCE_H_
|
||||
31
Engine/source/Verve/Core/Util/VSharedEnum.cpp
Normal file
31
Engine/source/Verve/Core/Util/VSharedEnum.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "VSharedEnum.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Implement the Action enum list.
|
||||
ImplementEnumType( VActionToggle, "" )
|
||||
{ VSharedEnum::k_ActionTurnOn, "ON" },
|
||||
{ VSharedEnum::k_ActionTurnOff, "OFF" },
|
||||
EndImplementEnumType;
|
||||
49
Engine/source/Verve/Core/Util/VSharedEnum.h
Normal file
49
Engine/source/Verve/Core/Util/VSharedEnum.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VSHAREDENUM_H_
|
||||
#define _VT_VSHAREDENUM_H_
|
||||
|
||||
#ifndef _DYNAMIC_CONSOLETYPES_H_
|
||||
#include "console/dynamicTypes.h"
|
||||
#endif
|
||||
|
||||
namespace VSharedEnum
|
||||
{
|
||||
enum eActionToggle
|
||||
{
|
||||
k_ActionTurnOn,
|
||||
k_ActionTurnOff,
|
||||
};
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Define Types.
|
||||
typedef VSharedEnum::eActionToggle VActionToggle;
|
||||
|
||||
// Declare Enum Types.
|
||||
DefineEnumType( VActionToggle );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VSHAREDENUM_H_
|
||||
1160
Engine/source/Verve/Core/VController.cpp
Normal file
1160
Engine/source/Verve/Core/VController.cpp
Normal file
File diff suppressed because it is too large
Load diff
246
Engine/source/Verve/Core/VController.h
Normal file
246
Engine/source/Verve/Core/VController.h
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VCONTROLLER_H_
|
||||
#define _VT_VCONTROLLER_H_
|
||||
|
||||
#ifndef _VT_VERVECONFIG_H_
|
||||
#include "Verve/VerveConfig.h"
|
||||
#endif
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
|
||||
#ifndef _PROCESSLIST_H_
|
||||
#include "T3D/gameBase/processList.h"
|
||||
#endif
|
||||
|
||||
#ifndef _ITICKABLE_H_
|
||||
#include "core/iTickable.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_VPERSISTENCE_H_
|
||||
#include "Verve/Core/Persistence/VPersistence.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_VTREENODE_H_
|
||||
#include "Verve/Core/VTreeNode.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_VDATATABLE_H_
|
||||
#include "Verve/Core/VDataTable.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_TORQUE_CAMERA_H_
|
||||
#include "Verve/Torque/TCamera.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class VObject;
|
||||
|
||||
class VTrack;
|
||||
class VEvent;
|
||||
class VGroup;
|
||||
|
||||
class VDirectorGroup;
|
||||
class VDirectorTrack;
|
||||
|
||||
typedef VectorPtr<VTrack*> VTrackVector;
|
||||
typedef VTrackVector::iterator VTrackIterator;
|
||||
|
||||
typedef VectorPtr<VEvent*> VEventVector;
|
||||
typedef VEventVector::iterator VEventIterator;
|
||||
|
||||
typedef VectorPtr<VGroup*> VGroupVector;
|
||||
typedef VGroupVector::iterator VGroupIterator;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VController : public SimObject,
|
||||
public virtual ITickable,
|
||||
public VTreeNode
|
||||
{
|
||||
typedef SimObject Parent;
|
||||
|
||||
public:
|
||||
|
||||
enum eControllerStatus
|
||||
{
|
||||
k_StatusInit = BIT( 0 ),
|
||||
|
||||
k_StatusPlaying = BIT( 1 ),
|
||||
k_StatusPaused = BIT( 2 ),
|
||||
k_StatusStopped = BIT( 3 ),
|
||||
};
|
||||
|
||||
enum eControllerEventType
|
||||
{
|
||||
k_EventInit,
|
||||
k_EventReset,
|
||||
|
||||
k_EventPlay,
|
||||
k_EventPause,
|
||||
k_EventStop,
|
||||
|
||||
k_EventLoop,
|
||||
};
|
||||
|
||||
enum eControllerJumpType
|
||||
{
|
||||
k_JumpTime,
|
||||
k_JumpDelta,
|
||||
|
||||
k_JumpInvalid,
|
||||
};
|
||||
|
||||
typedef Signal<void( const S32 &pTime, const S32 &pDelta )> ControllerUpdateSignal;
|
||||
typedef Signal<bool( eControllerEventType )> ControllerEventSignal;
|
||||
|
||||
private:
|
||||
|
||||
// Data.
|
||||
|
||||
VDataTable mDataTable;
|
||||
|
||||
// Event Signal.
|
||||
|
||||
ControllerUpdateSignal mControllerUpdateSignal;
|
||||
ControllerEventSignal mControllerEventSignal;
|
||||
|
||||
// Properties.
|
||||
|
||||
S32 mStatus;
|
||||
|
||||
S32 mTime;
|
||||
U32 mLastTime;
|
||||
S32 mDuration;
|
||||
F32 mTimeScale;
|
||||
|
||||
bool mLoop;
|
||||
bool mLoopBackwards;
|
||||
S32 mLoopCount;
|
||||
S32 mLoopIndex;
|
||||
S32 mLoopDelay;
|
||||
S32 mLoopDelayTime;
|
||||
|
||||
eControllerJumpType mJump;
|
||||
S32 mJumpTime;
|
||||
|
||||
bool mResetOnCompletion;
|
||||
|
||||
public:
|
||||
|
||||
VController();
|
||||
~VController();
|
||||
|
||||
static void initPersistFields( void );
|
||||
|
||||
// ITickable.
|
||||
|
||||
void interpolateTick( F32 pDelta ) { };
|
||||
void advanceTime( F32 pDelta ) { };
|
||||
void processTick( void );
|
||||
void onPostTick( void );
|
||||
|
||||
// Controller.
|
||||
|
||||
void reset( void );
|
||||
void reset( const S32 &pTime );
|
||||
|
||||
void play( void );
|
||||
void play( const S32 &pTime );
|
||||
|
||||
void pause( void );
|
||||
void stop( const bool &pReset = true );
|
||||
|
||||
void jump( void );
|
||||
void jump( const eControllerJumpType &pType, const S32 &pDelta );
|
||||
|
||||
void updateStatus( const S32 &pStatus );
|
||||
|
||||
// Reference.
|
||||
|
||||
VGroup *getObject( const String &pLabel );
|
||||
template <class T> inline bool getObject( const String &pLabel, T *&pObject )
|
||||
{
|
||||
// Reference Group.
|
||||
pObject = dynamic_cast<T*>( getObject( pLabel ) );
|
||||
|
||||
// Valid?
|
||||
return ( pObject != NULL );
|
||||
}
|
||||
|
||||
bool getDataValue( const String &pFieldName, String &pValue );
|
||||
void clearData( void );
|
||||
void clearData( const S32 &pIndex );
|
||||
void clearData( const String &pFieldName );
|
||||
|
||||
void sort( void );
|
||||
|
||||
// Saving.
|
||||
|
||||
bool writeDataTable( TiXmlElement *pElement );
|
||||
|
||||
// Reading.
|
||||
|
||||
bool readDataTable( TiXmlElement *pElement );
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VController );
|
||||
|
||||
public:
|
||||
|
||||
inline VDataTable &getDataTable( void ) { return mDataTable; };
|
||||
|
||||
inline ControllerUpdateSignal &getControllerUpdateSignal( void ) { return mControllerUpdateSignal; };
|
||||
inline ControllerEventSignal &getControllerEventSignal( void ) { return mControllerEventSignal; };
|
||||
void postEvent( const eControllerEventType &pEvent );
|
||||
|
||||
VDirectorGroup *getDirectorGroup( void );
|
||||
VDirectorTrack *getDirectorTrack( void );
|
||||
|
||||
inline void setTime( const S32 &pTime ) { mTime = pTime; };
|
||||
inline void setDuration( const S32 &pDuration ) { mDuration = pDuration; };
|
||||
void setTimeScale( const F32 &pTimeScale );
|
||||
|
||||
inline bool isLooping( void ) { return mLoop; };
|
||||
inline bool isPlaying( void ) { return ( mStatus & k_StatusPlaying ); };
|
||||
inline bool isPaused( void ) { return ( mStatus & k_StatusPaused ); };
|
||||
inline bool isStopped( void ) { return ( mStatus & k_StatusStopped ); };
|
||||
inline bool isPlayingForward( void ) { return ( mTimeScale > 0.f ); };
|
||||
|
||||
inline S32 getTime( void ) { return mTime; };
|
||||
inline S32 getDuration( void ) { return mDuration; };
|
||||
inline F32 getTimeScale( void ) { return mTimeScale; };
|
||||
inline S32 getLoopDelayTime( void ) { return mLoopDelayTime; };
|
||||
|
||||
protected:
|
||||
|
||||
static bool setTime( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTime( dAtoi( pData ) ); return false; };
|
||||
static bool setDuration( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setDuration( dAtoi( pData ) ); return false; };
|
||||
static bool setTimeScale( void *pObject, const char *pArray, const char *pData ) { static_cast<VController*>( pObject )->setTimeScale( dAtof( pData ) ); return false; };
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VCONTROLLER_H_
|
||||
253
Engine/source/Verve/Core/VDataTable.cpp
Normal file
253
Engine/source/Verve/Core/VDataTable.cpp
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/VDataTable.h"
|
||||
|
||||
#include "console/simObject.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Implement the DataType enum list.
|
||||
ImplementEnumType( VDataTableDataType, "" )
|
||||
{ VDataTable::k_TypeExpression, "EXPRESSION" },
|
||||
{ VDataTable::k_TypeStatic, "STATIC" },
|
||||
{ VDataTable::k_TypeVariable, "VARIABLE" },
|
||||
EndImplementEnumType;
|
||||
|
||||
VDataTable::eDataType VDataTable::getDataTypeEnum( const char *pLabel )
|
||||
{
|
||||
VDataTable::eDataType out;
|
||||
if ( !castConsoleTypeFromString( out, pLabel ) )
|
||||
{
|
||||
// Bah!
|
||||
return VDataTable::k_TypeInvalid;
|
||||
}
|
||||
|
||||
// Return.
|
||||
return out;
|
||||
}
|
||||
|
||||
const char *VDataTable::getDataTypeDescription( const VDataTable::eDataType pEnum )
|
||||
{
|
||||
// Return.
|
||||
return castConsoleTypeToString( pEnum );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VDataTable::VDataTable( void )
|
||||
{
|
||||
mDataMap.clear();
|
||||
}
|
||||
|
||||
VDataTable::~VDataTable( void )
|
||||
{
|
||||
mDataMap.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::insert( pType, pFieldName );
|
||||
//
|
||||
// Add a DataTable entry, referencing the field name and assign it the given
|
||||
// data type.
|
||||
//
|
||||
// For a full list of possible data types, see the 'eDataType' declaration in
|
||||
// VDataTable.h.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VDataTable::insert( eDataType pType, const String &pFieldName )
|
||||
{
|
||||
if ( mDataMap.contains( pFieldName ) )
|
||||
{
|
||||
// Change Field Type.
|
||||
mDataMap.find( pFieldName )->value.Type = pType;
|
||||
|
||||
// Return.
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert Item.
|
||||
mDataMap.insert( pFieldName, sDataItem( pType, pFieldName ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::clear( pFieldName );
|
||||
//
|
||||
// Clear the DataTable entry with the given field name.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VDataTable::clear( const String &pFieldName )
|
||||
{
|
||||
// Clear Item.
|
||||
mDataMap.erase( pFieldName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::clear();
|
||||
//
|
||||
// Clear the contents of the DataTable entirely.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VDataTable::clear( void )
|
||||
{
|
||||
// Clear.
|
||||
mDataMap.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::getCount();
|
||||
//
|
||||
// Return the number of DataTable entries.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
S32 VDataTable::getCount( void )
|
||||
{
|
||||
return mDataMap.size();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::getItem( pIndex, *pDataItem );
|
||||
//
|
||||
// Return the item with the given index. This method will return false if there
|
||||
// is no valid data entry with that index.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VDataTable::getItem( const S32 &pIndex, sDataItem *pDataItem )
|
||||
{
|
||||
if ( pIndex < 0 || pIndex >= mDataMap.size() )
|
||||
{
|
||||
// Invalid Field.
|
||||
return false;
|
||||
}
|
||||
|
||||
S32 index = 0;
|
||||
for ( VDataMap::Iterator itr = mDataMap.begin(); itr != mDataMap.end(); ++itr )
|
||||
{
|
||||
if ( index == pIndex )
|
||||
{
|
||||
if ( pDataItem )
|
||||
{
|
||||
// Store Reference.
|
||||
*pDataItem = ( itr->value );
|
||||
}
|
||||
|
||||
// Valid Field.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Increment.
|
||||
++index;
|
||||
}
|
||||
|
||||
// Invalid Field.
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::getItem( pFieldName, *pDataItem );
|
||||
//
|
||||
// Return the item with the given field name. This method will return false if
|
||||
// there is no valid data entry with that name.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VDataTable::getItem( const String &pFieldName, sDataItem *pDataItem )
|
||||
{
|
||||
if ( mDataMap.contains( pFieldName ) )
|
||||
{
|
||||
if ( pDataItem )
|
||||
{
|
||||
// Fetch Item
|
||||
*pDataItem = mDataMap.find( pFieldName )->value;
|
||||
}
|
||||
|
||||
// Valid Field.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Invalid Field.
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VDataTable::getValue( pObject, pFieldName, *pValue );
|
||||
//
|
||||
// Evaluate and return the expression provided in the data field.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VDataTable::getValue( SimObject *pObject, const String &pFieldName, String &pValue )
|
||||
{
|
||||
if ( !pObject || pFieldName.isEmpty() )
|
||||
{
|
||||
// Sanity!
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fetch Data.
|
||||
sDataItem *data = &( mDataMap.find( pFieldName )->value );
|
||||
if ( !data )
|
||||
{
|
||||
// No Field.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Field Value.
|
||||
const char *fieldValue = pObject->getDataField( StringTable->insert( data->FieldName ), NULL );
|
||||
|
||||
switch ( data->Type )
|
||||
{
|
||||
case VDataTable::k_TypeExpression :
|
||||
{
|
||||
// Evaluate.
|
||||
pValue = Con::evaluate( fieldValue, false ).getStringValue();
|
||||
|
||||
} break;
|
||||
|
||||
case VDataTable::k_TypeStatic :
|
||||
{
|
||||
// Use Value.
|
||||
pValue = fieldValue;
|
||||
|
||||
} break;
|
||||
|
||||
case VDataTable::k_TypeVariable :
|
||||
{
|
||||
|
||||
// Fetch Variable.
|
||||
pValue = Con::getVariable( fieldValue );
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
// Valid Field.
|
||||
return true;
|
||||
}
|
||||
118
Engine/source/Verve/Core/VDataTable.h
Normal file
118
Engine/source/Verve/Core/VDataTable.h
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VDATATABLE_H_
|
||||
#define _VT_VDATATABLE_H_
|
||||
|
||||
#ifndef CORE_TDICTIONARY_H
|
||||
#include "core/util/tDictionary.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLE_H_
|
||||
#include "console/console.h"
|
||||
#endif
|
||||
|
||||
#ifndef _DYNAMIC_CONSOLETYPES_H_
|
||||
#include "console/dynamicTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _STRINGTABLE_H_
|
||||
#include "core/stringTable.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VDataTable
|
||||
{
|
||||
public:
|
||||
|
||||
enum eDataType
|
||||
{
|
||||
k_TypeExpression,
|
||||
k_TypeStatic,
|
||||
k_TypeVariable,
|
||||
|
||||
k_TypeInvalid,
|
||||
};
|
||||
|
||||
struct sDataItem
|
||||
{
|
||||
eDataType Type;
|
||||
String FieldName;
|
||||
|
||||
sDataItem( void ) :
|
||||
Type( k_TypeInvalid ),
|
||||
FieldName( String::EmptyString )
|
||||
{
|
||||
// Void.
|
||||
};
|
||||
|
||||
sDataItem( eDataType pType, const String &pFieldName ) :
|
||||
Type( pType ),
|
||||
FieldName( pFieldName )
|
||||
{
|
||||
// Void.
|
||||
};
|
||||
};
|
||||
|
||||
// Enum Lookup.
|
||||
static VDataTable::eDataType getDataTypeEnum( const char *pLabel );
|
||||
static const char *getDataTypeDescription( const VDataTable::eDataType pEnum );
|
||||
|
||||
// Map Type.
|
||||
typedef Map<String, sDataItem> VDataMap;
|
||||
|
||||
public:
|
||||
|
||||
VDataMap mDataMap;
|
||||
|
||||
public:
|
||||
|
||||
VDataTable( void );
|
||||
~VDataTable( void );
|
||||
|
||||
// Data.
|
||||
|
||||
void insert( eDataType pType, const String &pFieldName );
|
||||
void clear( const String &pFieldName );
|
||||
void clear( void );
|
||||
|
||||
// Reference.
|
||||
|
||||
S32 getCount( void );
|
||||
bool getItem( const S32 &pIndex, sDataItem *pDataItem = NULL );
|
||||
bool getItem( const String &pFieldName, sDataItem *pDataItem = NULL );
|
||||
|
||||
bool getValue( SimObject *pObject, const String &pFieldName, String &pValue );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Define Types.
|
||||
typedef VDataTable::eDataType VDataTableDataType;
|
||||
|
||||
// Declare Enum Types.
|
||||
DefineEnumType( VDataTableDataType );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VDATATABLE_H_
|
||||
406
Engine/source/Verve/Core/VEvent.cpp
Normal file
406
Engine/source/Verve/Core/VEvent.cpp
Normal file
|
|
@ -0,0 +1,406 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/VEvent.h"
|
||||
#include "Verve/Core/VGroup.h"
|
||||
#include "Verve/Core/VTrack.h"
|
||||
|
||||
#include "console/consoleTypes.h"
|
||||
#include "math/mMathFn.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_CONOBJECT( VEvent );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VEvent::VEvent( void ) :
|
||||
mIsPlaying( false ),
|
||||
mTriggered( false ),
|
||||
mTriggerTime( 0 ),
|
||||
mDuration( 0 )
|
||||
{
|
||||
setLabel( "DefaultEvent" );
|
||||
}
|
||||
|
||||
void VEvent::initPersistFields( void )
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addProtectedField( "TriggerTime", TypeS32, Offset( mTriggerTime, VEvent ), &setTriggerTime, &defaultProtectedGetFn, "The time that this event is triggered." );
|
||||
addProtectedField( "Duration", TypeS32, Offset( mDuration, VEvent ), &setDuration, &defaultProtectedGetFn, "The total duration that this event plays for." );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Controller Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::onControllerReset( pTime, pForward );
|
||||
//
|
||||
// Reset the status of the event. If the given time is between the event's
|
||||
// start and finish times, then the isPlaying flag will be true. This means
|
||||
// that the event is free to be triggered upon playback.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VEvent::onControllerReset( const S32 &pTime, const bool &pForward )
|
||||
{
|
||||
// Reset Status.
|
||||
mIsPlaying = ( pTime > mTriggerTime && pTime < ( mTriggerTime + mDuration ) );
|
||||
mTriggered = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::onControllerUpdate( pTime, pDelta )
|
||||
//
|
||||
// Integrate is only called when this event is the Next Event for the parent
|
||||
// track. For each track, there is only ever *one* event being integrated - the
|
||||
// event that needs to be triggered next.
|
||||
//
|
||||
// If the event has a duration greater than 0, then this event will continue to
|
||||
// integrate until its time is up, or the controller finishes playing
|
||||
// (whichever happens first).
|
||||
//
|
||||
// If a value of true is returned, then this event will continue to integrate
|
||||
// until a value of false is returned to the parent track. When this happens,
|
||||
// this event ceases to be the track's Next Event and will not continue
|
||||
// updating.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VEvent::onControllerUpdate( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
if ( !isEnabled() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const S32 newTime = ( pTime + pDelta );
|
||||
const S32 &startTime = getStartTime();
|
||||
const S32 &finishTime = getFinishTime();
|
||||
|
||||
if ( !mIsPlaying || !mTriggered )
|
||||
{
|
||||
if ( !mIsPlaying )
|
||||
{
|
||||
if ( ( pDelta > 0 && newTime < startTime )
|
||||
|| ( pDelta < 0 && newTime > startTime ) )
|
||||
{
|
||||
// Not Time to Trigger.
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ( pDelta > 0 && pTime > startTime )
|
||||
|| ( pDelta < 0 && pTime < startTime ) )
|
||||
{
|
||||
//AssertFatal( false, "VEvent::onControllerUpdate() - Event has been skipped." );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !mTriggered )
|
||||
{
|
||||
// Play and Trigger.
|
||||
mIsPlaying = ( mDuration > 0 );
|
||||
mTriggered = true;
|
||||
|
||||
// Callback.
|
||||
onTrigger( pTime, pDelta );
|
||||
|
||||
if ( mDuration == 0 )
|
||||
{
|
||||
// Stop Integrating.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return Here.
|
||||
// Note: If Duration is non-zero this event will continue to update
|
||||
// so that VEvent:: onUpdate is processed for the full event
|
||||
// duration.
|
||||
return ( mDuration != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// Complete?
|
||||
const bool isComplete = ( ( pDelta > 0 && newTime > finishTime )
|
||||
|| ( pDelta < 0 && newTime < finishTime ) );
|
||||
|
||||
if ( !isComplete )
|
||||
{
|
||||
// Callback.
|
||||
onUpdate( pTime, pDelta );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Complete.
|
||||
mIsPlaying = false;
|
||||
|
||||
// Callback.
|
||||
onComplete( pTime, pDelta );
|
||||
}
|
||||
|
||||
// Continue?
|
||||
return !isComplete;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Callback Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::onTrigger( pTime, pDelta );
|
||||
//
|
||||
// This method is called when an event is due to be triggered. This method is
|
||||
// meant to be overloaded by derived classes.
|
||||
//
|
||||
// For examples of what an event might do, please refer to some of the included
|
||||
// events with Verve.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VEvent::onTrigger( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
// Void.
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::onUpdate( pTime, pDelta );
|
||||
//
|
||||
// This method is called each tick once an event has been triggered and ceases
|
||||
// to be called when it is completed. This method is meant to be overloaded by
|
||||
// derived classes.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VEvent::onUpdate( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
// Void.
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::onComplete( pTime, pDelta );
|
||||
//
|
||||
// This method is called once an event has finished being updated. It is not
|
||||
// called on events that have a duration of 0. This method is meant to be
|
||||
// overloaded by derived classes.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VEvent::onComplete( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
// Void.
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Property Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::getGroup();
|
||||
//
|
||||
// Returns the parent group.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VGroup *VEvent::getGroup( void )
|
||||
{
|
||||
VTrack *track = getTrack();
|
||||
if ( track )
|
||||
{
|
||||
return track->getGroup();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::getTrack();
|
||||
//
|
||||
// Returns the parent track.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VTrack *VEvent::getTrack( void )
|
||||
{
|
||||
return dynamic_cast<VTrack*>( mParentNode );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::getNextEvent();
|
||||
//
|
||||
// Returns the next event.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VEvent *VEvent::getNextEvent( void )
|
||||
{
|
||||
if ( !isControllerPlayingForward() )
|
||||
{
|
||||
return dynamic_cast<VEvent*>( mSiblingPrevNode );
|
||||
}
|
||||
|
||||
return dynamic_cast<VEvent*>( mSiblingNextNode );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::getPreviousEvent();
|
||||
//
|
||||
// Returns the previous event.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VEvent *VEvent::getPreviousEvent( void )
|
||||
{
|
||||
if ( !isControllerPlayingForward() )
|
||||
{
|
||||
return dynamic_cast<VEvent*>( mSiblingNextNode );
|
||||
}
|
||||
|
||||
return dynamic_cast<VEvent*>( mSiblingPrevNode );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::getStartTime();
|
||||
//
|
||||
// Returns the time, in milliseconds, that the event is due to trigger.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
S32 VEvent::getStartTime( void )
|
||||
{
|
||||
return ( mTriggerTime + ( !isControllerPlayingForward() * mDuration ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::getFinishTime();
|
||||
//
|
||||
// Returns the time, in milliseconds, that the event will cease updating.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
S32 VEvent::getFinishTime( void )
|
||||
{
|
||||
return ( mTriggerTime + ( isControllerPlayingForward() * mDuration ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::setTriggerTime( pTime );
|
||||
//
|
||||
// Apply the given trigger time to the object.
|
||||
//
|
||||
// If the project was built using the VT_EDITOR preprocessor argument, then
|
||||
// the validity of the passed value is verified. It also cannot be changed
|
||||
// while the controller is playing.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VEvent::setTriggerTime( const S32 &pTime )
|
||||
{
|
||||
#ifdef VT_EDITOR
|
||||
|
||||
VTrack *track = getTrack();
|
||||
if ( !track )
|
||||
{
|
||||
// Apply Time.
|
||||
mTriggerTime = pTime;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( track->isControllerPlaying() )
|
||||
{
|
||||
// Don't Change While Playing.
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
// Check For Overlap.
|
||||
for ( ITreeNode *node = mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
VEvent *event = ( VEvent* )node;
|
||||
if ( event == this )
|
||||
{
|
||||
// Skip.
|
||||
continue;
|
||||
}
|
||||
|
||||
const U32 startTime = getStartTime();
|
||||
const U32 finishTime = getFinishTime();
|
||||
|
||||
if ( ( pTime > startTime && pTime < finishTime )
|
||||
|| ( ( pTime + mDuration ) > startTime && ( pTime + mDuration ) < finishTime )
|
||||
|| ( pTime < startTime && ( pTime + mDuration ) > finishTime ) )
|
||||
{
|
||||
// Overlap!
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Apply Time.
|
||||
mTriggerTime = mClamp( pTime, 0, getControllerDuration() );
|
||||
|
||||
// Sort Events.
|
||||
track->sort();
|
||||
|
||||
// Reset Track.
|
||||
track->onControllerReset( getControllerTime(), isControllerPlayingForward() );
|
||||
|
||||
#else
|
||||
|
||||
// Apply Time.
|
||||
mTriggerTime = pTime;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VEvent::setDuration( pDuration );
|
||||
//
|
||||
// Apply the given duration time to the object.
|
||||
//
|
||||
// If the project was built using the VT_EDITOR preprocessor argument, then
|
||||
// the validity of the passed value is verified. It also cannot be changed
|
||||
// while the controller is playing.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VEvent::setDuration( const S32 &pDuration )
|
||||
{
|
||||
#ifdef VT_EDITOR
|
||||
|
||||
if ( isControllerPlaying() )
|
||||
{
|
||||
// Don't Change While Playing.
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Apply Duration.
|
||||
mDuration = pDuration;
|
||||
}
|
||||
109
Engine/source/Verve/Core/VEvent.h
Normal file
109
Engine/source/Verve/Core/VEvent.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VEVENT_H_
|
||||
#define _VT_VEVENT_H_
|
||||
|
||||
#ifndef _VT_VOBJECT_H_
|
||||
#include "Verve/Core/VObject.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class VGroup;
|
||||
class VTrack;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VEvent : public VObject
|
||||
{
|
||||
typedef VObject Parent;
|
||||
|
||||
protected:
|
||||
|
||||
bool mIsPlaying;
|
||||
bool mTriggered;
|
||||
|
||||
S32 mTriggerTime;
|
||||
S32 mDuration;
|
||||
|
||||
public:
|
||||
|
||||
VEvent( void );
|
||||
|
||||
static void initPersistFields( void );
|
||||
|
||||
// Controller Methods.
|
||||
|
||||
virtual void onControllerReset( const S32 &pTime, const bool &pForward );
|
||||
virtual bool onControllerUpdate( const S32 &pTime, const S32 &pDelta );
|
||||
|
||||
// Callback Methods.
|
||||
|
||||
virtual void onTrigger( const S32 &pTime, const S32 &pDelta );
|
||||
virtual void onUpdate( const S32 &pTime, const S32 &pDelta );
|
||||
virtual void onComplete( const S32 &pTime, const S32 &pDelta );
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VEvent );
|
||||
|
||||
public:
|
||||
|
||||
// Property Methods.
|
||||
|
||||
VGroup *getGroup( void );
|
||||
template <class T> inline bool getGroup( T *&pGroup )
|
||||
{
|
||||
// Reference Group.
|
||||
pGroup = dynamic_cast<T*>( getGroup() );
|
||||
// Validate.
|
||||
return ( pGroup != NULL );
|
||||
}
|
||||
|
||||
VTrack *getTrack( void );
|
||||
template <class T> inline bool getTrack( T *&pTrack )
|
||||
{
|
||||
// Reference Track.
|
||||
pTrack = dynamic_cast<T*>( getTrack() );
|
||||
// Validate.
|
||||
return ( pTrack != NULL );
|
||||
}
|
||||
|
||||
VEvent *getNextEvent( void );
|
||||
VEvent *getPreviousEvent( void );
|
||||
|
||||
inline bool isPlaying( void ) { return mIsPlaying; };
|
||||
inline S32 getTriggerTime( void ) { return mTriggerTime; };
|
||||
inline S32 getDuration( void ) { return mDuration; };
|
||||
|
||||
virtual S32 getStartTime( void );
|
||||
virtual S32 getFinishTime( void );
|
||||
|
||||
virtual void setTriggerTime( const S32 &pTime );
|
||||
virtual void setDuration( const S32 &pDuration );
|
||||
|
||||
static bool setTriggerTime( void *obj, const char *pArray, const char *data ) { static_cast<VEvent*>( obj )->setTriggerTime( dAtoi( data ) ); return false; };
|
||||
static bool setDuration( void *obj, const char *pArray, const char *data ) { static_cast<VEvent*>( obj )->setDuration( dAtoi( data ) ); return false; };
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VEVENT_H_
|
||||
32
Engine/source/Verve/Core/VGroup.cpp
Normal file
32
Engine/source/Verve/Core/VGroup.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/VGroup.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_CONOBJECT( VGroup );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VGroup::VGroup( void )
|
||||
{
|
||||
setLabel( "DefaultGroup" );
|
||||
};
|
||||
47
Engine/source/Verve/Core/VGroup.h
Normal file
47
Engine/source/Verve/Core/VGroup.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VGROUP_H_
|
||||
#define _VT_VGROUP_H_
|
||||
|
||||
#ifndef _VT_VOBJECT_H_
|
||||
#include "Verve/Core/VObject.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VGroup : public VObject
|
||||
{
|
||||
typedef VObject Parent;
|
||||
|
||||
public:
|
||||
|
||||
VGroup( void );
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VGroup );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VGROUP_H_
|
||||
489
Engine/source/Verve/Core/VObject.cpp
Normal file
489
Engine/source/Verve/Core/VObject.cpp
Normal file
|
|
@ -0,0 +1,489 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/VObject.h"
|
||||
#include "Verve/Core/VController.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_CONOBJECT( VObject );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VObject::VObject( void ) :
|
||||
mController( NULL ),
|
||||
mLabel( String::EmptyString ),
|
||||
mEnabled( true )
|
||||
{
|
||||
// Void.
|
||||
};
|
||||
|
||||
VObject::~VObject( void )
|
||||
{
|
||||
// Remove.
|
||||
remove();
|
||||
}
|
||||
|
||||
void VObject::initPersistFields( void )
|
||||
{
|
||||
// Don't Use Parent Fields.
|
||||
// Parent::initPersistFields();
|
||||
|
||||
addProtectedField( "Enabled", TypeBool, Offset( mEnabled, VObject ), &setEnabled, &defaultProtectedGetFn, "Enable or Disable the object from playback." );
|
||||
addProtectedField( "Label", TypeRealString, Offset( mLabel, VObject ), &setLabel, &defaultProtectedGetFn, "The label this object is referenced by." );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Reference Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::getObject( pLabel );
|
||||
//
|
||||
// Returns the object with the given label. If no object belongs to this object
|
||||
// with that label, then a NULL value is returned.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VObject *VObject::getObject( const String &pLabel )
|
||||
{
|
||||
VObject *node = ( VObject* )mChildNode;
|
||||
while ( node )
|
||||
{
|
||||
// Compare Names.
|
||||
if ( node->getLabel().equal( pLabel, String::NoCase ) )
|
||||
{
|
||||
// Valid.
|
||||
return node;
|
||||
}
|
||||
|
||||
// Next Sibling.
|
||||
node = ( VObject* )node->mSiblingNextNode;
|
||||
}
|
||||
|
||||
// Invalid.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Property Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::isEnabled();
|
||||
//
|
||||
// Returns whether this object is enabled.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VObject::isEnabled( void )
|
||||
{
|
||||
VObject *parent = dynamic_cast<VObject*>( getParent() );
|
||||
if ( parent && !parent->isEnabled() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::isControllerPlaying();
|
||||
//
|
||||
// Returns whether the root controller is currently playing.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VObject::isControllerPlaying( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->isPlaying();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::isControllerPaused();
|
||||
//
|
||||
// Returns whether the root controller is currently paused.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VObject::isControllerPaused( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->isPaused();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::isControllerStopped();
|
||||
//
|
||||
// Returns whether the root controller is currently stopped.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VObject::isControllerStopped( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->isStopped();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::isControllerPlayingForward();
|
||||
//
|
||||
// Returns whether the root controller is currently playing forward.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VObject::isControllerPlayingForward( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->isPlayingForward();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::isControllerLooping();
|
||||
//
|
||||
// Returns whether the root controller is looping the sequence.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VObject::isControllerLooping( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->isLooping();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::getControllerTime();
|
||||
//
|
||||
// Returns the current time of the root controller.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
S32 VObject::getControllerTime( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->getTime();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::getControllerTimeScale();
|
||||
//
|
||||
// Returns the current timescale of the root controller.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
F32 VObject::getControllerTimeScale( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->getTimeScale();
|
||||
}
|
||||
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::getControllerDuration();
|
||||
//
|
||||
// Returns the duration of the root controller.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
S32 VObject::getControllerDuration( void )
|
||||
{
|
||||
if ( getController() )
|
||||
{
|
||||
return getController()->getDuration();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::setLabel( pLabel );
|
||||
//
|
||||
// Set the label property.
|
||||
//
|
||||
// If the project was built using the VT_EDITOR preprocessor argument, then the
|
||||
// label will not be changed if the target name is already used in the parent
|
||||
// object.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VObject::setLabel( const String &pLabel )
|
||||
{
|
||||
#ifdef VT_EDITOR
|
||||
if ( mParentNode )
|
||||
{
|
||||
// Empty Label?
|
||||
if ( mLabel.isEmpty() )
|
||||
{
|
||||
// Set Uniqu Label.
|
||||
setLabelUnique( pLabel );
|
||||
return;
|
||||
}
|
||||
|
||||
for ( VObject *walk = ( VObject* )mChildNode; walk != NULL; walk = ( VObject* )walk->mSiblingNextNode )
|
||||
{
|
||||
if ( walk != this )
|
||||
{
|
||||
if ( pLabel == walk->getLabel() )
|
||||
{
|
||||
// Exit.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set Label.
|
||||
mLabel = pLabel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::setLabelUnique( pLabel );
|
||||
//
|
||||
// If the label that has been passed is already in use, then a new label will
|
||||
// be generated by appending an index to the label. For example: MyLabel
|
||||
// becomes MyLabel0 ... MyLabelN
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VObject::setLabelUnique( const String &pLabel )
|
||||
{
|
||||
if ( mParentNode && pLabel.isNotEmpty() )
|
||||
{
|
||||
for ( VObject *walk = ( VObject* )mChildNode; walk != NULL; walk = ( VObject* )walk->mSiblingNextNode )
|
||||
{
|
||||
if ( walk != this )
|
||||
{
|
||||
if ( pLabel == walk->getLabel() )
|
||||
{
|
||||
// Strip Trailing Number.
|
||||
S32 i = -1;
|
||||
String labelBase( String::GetTrailingNumber( pLabel, i ) );
|
||||
i++;
|
||||
|
||||
// Construct New Name.
|
||||
String labelBuffer = String::ToString( "%s%d", labelBase.c_str(), i );
|
||||
|
||||
// Set Name.
|
||||
setLabelUnique( labelBuffer );
|
||||
|
||||
// Exit.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set Name.
|
||||
mLabel = pLabel;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Callback Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::onAttach();
|
||||
//
|
||||
// Callback made when this object is attached to another node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VObject::onAttach( void )
|
||||
{
|
||||
VTreeNode::onAttach();
|
||||
|
||||
// Store Controller.
|
||||
mController = dynamic_cast<VController*>( getRoot() );
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
if ( isProperlyAdded() )
|
||||
{
|
||||
Con::executef( this, "onAttach" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VObject::onDetach();
|
||||
//
|
||||
// Callback made when this object is detached from a parent node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VObject::onDetach( void )
|
||||
{
|
||||
VTreeNode::onDetach();
|
||||
|
||||
// Clear Controller.
|
||||
mController = NULL;
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
if ( isProperlyAdded() )
|
||||
{
|
||||
Con::executef( this, "onDetach" );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Debug Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod( VObject, writeFile, bool, (String fileName), (""), "( string pFileName ) - Save to a given filename.\n"
|
||||
"@param pFileName The target file to write to.\n"
|
||||
"@return Returns true if the write was successful." )
|
||||
{
|
||||
// Write Target File.
|
||||
return VPersistence::writeFile(fileName.c_str(), object );
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, readFile, bool, (String fileName), (""), "( string pFileName ) - Clears the object and loads the new data from the given filename.\n"
|
||||
"@param pFileName The target file to read from.\n"
|
||||
"@return Returns true if the read was successful." )
|
||||
{
|
||||
// Read Target File.
|
||||
return VPersistence::readFile(fileName.c_str(), object );
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, getRoot, S32, (),, "( void ) - Get the root object.\n"
|
||||
"@return Returns the SimObjectId for the root object." )
|
||||
{
|
||||
// Fetch Object.
|
||||
VObject *objectRef = ( VObject* )object->getRoot();
|
||||
|
||||
// Return Object ID.
|
||||
return ( objectRef ) ? objectRef->getId() : 0;
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, getParent, S32, (),, "( void ) - Get the parent object.\n"
|
||||
"@return Returns the SimObjectId for the parent object." )
|
||||
{
|
||||
// Fetch Object.
|
||||
VObject *objectRef = ( VObject* )object->mParentNode;
|
||||
|
||||
// Return Object ID.
|
||||
return ( objectRef ) ? objectRef->getId() : 0;
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, getIndex, S32, (),, "( void ) - Get the index of this object relative to its siblings.\n"
|
||||
"@return Returns the index of this object." )
|
||||
{
|
||||
return object->getIndex();
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, getCount, S32, (),, "( void ) - Get the number of child objects.\n"
|
||||
"@return Returns the number of child objects." )
|
||||
{
|
||||
return object->size();
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, getObject, S32, (S32 index), (0), "( int pIndex ) - Get the object corresponding to the given index.\n"
|
||||
"@param pIndex The index of the object you wish to retrieve.\n"
|
||||
"@return Returns the SimObjectID for the object." )
|
||||
{
|
||||
// Fetch Object.
|
||||
VObject *objectRef = ( VObject* )object->at(index);
|
||||
|
||||
// Return Object ID.
|
||||
return ( objectRef ) ? objectRef->getId() : 0;
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, clear, void, (),, "( void ) - Detaches and deletes all of the child objects.\n"
|
||||
"@return No return value." )
|
||||
{
|
||||
// Clear Sequence Lists.
|
||||
object->clear();
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, addObject, void, (SimObject* simObj), (nullAsType<SimObject*>()), "( SimObject pObject ) - Add a child object to this node.\n"
|
||||
"@param pObject The SimObjectID of the object to be added to this node.\n"
|
||||
"@return No return value." )
|
||||
{
|
||||
if (simObj == nullptr)
|
||||
return;
|
||||
|
||||
VObject *child = dynamic_cast<VObject*>(simObj);
|
||||
if ( child )
|
||||
{
|
||||
child->addTo( object );
|
||||
}
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, removeObject, void, (SimObject* simObj), (nullAsType<SimObject*>()), "( SimObject pObject ) - Remove the target object from this node.\n"
|
||||
"@param pObject The SimObjectID of the object to be removed from this node.\n"
|
||||
"@return No return value." )
|
||||
{
|
||||
if (simObj == nullptr)
|
||||
return;
|
||||
|
||||
VObject *child = dynamic_cast<VObject*>(simObj);
|
||||
if ( child && child->getParent() == object )
|
||||
{
|
||||
child->remove();
|
||||
}
|
||||
}
|
||||
|
||||
DefineEngineMethod( VObject, setLabelUnique, void, (String label), (""), "( string pLabel ) - Force this label to be unique.\n"
|
||||
"@param pLabel The name you wish to reference this object by.\n"
|
||||
"@return No return value." )
|
||||
{
|
||||
// Set Label.
|
||||
object->setLabelUnique(label);
|
||||
}
|
||||
#endif
|
||||
126
Engine/source/Verve/Core/VObject.h
Normal file
126
Engine/source/Verve/Core/VObject.h
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VOBJECT_H_
|
||||
#define _VT_VOBJECT_H_
|
||||
|
||||
#ifndef _VT_VERVECONFIG_H_
|
||||
#include "Verve/VerveConfig.h"
|
||||
#endif
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
#ifndef _SIMOBJECT_H_
|
||||
#include "console/simObject.h"
|
||||
#endif
|
||||
|
||||
#define VObjectRep SimObject
|
||||
#else
|
||||
#ifndef _CONSOLEOBJECT_H_
|
||||
#include "console/consoleObject.h"
|
||||
#endif
|
||||
|
||||
#define VObjectRep ConsoleObject
|
||||
#endif
|
||||
|
||||
#ifndef _VT_VTREENODE_H_
|
||||
#include "Verve/Core/VTreeNode.h"
|
||||
#endif
|
||||
|
||||
#ifndef TINYXML_INCLUDED
|
||||
#include "tinyxml/tinyxml.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class VController;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VObject : public VObjectRep,
|
||||
public VTreeNode
|
||||
{
|
||||
typedef VObjectRep Parent;
|
||||
|
||||
protected:
|
||||
|
||||
VController *mController;
|
||||
|
||||
String mLabel;
|
||||
bool mEnabled;
|
||||
|
||||
public:
|
||||
|
||||
VObject( void );
|
||||
virtual ~VObject( void );
|
||||
|
||||
static void initPersistFields( void );
|
||||
|
||||
// Reference Methods.
|
||||
|
||||
VObject *getObject( const String &pLabel );
|
||||
template <class T> inline bool getObject( const String &pLabel, T *&pObject )
|
||||
{
|
||||
// Reference Object.
|
||||
pObject = dynamic_cast<T*>( getObject( pLabel ) );
|
||||
|
||||
// Valid?
|
||||
return ( pObject != NULL );
|
||||
}
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VObject );
|
||||
|
||||
public:
|
||||
|
||||
// Property Methods.
|
||||
|
||||
inline VController *getController( void ) { return mController; };
|
||||
|
||||
inline const String &getLabel( void ) const { return mLabel; };
|
||||
bool isEnabled( void );
|
||||
|
||||
bool isControllerPlaying( void );
|
||||
bool isControllerPaused( void );
|
||||
bool isControllerStopped( void );
|
||||
bool isControllerPlayingForward( void );
|
||||
bool isControllerLooping( void );
|
||||
S32 getControllerTime( void );
|
||||
F32 getControllerTimeScale( void );
|
||||
S32 getControllerDuration( void );
|
||||
|
||||
virtual void setLabel( const String &pLabel );
|
||||
void setLabelUnique( const String &pLabel );
|
||||
inline void setEnabled( const bool &pEnabled ) { mEnabled = pEnabled; };
|
||||
|
||||
// Callback Methods.
|
||||
|
||||
virtual void onAttach( void );
|
||||
virtual void onDetach( void );
|
||||
|
||||
// Static Methods.
|
||||
|
||||
static bool setEnabled( void *pObject, const char *pArray, const char *pData ) { static_cast<VObject*>( pObject )->setEnabled( dAtob( pData ) ); return false; };
|
||||
static bool setLabel( void *pObject, const char *pArray, const char *pData ) { static_cast<VObject*>( pObject )->setLabel( pData ); return false; };
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VOBJECT_H_
|
||||
448
Engine/source/Verve/Core/VTrack.cpp
Normal file
448
Engine/source/Verve/Core/VTrack.cpp
Normal file
|
|
@ -0,0 +1,448 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/VTrack.h"
|
||||
#include "Verve/Core/VGroup.h"
|
||||
#include "Verve/Core/VController.h"
|
||||
#include "math/mMath.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_CONOBJECT( VTrack );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VTrack::VTrack( void ) :
|
||||
mNextEvent( NULL )
|
||||
{
|
||||
setLabel( "DefaultTrack" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Tree Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::onAttach();
|
||||
//
|
||||
// This callback subscribes this object to the controller's event signal.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTrack::onAttach( void )
|
||||
{
|
||||
Parent::onAttach();
|
||||
|
||||
// Valid Controller?
|
||||
if ( getController() )
|
||||
{
|
||||
// Subscribe to Updates.
|
||||
getController()->getControllerUpdateSignal().notify( this, &VTrack::onControllerUpdate );
|
||||
|
||||
// Subscribe to Events.
|
||||
getController()->getControllerEventSignal().notify( this, &VTrack::onControllerEvent );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::onAttach();
|
||||
//
|
||||
// This callback removes this object from the controller's event signal
|
||||
// notification list.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTrack::onDetach( void )
|
||||
{
|
||||
// Valid Controller?
|
||||
if ( getController() )
|
||||
{
|
||||
// Remove Update Notification.
|
||||
getController()->getControllerUpdateSignal().remove( this, &VTrack::onControllerUpdate );
|
||||
|
||||
// Remove Event Notification.
|
||||
getController()->getControllerEventSignal().remove( this, &VTrack::onControllerEvent );
|
||||
}
|
||||
|
||||
Parent::onDetach();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Controller Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::onControllerUpdate( pTime, pDelta );
|
||||
//
|
||||
// The Next Event is integrated until has finished its execution. Once it has
|
||||
// finished, the next event to be triggered becomes the Current Event. Doing
|
||||
// this means that only one event is ever checked to see if it should be
|
||||
// triggered.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTrack::onControllerUpdate( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
if ( !isEnabled() || !mNextEvent )
|
||||
{
|
||||
// Don't Update.
|
||||
return;
|
||||
}
|
||||
|
||||
// Update Next Event.
|
||||
while ( !mNextEvent->onControllerUpdate( pTime, pDelta ) )
|
||||
{
|
||||
// Next Event?
|
||||
if ( !updateNextEvent() )
|
||||
{
|
||||
// No Valid Events.
|
||||
mNextEvent = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::onControllerEvent( pEvent );
|
||||
//
|
||||
// When the controller's state changes, this method is called. If the
|
||||
// controller is reset the virtual method, onControllerReset is called.
|
||||
//
|
||||
// For a full list of possible events, see the 'eControllerEventType'
|
||||
// declaration in VController.h.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VTrack::onControllerEvent( VController::eControllerEventType pEvent )
|
||||
{
|
||||
if ( !getController() )
|
||||
{
|
||||
AssertFatal( false, "VTrack::onControllerEvent() - Invalid Controller." );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enabled?
|
||||
if ( !isEnabled() )
|
||||
{
|
||||
// Continue Processing Events.
|
||||
return true;
|
||||
}
|
||||
|
||||
switch( pEvent )
|
||||
{
|
||||
case VController::k_EventReset :
|
||||
{
|
||||
|
||||
// Reset.
|
||||
onControllerReset( getControllerTime(), isControllerPlayingForward() );
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
// Continue Processing Events.
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::onControllerReset( pTime, pForward );
|
||||
//
|
||||
// Reset the status of the track. The Next Event is allocated here.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTrack::onControllerReset( const S32 &pTime, const bool &pForward )
|
||||
{
|
||||
// Clear Next Event.
|
||||
mNextEvent = NULL;
|
||||
|
||||
for ( ITreeNode *node = mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
VEvent *event = ( VEvent* )node;
|
||||
|
||||
// Reset Event.
|
||||
event->onControllerReset( pTime, pForward );
|
||||
|
||||
if ( ( event->isPlaying() )
|
||||
|| ( pForward && event->getTriggerTime() >= pTime ) )
|
||||
{
|
||||
if ( !mNextEvent )
|
||||
{
|
||||
// Use as Next Event.
|
||||
mNextEvent = event;
|
||||
}
|
||||
}
|
||||
else if ( !pForward && pTime >= event->getTriggerTime() )
|
||||
{
|
||||
VEvent *nextEvent = ( VEvent* )node->mSiblingNextNode;
|
||||
if ( !nextEvent || pTime < nextEvent->getTriggerTime() )
|
||||
{
|
||||
// Use as Next Event.
|
||||
mNextEvent = event;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Reference Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::sort();
|
||||
//
|
||||
// Sort the track's events by the event's trigger time.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTrack::sort( void )
|
||||
{
|
||||
const S32 count = size();
|
||||
for ( S32 j = 0; j < count; j++ )
|
||||
{
|
||||
for ( ITreeNode *node = mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
VEvent *eventA = ( VEvent* )node;
|
||||
VEvent *eventB = ( VEvent* )node->mSiblingNextNode;
|
||||
if ( !eventB )
|
||||
{
|
||||
// No Node.
|
||||
break;
|
||||
}
|
||||
|
||||
// Swap?
|
||||
if ( eventA->getTriggerTime() > eventB->getTriggerTime() )
|
||||
{
|
||||
// Get Outer Siblings.
|
||||
ITreeNode *prevNode = eventA->mSiblingPrevNode;
|
||||
ITreeNode *nextNode = eventB->mSiblingNextNode;
|
||||
|
||||
if ( eventA->mParentNode && eventA->mParentNode->mChildNode == eventA )
|
||||
{
|
||||
// New Child Node.
|
||||
eventA->mParentNode->mChildNode = eventB;
|
||||
}
|
||||
|
||||
//
|
||||
// Move A.
|
||||
eventA->mSiblingPrevNode = eventB;
|
||||
eventA->mSiblingNextNode = nextNode;
|
||||
|
||||
if ( nextNode )
|
||||
{
|
||||
// Update Outer Sibling.
|
||||
nextNode->mSiblingPrevNode = eventA;
|
||||
}
|
||||
|
||||
//
|
||||
// Move B.
|
||||
|
||||
eventB->mSiblingPrevNode = prevNode;
|
||||
eventB->mSiblingNextNode = eventA;
|
||||
|
||||
if ( prevNode )
|
||||
{
|
||||
// Update Outer Sibling.
|
||||
prevNode->mSiblingNextNode = eventB;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::updateNextEvent( pForward );
|
||||
//
|
||||
// Point mNextEvent to the next valid event in the track's sequence.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VTrack::updateNextEvent( void )
|
||||
{
|
||||
if ( !mNextEvent )
|
||||
{
|
||||
// Invalid Event.
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( ( mNextEvent = mNextEvent->getNextEvent() ) != NULL )
|
||||
{
|
||||
if ( mNextEvent->isEnabled() )
|
||||
{
|
||||
// Valid Event.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Invalid Event.
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Property Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::getGroup();
|
||||
//
|
||||
// Returns the Track's parent group.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VGroup *VTrack::getGroup( void )
|
||||
{
|
||||
return dynamic_cast<VGroup*>( mParentNode );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::getNextEvent();
|
||||
//
|
||||
// Returns the Event that the Track is currently observing.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VEvent *VTrack::getNextEvent( void )
|
||||
{
|
||||
return mNextEvent;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::getCurrentEvent();
|
||||
//
|
||||
// Returns the Event that the Track is currently observing and playing. This
|
||||
// will only ever be non-null when the track is observing an Event that has a
|
||||
// non-zero duration and has been triggered.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VEvent *VTrack::getCurrentEvent( void )
|
||||
{
|
||||
if ( mNextEvent && mNextEvent->isPlaying() )
|
||||
{
|
||||
return mNextEvent;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::getPreviousEvent();
|
||||
//
|
||||
// Returns the Event that the Track was last intergrating.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
VEvent *VTrack::getPreviousEvent( void )
|
||||
{
|
||||
if ( mNextEvent )
|
||||
{
|
||||
return mNextEvent->getPreviousEvent();
|
||||
}
|
||||
|
||||
if ( !isControllerPlayingForward() )
|
||||
{
|
||||
return dynamic_cast<VEvent*>( getChild() );
|
||||
}
|
||||
|
||||
return dynamic_cast<VEvent*>( getLastChild() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTrack::calclateInterp( pTime );
|
||||
//
|
||||
// This method returns the interp time between or within events. If the given
|
||||
// time is between two events, the return time is:
|
||||
//
|
||||
// ( pTime - last_event_finish_time )
|
||||
// / ( next_event_start_time - last_event_finish_time )
|
||||
//
|
||||
// If the given time is within an event, the return time is:
|
||||
//
|
||||
// ( pTime - event_start_time ) / ( event_duration )
|
||||
//
|
||||
// The value returned here is between 0.0 and 1.0.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
F32 VTrack::calculateInterp( S32 pTime )
|
||||
{
|
||||
if ( !isControllerPlayingForward() )
|
||||
{
|
||||
return ( 1.f - _calculateInterp( pTime ) );
|
||||
}
|
||||
|
||||
return _calculateInterp( pTime );
|
||||
}
|
||||
|
||||
F32 VTrack::_calculateInterp( S32 pTime )
|
||||
{
|
||||
// Fetch Duration.
|
||||
const S32 sequenceDuration = getControllerDuration();
|
||||
if ( sequenceDuration == 0 || pTime == sequenceDuration )
|
||||
{
|
||||
// Sanity!
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
if ( !mChildNode )
|
||||
{
|
||||
// Quick Interp.
|
||||
return F32( pTime / sequenceDuration );
|
||||
}
|
||||
|
||||
// Last Time.
|
||||
S32 lastTime = 0;
|
||||
|
||||
VEvent *walk = ( VEvent* )mChildNode;
|
||||
while ( walk )
|
||||
{
|
||||
const S32 startTime = walk->getStartTime();
|
||||
const S32 finishTime = walk->getFinishTime();
|
||||
|
||||
if ( pTime < startTime )
|
||||
{
|
||||
return ( F32( pTime - lastTime ) / F32( startTime - lastTime ) );
|
||||
}
|
||||
|
||||
// Update Last Time.
|
||||
lastTime = startTime;
|
||||
|
||||
if ( pTime < finishTime )
|
||||
{
|
||||
return ( F32( pTime - lastTime ) / F32( finishTime - lastTime ) );
|
||||
}
|
||||
|
||||
// Update Last Time.
|
||||
lastTime = finishTime;
|
||||
|
||||
// Fetch Next Node.
|
||||
walk = ( VEvent* )walk->mSiblingNextNode;
|
||||
}
|
||||
|
||||
// Return.
|
||||
return ( F32( pTime - lastTime ) / F32( sequenceDuration - lastTime ) );
|
||||
}
|
||||
123
Engine/source/Verve/Core/VTrack.h
Normal file
123
Engine/source/Verve/Core/VTrack.h
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VTRACK_H_
|
||||
#define _VT_VTRACK_H_
|
||||
|
||||
#ifndef _VT_VCONTROLLER_H_
|
||||
#include "Verve/Core/VController.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_VEVENT_H_
|
||||
#include "Verve/Core/VEvent.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_TORQUE_SCENEOBJECT_H_
|
||||
#include "Verve/Torque/TSceneObject.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class VGroup;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VTrack : public VObject
|
||||
{
|
||||
typedef VObject Parent;
|
||||
|
||||
public:
|
||||
|
||||
// Controller Members.
|
||||
|
||||
VEvent *mNextEvent;
|
||||
|
||||
public:
|
||||
|
||||
VTrack();
|
||||
|
||||
// Tree Methods.
|
||||
|
||||
virtual void onAttach( void );
|
||||
virtual void onDetach( void );
|
||||
|
||||
// Controller Methods.
|
||||
|
||||
virtual void onControllerUpdate( const S32 &pTime, const S32 &pDelta );
|
||||
virtual bool onControllerEvent( VController::eControllerEventType pEvent );
|
||||
|
||||
virtual void onControllerReset( const S32 &pTime, const bool &pForward );
|
||||
|
||||
// Reference Methods.
|
||||
|
||||
void sort( void );
|
||||
bool updateNextEvent( void );
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VTrack );
|
||||
|
||||
public:
|
||||
|
||||
// Property Methods.
|
||||
|
||||
VGroup *getGroup( void );
|
||||
template <class T> inline bool getGroup( T *&pGroup )
|
||||
{
|
||||
// Reference Group.
|
||||
pGroup = dynamic_cast<T*>( getGroup() );
|
||||
// Validate.
|
||||
return ( pGroup != NULL );
|
||||
}
|
||||
|
||||
VEvent *getNextEvent( void );
|
||||
template <class T> inline bool getNextEvent( T *&pEvent )
|
||||
{
|
||||
// Reference Object.
|
||||
pEvent = dynamic_cast<T*>( getNextEvent() );
|
||||
// Validate.
|
||||
return ( pEvent != NULL );
|
||||
}
|
||||
|
||||
VEvent *getCurrentEvent( void );
|
||||
template <class T> inline bool getCurrentEvent( T *&pEvent )
|
||||
{
|
||||
// Reference Object.
|
||||
pEvent = dynamic_cast<T*>( getCurrentEvent() );
|
||||
// Validate.
|
||||
return ( pEvent != NULL );
|
||||
}
|
||||
|
||||
VEvent *getPreviousEvent( void );
|
||||
template <class T> inline bool getPreviousEvent( T *&pEvent )
|
||||
{
|
||||
// Reference Object.
|
||||
pEvent = dynamic_cast<T*>( getPreviousEvent() );
|
||||
// Validate.
|
||||
return ( pEvent != NULL );
|
||||
}
|
||||
|
||||
F32 calculateInterp( S32 pTime );
|
||||
F32 _calculateInterp( S32 pTime );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VTRACK_H_
|
||||
471
Engine/source/Verve/Core/VTreeNode.cpp
Normal file
471
Engine/source/Verve/Core/VTreeNode.cpp
Normal file
|
|
@ -0,0 +1,471 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Core/VTreeNode.h"
|
||||
#include "console/simObject.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VTreeNode::VTreeNode( void )
|
||||
{
|
||||
mParentNode = NULL;
|
||||
mChildNode = NULL;
|
||||
mSiblingPrevNode = NULL;
|
||||
mSiblingNextNode = NULL;
|
||||
}
|
||||
|
||||
VTreeNode::~VTreeNode( void )
|
||||
{
|
||||
// Delete Children.
|
||||
clear();
|
||||
|
||||
// Detach.
|
||||
remove();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Reference Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::clear();
|
||||
//
|
||||
// Delete all child nodes.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::clear( void )
|
||||
{
|
||||
if ( !mChildNode )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while ( mChildNode )
|
||||
{
|
||||
// Fetch Child Node.
|
||||
ITreeNode *node = mChildNode;
|
||||
|
||||
// Clear It.
|
||||
node->clear();
|
||||
|
||||
// Detach It.
|
||||
node->remove();
|
||||
|
||||
// Delete It.
|
||||
SimObject *object = dynamic_cast<SimObject*>( node );
|
||||
if ( object )
|
||||
{
|
||||
object->deleteObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// ITreeNode Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getRoot();
|
||||
//
|
||||
// Returns the root object.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::getRoot( void )
|
||||
{
|
||||
ITreeNode *parent = this;
|
||||
while ( parent->mParentNode )
|
||||
{
|
||||
parent = parent->mParentNode;
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getParent();
|
||||
//
|
||||
// Returns the parent object.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::getParent( void )
|
||||
{
|
||||
return mParentNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getChild();
|
||||
//
|
||||
// Returns the first child object.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::getChild( void )
|
||||
{
|
||||
return mChildNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getChild();
|
||||
//
|
||||
// Returns the first child object.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::getLastChild( void )
|
||||
{
|
||||
// Any Nodes?
|
||||
if ( !mChildNode )
|
||||
{
|
||||
// Null.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Front Node.
|
||||
ITreeNode *lastNode = mChildNode;
|
||||
|
||||
// Fetch Last Node.
|
||||
while ( lastNode->mSiblingNextNode )
|
||||
{
|
||||
lastNode = lastNode->mSiblingNextNode;
|
||||
}
|
||||
|
||||
// Return.
|
||||
return lastNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getPrevSibling();
|
||||
//
|
||||
// Returns the previous object in the linked list.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::getPrevSibling( void )
|
||||
{
|
||||
return mSiblingPrevNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getNextSibling();
|
||||
//
|
||||
// Returns the next object in the linked list.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::getNextSibling( void )
|
||||
{
|
||||
return mSiblingNextNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::size();
|
||||
//
|
||||
// Returns the number of child objects. Only includes top level.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int VTreeNode::size( void )
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
ITreeNode *node = mChildNode;
|
||||
while ( node )
|
||||
{
|
||||
size++;
|
||||
|
||||
node = node->mSiblingNextNode;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::at( pIndex );
|
||||
//
|
||||
// Returns the object at the given index.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
ITreeNode *VTreeNode::at( const int pIndex )
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
ITreeNode *node = mChildNode;
|
||||
while ( node )
|
||||
{
|
||||
if ( index++ == pIndex )
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
node = node->mSiblingNextNode;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::getIndex();
|
||||
//
|
||||
// Returns the index of the object in relation to the sibling nodes.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int VTreeNode::getIndex( void )
|
||||
{
|
||||
if ( !inTree() )
|
||||
{
|
||||
// No Index.
|
||||
return 0;
|
||||
}
|
||||
|
||||
ITreeNode *walk = NULL;
|
||||
if ( mParentNode )
|
||||
{
|
||||
walk = mParentNode->mChildNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
walk = this;
|
||||
while ( walk->mSiblingPrevNode )
|
||||
{
|
||||
// Walk Up.
|
||||
walk = walk->mSiblingPrevNode;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; walk; walk = walk->mSiblingNextNode, i++ )
|
||||
{
|
||||
if ( walk == this )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
AssertFatal( false, "VTreeNode::getIndex() - Node List Broken?" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::addTo( pNode );
|
||||
//
|
||||
// Attach this node to the back of the target node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::addTo( ITreeNode *pNode )
|
||||
{
|
||||
if ( inTree() )
|
||||
{
|
||||
// Already In Tree.
|
||||
return;
|
||||
}
|
||||
|
||||
// Set Parent.
|
||||
mParentNode = pNode;
|
||||
|
||||
if ( !pNode->mChildNode )
|
||||
{
|
||||
// Store Child Node.
|
||||
pNode->mChildNode = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Front Node.
|
||||
ITreeNode *headNode = pNode->mChildNode;
|
||||
|
||||
// Fetch Head Node.
|
||||
while ( headNode->mSiblingNextNode )
|
||||
{
|
||||
headNode = headNode->mSiblingNextNode;
|
||||
}
|
||||
|
||||
// Reference Next Node.
|
||||
headNode->mSiblingNextNode = this;
|
||||
|
||||
// Reference Previous Node.
|
||||
mSiblingPrevNode = headNode;
|
||||
}
|
||||
|
||||
// Callback.
|
||||
onAttach();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::addToFront( pNode );
|
||||
//
|
||||
// Attach this node to the front of the target node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::addToFront( ITreeNode *pNode )
|
||||
{
|
||||
if ( inTree() )
|
||||
{
|
||||
// Already In Tree.
|
||||
return;
|
||||
}
|
||||
|
||||
// Set Parent.
|
||||
mParentNode = pNode;
|
||||
|
||||
if ( !pNode->mChildNode )
|
||||
{
|
||||
// Store Child Node.
|
||||
pNode->mChildNode = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
// First Node.
|
||||
ITreeNode *childNode = pNode->mChildNode;
|
||||
|
||||
// Reference Previous Node.
|
||||
childNode->mSiblingPrevNode = this;
|
||||
|
||||
// Reference Next Node.
|
||||
mSiblingNextNode = childNode;
|
||||
|
||||
// Store Child Node.
|
||||
pNode->mChildNode = this;
|
||||
}
|
||||
|
||||
// Callback.
|
||||
onAttach();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::remove();
|
||||
//
|
||||
// Detach this node from the current parent node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::remove( void )
|
||||
{
|
||||
if ( !inTree() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Callback.
|
||||
onDetach();
|
||||
|
||||
if ( mParentNode && mParentNode->mChildNode == this )
|
||||
{
|
||||
// Update Parent Reference.
|
||||
mParentNode->mChildNode = mSiblingNextNode;
|
||||
}
|
||||
|
||||
if ( mSiblingNextNode )
|
||||
{
|
||||
// Update Previous Node.
|
||||
mSiblingNextNode->mSiblingPrevNode = mSiblingPrevNode;
|
||||
}
|
||||
|
||||
if ( mSiblingPrevNode )
|
||||
{
|
||||
// Update Next Node.
|
||||
mSiblingPrevNode->mSiblingNextNode = mSiblingNextNode;
|
||||
}
|
||||
|
||||
// Remove References.
|
||||
mParentNode = mSiblingPrevNode = mSiblingNextNode = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::moveTo( pNode );
|
||||
//
|
||||
// Detach this node and attach it to the target node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::moveTo( ITreeNode *pNode )
|
||||
{
|
||||
if ( inTree() )
|
||||
{
|
||||
// Remove from Tree.
|
||||
remove();
|
||||
}
|
||||
|
||||
// Add to tree.
|
||||
addTo( pNode );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::onAttach();
|
||||
//
|
||||
// This method will be called when this node, or a parent node, is attached to
|
||||
// a node.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::onAttach( void )
|
||||
{
|
||||
// Notify Children.
|
||||
for ( ITreeNode *node = mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
node->onAttach();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::onDetach();
|
||||
//
|
||||
// This method will be called when this node, or a parent node, is detached.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VTreeNode::onDetach( void )
|
||||
{
|
||||
// Notify Children.
|
||||
for ( ITreeNode *node = mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
node->onDetach();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VTreeNode::inTree();
|
||||
//
|
||||
// Returns true if the node is the a member of a node tree.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VTreeNode::inTree( void )
|
||||
{
|
||||
return !( mParentNode == NULL &&
|
||||
mSiblingPrevNode == NULL &&
|
||||
mSiblingNextNode == NULL );
|
||||
}
|
||||
73
Engine/source/Verve/Core/VTreeNode.h
Normal file
73
Engine/source/Verve/Core/VTreeNode.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VTREENODE_H_
|
||||
#define _VT_VTREENODE_H_
|
||||
|
||||
#ifndef _VT_ITREENODE_H_
|
||||
#include "Verve/Core/ITreeNode.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VTreeNode : public ITreeNode
|
||||
{
|
||||
typedef ITreeNode Parent;
|
||||
|
||||
public:
|
||||
|
||||
VTreeNode( void );
|
||||
~VTreeNode( void );
|
||||
|
||||
// Reference Methods.
|
||||
|
||||
virtual void clear( void );
|
||||
|
||||
// ITreeNode Methods.
|
||||
|
||||
virtual ITreeNode *getRoot( void );
|
||||
virtual ITreeNode *getParent( void );
|
||||
virtual ITreeNode *getChild( void );
|
||||
virtual ITreeNode *getLastChild( void );
|
||||
|
||||
virtual ITreeNode *getPrevSibling( void );
|
||||
virtual ITreeNode *getNextSibling( void );
|
||||
|
||||
virtual ITreeNode *at( const int pIndex );
|
||||
virtual int size( void );
|
||||
|
||||
virtual int getIndex( void );
|
||||
|
||||
virtual void addTo( ITreeNode *pNode );
|
||||
virtual void addToFront( ITreeNode *pNode );
|
||||
virtual void remove( void );
|
||||
virtual void moveTo( ITreeNode *pNode );
|
||||
|
||||
virtual void onAttach( void );
|
||||
virtual void onDetach( void );
|
||||
|
||||
virtual bool inTree( void );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VTREENODE_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue