mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 10:37:41 -04:00
Merge pull request #192 from boq/notify_int
Allow plNotify variable events to carry integers in addition to floats. We can finally merge with the release of Cyan MOULa 912.
This commit is contained in:
@ -1361,12 +1361,19 @@ hsBool plPythonFileMod::MsgReceive(plMessage* msg)
|
|||||||
// depending on the data type create the data
|
// depending on the data type create the data
|
||||||
switch ( eventData->fDataType )
|
switch ( eventData->fDataType )
|
||||||
{
|
{
|
||||||
case proEventData::kNumber:
|
case proEventData::kFloat:
|
||||||
PyList_SetItem(event, 3, PyFloat_FromDouble(eventData->fNumber));
|
PyList_SetItem(event, 3, PyFloat_FromDouble(eventData->fNumber.f));
|
||||||
break;
|
break;
|
||||||
case proEventData::kKey:
|
case proEventData::kKey:
|
||||||
PyList_SetItem(event, 3, pyKey::New(eventData->fKey));
|
PyList_SetItem(event, 3, pyKey::New(eventData->fKey));
|
||||||
break;
|
break;
|
||||||
|
case proEventData::kInt:
|
||||||
|
PyList_SetItem(event, 3, PyInt_FromLong(eventData->fNumber.i));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Py_XINCREF(Py_None);
|
||||||
|
PyList_SetItem(event, 3, Py_None);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// add this event record to the main event list (lists within a list)
|
// add this event record to the main event list (lists within a list)
|
||||||
PyList_Append(levents, event);
|
PyList_Append(levents, event);
|
||||||
|
@ -148,7 +148,17 @@ void pyNotify::AddControlKeyEvent( int32_t key, hsBool down )
|
|||||||
|
|
||||||
void pyNotify::AddVarNumber(const char* name, float number)
|
void pyNotify::AddVarNumber(const char* name, float number)
|
||||||
{
|
{
|
||||||
fBuildMsg.AddVariableEvent(name,number);
|
fBuildMsg.AddVariableEvent(name, number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pyNotify::AddVarNumber(const char* name, int number)
|
||||||
|
{
|
||||||
|
fBuildMsg.AddVariableEvent(name, number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pyNotify::AddVarNull(const char* name)
|
||||||
|
{
|
||||||
|
fBuildMsg.AddVariableEvent(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pyNotify::AddVarKey(const char* name, pyKey* key)
|
void pyNotify::AddVarKey(const char* name, pyKey* key)
|
||||||
|
@ -100,6 +100,8 @@ public:
|
|||||||
virtual void AddPickEvent(hsBool enabled, pyKey* other, pyKey* self, pyPoint3 hitPoint);
|
virtual void AddPickEvent(hsBool enabled, pyKey* other, pyKey* self, pyPoint3 hitPoint);
|
||||||
virtual void AddControlKeyEvent( int32_t key, hsBool down );
|
virtual void AddControlKeyEvent( int32_t key, hsBool down );
|
||||||
virtual void AddVarNumber(const char* name, float number);
|
virtual void AddVarNumber(const char* name, float number);
|
||||||
|
virtual void AddVarNumber(const char* name, int number);
|
||||||
|
virtual void AddVarNull(const char* name);
|
||||||
virtual void AddVarKey(const char* name, pyKey* key);
|
virtual void AddVarKey(const char* name, pyKey* key);
|
||||||
virtual void AddFacingEvent( hsBool enabled, pyKey* other, pyKey* self, float dot);
|
virtual void AddFacingEvent( hsBool enabled, pyKey* other, pyKey* self, float dot);
|
||||||
virtual void AddContainerEvent( hsBool entering, pyKey* container, pyKey* contained);
|
virtual void AddContainerEvent( hsBool entering, pyKey* container, pyKey* contained);
|
||||||
|
@ -194,18 +194,86 @@ PYTHON_METHOD_DEFINITION(ptNotify, addControlKeyEvent, args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PYTHON_METHOD_DEFINITION(ptNotify, addVarNumber, args)
|
PYTHON_METHOD_DEFINITION(ptNotify, addVarNumber, args)
|
||||||
|
{
|
||||||
|
char* name;
|
||||||
|
PyObject* number = NULL;
|
||||||
|
if (!PyArg_ParseTuple(args, "s|O", &name, &number))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "addVarNumber expects a string and optional number");
|
||||||
|
PYTHON_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number == NULL || number == Py_None)
|
||||||
|
self->fThis->AddVarNull(name);
|
||||||
|
else if (PyInt_Check(number))
|
||||||
|
self->fThis->AddVarNumber(name, PyInt_AsLong(number));
|
||||||
|
else if (PyLong_Check(number))
|
||||||
|
{
|
||||||
|
// try as int first
|
||||||
|
long i = PyLong_AsLong(number);
|
||||||
|
if (!PyErr_Occurred())
|
||||||
|
{
|
||||||
|
self->fThis->AddVarNumber(name, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// OverflowError, try float
|
||||||
|
PyErr_Clear();
|
||||||
|
self->fThis->AddVarNumber(name, (float)PyLong_AsDouble(number));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (PyNumber_Check(number))
|
||||||
|
{
|
||||||
|
PyObject* f = PyNumber_Float(number);
|
||||||
|
self->fThis->AddVarNumber(name, (float)PyFloat_AsDouble(f));
|
||||||
|
Py_DECREF(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "addVarNumber expects a string and optional number");
|
||||||
|
PYTHON_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
PYTHON_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PYTHON_METHOD_DEFINITION(ptNotify, addVarFloat, args)
|
||||||
{
|
{
|
||||||
char* name;
|
char* name;
|
||||||
float number;
|
float number;
|
||||||
if (!PyArg_ParseTuple(args, "sf", &name, &number))
|
if (!PyArg_ParseTuple(args, "sf", &name, &number))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError, "addVarNumber expects a string and a float");
|
PyErr_SetString(PyExc_TypeError, "addVarFloat expects a string and a float");
|
||||||
PYTHON_RETURN_ERROR;
|
PYTHON_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
self->fThis->AddVarNumber(name, number);
|
self->fThis->AddVarNumber(name, number);
|
||||||
PYTHON_RETURN_NONE;
|
PYTHON_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PYTHON_METHOD_DEFINITION(ptNotify, addVarInt, args)
|
||||||
|
{
|
||||||
|
char* name;
|
||||||
|
int number;
|
||||||
|
if (!PyArg_ParseTuple(args, "si", &name, &number))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "addVarInt expects a string and a integer");
|
||||||
|
PYTHON_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
self->fThis->AddVarNumber(name, number);
|
||||||
|
PYTHON_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PYTHON_METHOD_DEFINITION(ptNotify, addVarNull, args)
|
||||||
|
{
|
||||||
|
char* name;
|
||||||
|
if (!PyArg_ParseTuple(args, "s", &name))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "addVarNull expects a string");
|
||||||
|
PYTHON_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
self->fThis->AddVarNull(name);
|
||||||
|
PYTHON_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
PYTHON_METHOD_DEFINITION(ptNotify, addVarKey, args)
|
PYTHON_METHOD_DEFINITION(ptNotify, addVarKey, args)
|
||||||
{
|
{
|
||||||
char* name;
|
char* name;
|
||||||
@ -337,6 +405,13 @@ PYTHON_START_METHODS_TABLE(ptNotify)
|
|||||||
PYTHON_METHOD(ptNotify, addPickEvent, "Params: enabledFlag,pickerKey,pickeeKey,hitPoint\nAdd a pick event record to the Notify message"),
|
PYTHON_METHOD(ptNotify, addPickEvent, "Params: enabledFlag,pickerKey,pickeeKey,hitPoint\nAdd a pick event record to the Notify message"),
|
||||||
PYTHON_METHOD(ptNotify, addControlKeyEvent, "Params: keynumber,downFlag\nAdd a keyboard event record to the Notify message"),
|
PYTHON_METHOD(ptNotify, addControlKeyEvent, "Params: keynumber,downFlag\nAdd a keyboard event record to the Notify message"),
|
||||||
PYTHON_METHOD(ptNotify, addVarNumber, "Params: name,number\nAdd a number variable event record to the Notify message\n"
|
PYTHON_METHOD(ptNotify, addVarNumber, "Params: name,number\nAdd a number variable event record to the Notify message\n"
|
||||||
|
"Method will try to pick appropriate variable type\n"
|
||||||
|
"This event record is used to pass a number variable to another python program"),
|
||||||
|
PYTHON_METHOD(ptNotify, addVarFloat, "Params: name,number\nAdd a float variable event record to the Notify message\n"
|
||||||
|
"This event record is used to pass a number variable to another python program"),
|
||||||
|
PYTHON_METHOD(ptNotify, addVarInt, "Params: name,number\nAdd a int variable event record to the Notify message\n"
|
||||||
|
"This event record is used to pass a number variable to another python program"),
|
||||||
|
PYTHON_METHOD(ptNotify, addVarNull, "Params: name,number\nAdd a null (no data) variable event record to the Notify message\n"
|
||||||
"This event record is used to pass a number variable to another python program"),
|
"This event record is used to pass a number variable to another python program"),
|
||||||
PYTHON_METHOD(ptNotify, addVarKey, "Params: name,key\nAdd a ptKey variable event record to the Notify message\n"
|
PYTHON_METHOD(ptNotify, addVarKey, "Params: name,key\nAdd a ptKey variable event record to the Notify message\n"
|
||||||
"This event record is used to pass a ptKey variable to another python program"),
|
"This event record is used to pass a ptKey variable to another python program"),
|
||||||
@ -402,7 +477,9 @@ void pyNotify::AddPlasmaConstantsClasses(PyObject *m)
|
|||||||
PYTHON_ENUM_END(m, PtEventType);
|
PYTHON_ENUM_END(m, PtEventType);
|
||||||
|
|
||||||
PYTHON_ENUM_START(PtNotifyDataType);
|
PYTHON_ENUM_START(PtNotifyDataType);
|
||||||
PYTHON_ENUM_ELEMENT(PtNotifyDataType, kNumber, proEventData::kNumber);
|
PYTHON_ENUM_ELEMENT(PtNotifyDataType, kFloat, proEventData::kFloat);
|
||||||
|
PYTHON_ENUM_ELEMENT(PtNotifyDataType, kInt, proEventData::kInt);
|
||||||
|
PYTHON_ENUM_ELEMENT(PtNotifyDataType, kNull, proEventData::kNull);
|
||||||
PYTHON_ENUM_ELEMENT(PtNotifyDataType, kKey, proEventData::kKey);
|
PYTHON_ENUM_ELEMENT(PtNotifyDataType, kKey, proEventData::kKey);
|
||||||
PYTHON_ENUM_END(m, PtNotifyDataType);
|
PYTHON_ENUM_END(m, PtNotifyDataType);
|
||||||
|
|
||||||
|
@ -174,8 +174,14 @@ void plNotifyMsg::AddEvent( proEventData* ed )
|
|||||||
proVariableEventData *evt = (proVariableEventData *)ed;
|
proVariableEventData *evt = (proVariableEventData *)ed;
|
||||||
switch (evt->fDataType)
|
switch (evt->fDataType)
|
||||||
{
|
{
|
||||||
case proEventData::kNumber:
|
case proEventData::kFloat:
|
||||||
AddVariableEvent(evt->fName, evt->fNumber);
|
AddVariableEvent(evt->fName, evt->fNumber.f);
|
||||||
|
break;
|
||||||
|
case proEventData::kInt:
|
||||||
|
AddVariableEvent(evt->fName, evt->fNumber.i);
|
||||||
|
break;
|
||||||
|
case proEventData::kNull:
|
||||||
|
AddVariableEvent(evt->fName);
|
||||||
break;
|
break;
|
||||||
case proEventData::kKey:
|
case proEventData::kKey:
|
||||||
AddVariableEvent(evt->fName, evt->fKey);
|
AddVariableEvent(evt->fName, evt->fKey);
|
||||||
@ -588,12 +594,44 @@ void plNotifyMsg::AddVariableEvent( const char* name, float number )
|
|||||||
// create the control key event record
|
// create the control key event record
|
||||||
proVariableEventData* pED = new proVariableEventData;
|
proVariableEventData* pED = new proVariableEventData;
|
||||||
pED->fName = hsStrcpy(nil,name);
|
pED->fName = hsStrcpy(nil,name);
|
||||||
// pED->fName = (char*)name;
|
pED->fDataType = proEventData::kFloat;
|
||||||
pED->fDataType = proEventData::kNumber;
|
pED->fNumber.f = number;
|
||||||
pED->fNumber = number;
|
|
||||||
fEvents.Append(pED); // then add it to the list of event records
|
fEvents.Append(pED); // then add it to the list of event records
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Function : AddVariableEvent
|
||||||
|
// PARAMETERS : name - name of the variable
|
||||||
|
// : number - the value of the variable as a number
|
||||||
|
//
|
||||||
|
// PURPOSE : Add a variable event record to this notify message
|
||||||
|
//
|
||||||
|
void plNotifyMsg::AddVariableEvent( const char* name, int number )
|
||||||
|
{
|
||||||
|
// create the control key event record
|
||||||
|
proVariableEventData* pED = new proVariableEventData;
|
||||||
|
pED->fName = hsStrcpy(nil,name);
|
||||||
|
pED->fDataType = proEventData::kInt;
|
||||||
|
pED->fNumber.i = number;
|
||||||
|
fEvents.Append(pED); // then add it to the list of event records
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Function : AddVariableEvent
|
||||||
|
// PARAMETERS : name - name of the variable
|
||||||
|
//
|
||||||
|
// PURPOSE : Add a variable event record to this notify message
|
||||||
|
//
|
||||||
|
void plNotifyMsg::AddVariableEvent( const char* name)
|
||||||
|
{
|
||||||
|
// create the control key event record
|
||||||
|
proVariableEventData* pED = new proVariableEventData;
|
||||||
|
pED->fName = hsStrcpy(nil,name);
|
||||||
|
pED->fDataType = proEventData::kNull;
|
||||||
|
fEvents.Append(pED); // then add it to the list of event records
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@ -1283,11 +1321,41 @@ void proVariableEventData::IDestruct()
|
|||||||
fName = nil;
|
fName = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void proVariableEventData::IReadNumber(hsStream * stream) {
|
||||||
|
switch (fDataType)
|
||||||
|
{
|
||||||
|
case kFloat:
|
||||||
|
fNumber.f = stream->ReadLEScalar();
|
||||||
|
break;
|
||||||
|
case kInt:
|
||||||
|
fNumber.i = stream->ReadLE32();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
stream->ReadLE32(); //ignore
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void proVariableEventData::IWriteNumber(hsStream * stream) {
|
||||||
|
switch (fDataType)
|
||||||
|
{
|
||||||
|
case kFloat:
|
||||||
|
stream->WriteLEScalar(fNumber.f);
|
||||||
|
break;
|
||||||
|
case kInt:
|
||||||
|
stream->WriteLE32(fNumber.i);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
stream->WriteLE32(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void proVariableEventData::IRead(hsStream* stream, hsResMgr* mgr)
|
void proVariableEventData::IRead(hsStream* stream, hsResMgr* mgr)
|
||||||
{
|
{
|
||||||
fName = stream->ReadSafeString();
|
fName = stream->ReadSafeString();
|
||||||
fDataType = stream->ReadLE32();
|
fDataType = stream->ReadLE32();
|
||||||
fNumber = stream->ReadLEScalar();
|
IReadNumber(stream);
|
||||||
fKey = mgr->ReadKey(stream);
|
fKey = mgr->ReadKey(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1295,7 +1363,7 @@ void proVariableEventData::IWrite(hsStream* stream, hsResMgr* mgr)
|
|||||||
{
|
{
|
||||||
stream->WriteSafeString(fName);
|
stream->WriteSafeString(fName);
|
||||||
stream->WriteLE32(fDataType);
|
stream->WriteLE32(fDataType);
|
||||||
stream->WriteLEScalar(fNumber);
|
IWriteNumber(stream);
|
||||||
mgr->WriteKey(stream, fKey);
|
mgr->WriteKey(stream, fKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1317,7 +1385,7 @@ void proVariableEventData::IReadVersion(hsStream* s, hsResMgr* mgr)
|
|||||||
if (contentFlags.IsBitSet(kProVariableDataType))
|
if (contentFlags.IsBitSet(kProVariableDataType))
|
||||||
fDataType = s->ReadLE32();
|
fDataType = s->ReadLE32();
|
||||||
if (contentFlags.IsBitSet(kProVariableNumber))
|
if (contentFlags.IsBitSet(kProVariableNumber))
|
||||||
fNumber = s->ReadLEScalar();
|
IReadNumber(s);
|
||||||
if (contentFlags.IsBitSet(kProVariableKey))
|
if (contentFlags.IsBitSet(kProVariableKey))
|
||||||
fKey = mgr->ReadKey(s);
|
fKey = mgr->ReadKey(s);
|
||||||
}
|
}
|
||||||
@ -1336,7 +1404,7 @@ void proVariableEventData::IWriteVersion(hsStream* s, hsResMgr* mgr)
|
|||||||
// kProVariableDataType
|
// kProVariableDataType
|
||||||
s->WriteLE32(fDataType);
|
s->WriteLE32(fDataType);
|
||||||
// kProVariableNumber
|
// kProVariableNumber
|
||||||
s->WriteLEScalar(fNumber);
|
IWriteNumber(s);
|
||||||
// kProVariableKey
|
// kProVariableKey
|
||||||
mgr->WriteKey(s, fKey);
|
mgr->WriteKey(s, fKey);
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,10 @@ public:
|
|||||||
|
|
||||||
enum dataType
|
enum dataType
|
||||||
{
|
{
|
||||||
kNumber=1,
|
kFloat=1,
|
||||||
kKey,
|
kKey,
|
||||||
|
kInt,
|
||||||
|
kNull,
|
||||||
kNotta
|
kNotta
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -181,9 +183,12 @@ proEventType(Variable)
|
|||||||
int32_t fDataType; // type of data
|
int32_t fDataType; // type of data
|
||||||
|
|
||||||
// Can't be a union, sadly, but it isn't that much of a waste of space...
|
// Can't be a union, sadly, but it isn't that much of a waste of space...
|
||||||
float fNumber; // if its a number
|
|
||||||
plKey fKey; // if its a plKey (pointer to something)
|
plKey fKey; // if its a plKey (pointer to something)
|
||||||
|
|
||||||
|
union {
|
||||||
|
float f;
|
||||||
|
int32_t i;
|
||||||
|
} fNumber;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void IInit();
|
virtual void IInit();
|
||||||
@ -193,6 +198,9 @@ protected:
|
|||||||
|
|
||||||
virtual void IReadVersion(hsStream* s, hsResMgr* mgr);
|
virtual void IReadVersion(hsStream* s, hsResMgr* mgr);
|
||||||
virtual void IWriteVersion(hsStream* s, hsResMgr* mgr);
|
virtual void IWriteVersion(hsStream* s, hsResMgr* mgr);
|
||||||
|
|
||||||
|
virtual void IReadNumber(hsStream * stream);
|
||||||
|
virtual void IWriteNumber(hsStream * stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
proEventType(Facing)
|
proEventType(Facing)
|
||||||
@ -368,7 +376,9 @@ public:
|
|||||||
void AddPickEvent( const plKey &other, const plKey& self, hsBool enabled, hsPoint3 hitPoint );
|
void AddPickEvent( const plKey &other, const plKey& self, hsBool enabled, hsPoint3 hitPoint );
|
||||||
void AddControlKeyEvent( int32_t key, hsBool down );
|
void AddControlKeyEvent( int32_t key, hsBool down );
|
||||||
void AddVariableEvent( const char* name, float number );
|
void AddVariableEvent( const char* name, float number );
|
||||||
void AddVariableEvent( const char *name, const plKey &key);
|
void AddVariableEvent( const char* name, int number );
|
||||||
|
void AddVariableEvent( const char* name );
|
||||||
|
void AddVariableEvent( const char *name, const plKey &key );
|
||||||
void AddFacingEvent( const plKey &other, const plKey &self, float dot, hsBool enabled);
|
void AddFacingEvent( const plKey &other, const plKey &self, float dot, hsBool enabled);
|
||||||
void AddContainerEvent( const plKey &container, const plKey &contained, hsBool entering);
|
void AddContainerEvent( const plKey &container, const plKey &contained, hsBool entering);
|
||||||
void AddActivateEvent( hsBool activate );
|
void AddActivateEvent( hsBool activate );
|
||||||
|
Reference in New Issue
Block a user