Progress for Animation Properties...
All that remains now is to fill in the switch statement and begin working on the sub property functions - all of which will operate under the same principal.
- New getanimationproperty({animation handle}, {property}, { frame (optional)}) is in progress works great. It only accepts an animation pointer, integer animation property, and an optional frame. If frame is omitted, frame defaults to 0. NO sub property support... Instead you will use this to get a handle for the sub property and and access that sub property with its own specific function.
- Notice I said integer for {property}. I have eliminated mapstrings for animation properties entirely. Instead the property enumerator is now part of openbor.h, and all animation property constants are accessible through openborconstant("ANI_PROP_...").
All that remains now is to fill in the switch statement and begin working on the sub property functions - all of which will operate under the same principal.
Code:
HRESULT openbor_getanimationproperty(ScriptVariant **varlist, ScriptVariant **pretvar, int paramCount)
{
#define SELF_NAME "getanimationproperty({animation handle}, {property}, {frame (optional)})"
#define ARG_MINIMUM 2 // Minimum required arguments.
#define ARG_ANIMATION 0 // Animation handle.
#define ARG_PROPERTY 1 // Animation property.
#define ARG_FRAME 2 // Optional animation frame.
int result = S_OK; // Success or error?
s_anim *animation = NULL; // Animation handle.
e_animation_properties property = 0; // Animation property supplied by string argument and enumerated from property list.
int frame = 0; // Optional frame for properties with per frame instances.
// Clear pass by value argument and map strings to animation property list. .
ScriptVariant_Clear(*pretvar);
// Verify incoming arguments. There should at least
// be a pointer for the animation handle and an integer
// animation property.
if(paramCount < ARG_MINIMUM
|| varlist[ARG_ANIMATION]->vt != VT_PTR
|| varlist[ARG_PROPERTY]->vt != VT_INTEGER)
{
printf("You must provide a valid animation handle and property: " SELF_NAME "\n");
result = E_FAIL;
// No point in doing anything else, exit here.
return result;
}
else
{
animation = (s_anim *)varlist[ARG_ANIMATION]->ptrVal;
property = (LONG)varlist[ARG_PROPERTY]->lVal;
}
// Get frame argument if provided.
if(varlist[ARG_FRAME]->vt != VT_EMPTY)
{
if(varlist[ARG_FRAME]->vt == VT_INTEGER)
{
frame = (LONG)varlist[ARG_FRAME]->lVal;
}
else
{
// User sent invalid type for frame argument.
// No reason to shut down. We'll just default to
// frame 0 and send an alert to log.
printf("Optional {frame} argument is invalid. Defaulting to frame 0: " SELF_NAME "\n");
}
}
// Most property values are integers. Set type here for less repetition.
ScriptVariant_ChangeType(*pretvar, VT_INTEGER);
// Which animation property to get?
switch(property)
{
case ANI_PROP_ANIMHITS:
(*pretvar)->lVal = (LONG)animation->animhits;
break;
case ANI_PROP_ANTIGRAV:
(*pretvar)->lVal = (LONG)animation->antigrav;
break;
case ANI_PROP_NUMFRAMES:
(*pretvar)->lVal = (LONG)animation->numframes;
break;
default:
printf("Unsupported animation property: " SELF_NAME "\n");
result = E_FAIL;
break;
}
return result;
#undef SELF_NAME
#undef ARG_MINIMUM
#undef ARG_ANIMATION
#undef ARG_PROPERTY
#undef ARG_FRAME
}