ConsoleObject

Engine/source/console/consoleObject.h

Interface class to the console.

More...

Public User Defined

Get a reference to a field by name.

bool
setField(const char * fieldName, const char * value)

Set the value of a field.

Logging

These functions will try to print out a message along the lines of "ObjectClass - ObjectName(ObjectId) - formatted message"

_getLogMessage(const char * fmt, va_list args)

Overload this in subclasses to change the message formatting.

logMessage(const char * fmt, ... )

Logs with Con::printf.

logWarning(const char * fmt, ... )

Logs with Con::warnf.

logError(const char * fmt, ... )

Logs with Con::errorf.

Field List

Get a list of all the fields. This information cannot be modified.

Get a list of all the fields, set up so we can modify them.

bool &

Get a handle to a boolean telling us if we expanded the dynamic group.

ConsoleObject Implementation

These functions are implemented in every subclass of ConsoleObject by an IMPLEMENT_CONOBJECT or IMPLEMENT_CO_* macro.

getClassId(U32 netClassGroup)

Get our network-layer class id.

Get our compiler and platform independent class name.

Get the abstract class information for this class.

Get the abstract class information for this class's superclass.

Object Creation

create(const char * in_pClassName)
create(const U32 groupId, const U32 typeId, const U32 in_classId)

Fields

addGroup(const char * in_pGroupname, const char * in_pGroupDocs)

Mark the beginning of a group of fields.

endGroup(const char * in_pGroupname)

Mark the end of a group of fields.

addArray(const char * arrayName, S32 count)

Marks the start of a fixed size array of fields.

endArray(const char * arrayName)

Marks the end of an array of fields.

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)

Register a complex field.

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)
addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const char * in_pFieldDocs, U32 flags)

Register a simple field.

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const char * in_pFieldDocs, U32 flags)
addFieldV(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, TypeValidator * v, const char * in_pFieldDocs)

Register a validated field.

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, AbstractClassRep::WriteDataNotify in_writeDataFn, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)

Register a complex protected field.

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)
addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, AbstractClassRep::WriteDataNotify in_writeDataFn, const char * in_pFieldDocs, U32 flags)

Register a simple protected field.

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, const char * in_pFieldDocs, U32 flags)
addDeprecatedField(const char * fieldName)

Add a deprecated field.

bool
removeField(const char * in_pFieldname)

Remove a field.

Object IDs and lookup.

For a subclass hierarchy based on ConsoleObject to become functional for use as a console object type, the hierarchy must implement a naming scheme and indexing function for looking up objects by name.

bool
disableFieldSubstitutions(const char * in_pFieldname)
bool
onlyKeepClearSubstitutions(const char * in_pFieldname)

Public Static Attributes

const bool

Subclasses of ConsoleObjects that are datablocks should redefine this static member variable and set it to true.

Protected Functions

Public Functions

Gets the ClassRep.

Public Static Functions

const char *

Register global constant variables and do other one-time initialization tasks in a subclass of ConsoleObject.

Register dynamic fields in a subclass of ConsoleObject.

const char *
lookupClassName(const U32 in_classTag)

Get the classname from a class tag.

Detailed Description

Interface class to the console.

The Basics

Any object which you want to work with the console system should derive from this, and access functionality through the static interface.

This class is always used with the DECLARE_CONOBJECT and IMPLEMENT_* macros.

// A very basic example object. It will do nothing!
class TorqueObject : public ConsoleObject {
     // Must provide a Parent typedef so the console system knows what we inherit from.
     typedef ConsoleObject Parent;

     // This does a lot of menial declaration for you.
     DECLARE_CONOBJECT(TorqueObject);

     // This is for us to register our fields in.
     static void initPersistFields();

     // A sample field.
     S8 mSample;
}

// And the accordant implementation...
IMPLEMENT_CONOBJECT(TorqueObject);

void TorqueObject::initPersistFields()
{
  // If you want to inherit any fields from the parent (you do), do this:
  Parent::initPersistFields();

  // Pass the field, the type, the offset,                  and a usage string.
  addField("sample", TypeS8, Offset(mSample, TorqueObject), "A test field.");
}

That's all you need to do to get a class registered with the console system. At this point, you can instantiate it via script, tie methods to it using ConsoleMethod, register fields, and so forth. You can also register any global variables related to the class by creating a consoleInit() method.

You will need to use different IMPLEMENT_ macros in different cases; for instance, if you are making a NetObject (for ghosting), a DataBlock, or a NetEvent.

see:

AbstractClassRep for gory implementation details.

Public User Defined

findField(StringTableEntry fieldName)

Get a reference to a field by name.

setField(const char * fieldName, const char * value)

Set the value of a field.

Logging

These functions will try to print out a message along the lines of "ObjectClass - ObjectName(ObjectId) - formatted message"

_getLogMessage(const char * fmt, va_list args)

Overload this in subclasses to change the message formatting.

Parameters:

fmt

A printf style format string.

args

A va_list containing the args passed ot a log function.

note:

It is suggested that you use String::VToString.

Reimplemented by: SimObject

logMessage(const char * fmt, ... )

Logs with Con::printf.

logWarning(const char * fmt, ... )

Logs with Con::warnf.

logError(const char * fmt, ... )

Logs with Con::errorf.

Field List

getFieldList()

Get a list of all the fields. This information cannot be modified.

getModifiableFieldList()

Get a list of all the fields, set up so we can modify them.

note:

This is a bad trick to pull if you aren't very careful, since you can blast field data!

getDynamicGroupExpand()

Get a handle to a boolean telling us if we expanded the dynamic group.

see:

GuiInspector::Inspect()

ConsoleObject Implementation

These functions are implemented in every subclass of ConsoleObject by an IMPLEMENT_CONOBJECT or IMPLEMENT_CO_* macro.

getClassId(U32 netClassGroup)

Get our network-layer class id.

Parameters:

netClassGroup

The net class for which we want our ID.

see:

getClassName()

Get our compiler and platform independent class name.

note:

This name can be used to instantiate another instance using create()

getStaticClassRep()

Get the abstract class information for this class.

getParentStaticClassRep()

Get the abstract class information for this class's superclass.

Object Creation

create(const char * in_pClassName)

create(const U32 groupId, const U32 typeId, const U32 in_classId)

Fields

addGroup(const char * in_pGroupname, const char * in_pGroupDocs)

Mark the beginning of a group of fields.

This is used in the consoleDoc system.

see:

console_autodoc

endGroup(const char * in_pGroupname)

Mark the end of a group of fields.

This is used in the consoleDoc system.

see:

console_autodoc

addArray(const char * arrayName, S32 count)

Marks the start of a fixed size array of fields.

see:

console_autodoc

endArray(const char * arrayName)

Marks the end of an array of fields.

see:

console_autodoc

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)

Register a complex field.

Parameters:

in_pFieldname

Name of the field.

in_fieldType

Type of the field.

see:

ConsoleDynamicTypes

Parameters:
in_fieldOffset

Offset to the field from the start of the class; calculated using the Offset() macro.

in_elementCount

Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.

in_pFieldDocs

Usage string for this field.

see:

console_autodoc

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const char * in_pFieldDocs, U32 flags)

Register a simple field.

Parameters:

in_pFieldname

Name of the field.

in_fieldType

Type of the field.

see:

ConsoleDynamicTypes

Parameters:
in_fieldOffset

Offset to the field from the start of the class; calculated using the Offset() macro.

in_pFieldDocs

Usage string for this field.

see:

console_autodoc

addField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const char * in_pFieldDocs, U32 flags)

addFieldV(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, TypeValidator * v, const char * in_pFieldDocs)

Register a validated field.

A validated field is just like a normal field except that you can't have it be an array, and that you give it a pointer to a TypeValidator subclass, which is then used to validate any value placed in it. Invalid values are ignored and an error is printed to the console.

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, AbstractClassRep::WriteDataNotify in_writeDataFn, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)

Register a complex protected field.

Parameters:

in_pFieldname

Name of the field.

in_fieldType

Type of the field.

see:

ConsoleDynamicTypes

Parameters:
in_fieldOffset

Offset to the field from the start of the class; calculated using the Offset() macro.

in_setDataFn

When this field gets set, it will call the callback provided.

see:

console_protected

Parameters:
in_getDataFn

When this field is accessed for it's data, it will return the value of this function

in_elementCount

Number of elements in this field. Arrays of elements are assumed to be contiguous in memory.

in_pFieldDocs

Usage string for this field.

see:

console_autodoc

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, const U32 in_elementCount, const char * in_pFieldDocs, U32 flags)

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, AbstractClassRep::WriteDataNotify in_writeDataFn, const char * in_pFieldDocs, U32 flags)

Register a simple protected field.

Parameters:

in_pFieldname

Name of the field.

in_fieldType

Type of the field.

see:

ConsoleDynamicTypes

Parameters:
in_fieldOffset

Offset to the field from the start of the class; calculated using the Offset() macro.

in_setDataFn

When this field gets set, it will call the callback provided.

see:

console_protected

Parameters:
in_getDataFn

When this field is accessed for it's data, it will return the value of this function

in_pFieldDocs

Usage string for this field.

see:

console_autodoc

addProtectedField(const char * in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn, const char * in_pFieldDocs, U32 flags)

addDeprecatedField(const char * fieldName)

Add a deprecated field.

A deprecated field will always be undefined, even if you assign a value to it. This is useful when you need to make sure that a field is not being used anymore.

removeField(const char * in_pFieldname)

Remove a field.

Sometimes, you just have to remove a field!

return:

True on success.

Object IDs and lookup.

For a subclass hierarchy based on ConsoleObject to become functional for use as a console object type, the hierarchy must implement a naming scheme and indexing function for looking up objects by name.

__findObject(const char * )

__getObjectId(ConsoleObject * )

disableFieldSubstitutions(const char * in_pFieldname)

onlyKeepClearSubstitutions(const char * in_pFieldname)

Public Static Attributes

const bool __smIsDatablock 

Subclasses of ConsoleObjects that are datablocks should redefine this static member variable and set it to true.

Private Functions

DECLARE_ABSTRACT_CLASS(ConsoleObject , EngineObject )

Protected Functions

ConsoleObject(const ConsoleObject & )

Deprecated:

This is disallowed.

Public Functions

ConsoleObject()

getClassRep()

Gets the ClassRep.

Public Static Functions

__category()

__description()

consoleInit()

Register global constant variables and do other one-time initialization tasks in a subclass of ConsoleObject.

Deprecated:

You should use ConsoleMethod and ConsoleFunction, not this, to register methods or commands.

see:

console

initPersistFields()

Register dynamic fields in a subclass of ConsoleObject.

lookupClassName(const U32 in_classTag)

Get the classname from a class tag.