Browse Source

Merge pull request #423 from Hoikas/agesdl

Fix Age.SetSDL commands
Adam Johnson 11 years ago
parent
commit
f578a42ab1
  1. 69
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  2. 57
      Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp
  3. 25
      Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h
  4. 20
      Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifierGlue.cpp

69
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp

@ -5931,6 +5931,8 @@ PF_CONSOLE_CMD( Mouse, ForceHide, "bool force", "Forces the mouse to be hidden (
PF_CONSOLE_GROUP( Age ) PF_CONSOLE_GROUP( Age )
plPythonSDLModifier* ExternFindAgePySDL();
PF_CONSOLE_CMD(Age, ShowSDL, "", "Prints the age SDL values") PF_CONSOLE_CMD(Age, ShowSDL, "", "Prints the age SDL values")
{ {
plStateDataRecord * rec = new plStateDataRecord; plStateDataRecord * rec = new plStateDataRecord;
@ -6002,72 +6004,23 @@ PF_CONSOLE_CMD( Age, GetTimeOfDay, "string agedefnfile", "Gets the elapsed days
PF_CONSOLE_CMD( Age, SetSDLFloat, "string varName, float value, int index", "Set the value of an age global variable" ) PF_CONSOLE_CMD( Age, SetSDLFloat, "string varName, float value, int index", "Set the value of an age global variable" )
{ {
int index = (int)params[2]; plPythonSDLModifier* sdlMod = ExternFindAgePySDL();
if (sdlMod)
extern const plPythonSDLModifier *ExternFindAgePySDL(); sdlMod->SetItem((const char*)params[0], (int)params[2], (float)params[1]);
const plPythonSDLModifier *sdlMod = ExternFindAgePySDL();
if (!sdlMod)
return;
plSimpleStateVariable *var = sdlMod->GetStateCache()->FindVar((const char *)params[0]);
if (!var)
return;
float v;
var->Get(&v, index);
var->Set((float)params[1], index);
// set the variable in the pythonSDL also
((plPythonSDLModifier*)sdlMod)->SetItemFromSDLVar(var);
// set it back to original so that its different
plSynchedObject* p = plSynchedObject::ConvertNoRef(((plSDLModifier*)sdlMod)->GetStateOwnerKey()->GetObjectPtr());
if (p)
p->DirtySynchState(sdlMod->GetSDLName(),plSynchedObject::kSendImmediately|plSynchedObject::kSkipLocalOwnershipCheck|plSynchedObject::kForceFullSend);
} }
PF_CONSOLE_CMD( Age, SetSDLInt, "string varName, int value, int index", "Set the value of an age global variable" ) PF_CONSOLE_CMD( Age, SetSDLInt, "string varName, int value, int index", "Set the value of an age global variable" )
{ {
int index = (int)params[2]; plPythonSDLModifier* sdlMod = ExternFindAgePySDL();
if (sdlMod)
extern const plPythonSDLModifier *ExternFindAgePySDL(); sdlMod->SetItem((const char*)params[0], (int)params[2], (int)params[1]);
const plPythonSDLModifier *sdlMod = ExternFindAgePySDL();
if (!sdlMod)
return;
plSimpleStateVariable *var = sdlMod->GetStateCache()->FindVar((const char *)params[0]);
if (!var)
return;
int v;
var->Get(&v, index);
var->Set((int)params[1], index);
// set the variable in the pythonSDL also
((plPythonSDLModifier*)sdlMod)->SetItemFromSDLVar(var);
plSynchedObject* p = plSynchedObject::ConvertNoRef(((plSDLModifier*)sdlMod)->GetStateOwnerKey()->GetObjectPtr());
if (p)
p->DirtySynchState(sdlMod->GetSDLName(),plSynchedObject::kSendImmediately|plSynchedObject::kSkipLocalOwnershipCheck|plSynchedObject::kForceFullSend);
} }
PF_CONSOLE_CMD( Age, SetSDLBool, "string varName, bool value, int index", "Set the value of an age global variable" ) PF_CONSOLE_CMD( Age, SetSDLBool, "string varName, bool value, int index", "Set the value of an age global variable" )
{ {
int index = (int)params[2]; plPythonSDLModifier* sdlMod = ExternFindAgePySDL();
if (sdlMod)
extern const plPythonSDLModifier *ExternFindAgePySDL(); sdlMod->SetItem((const char*)params[0], (int)params[2], (bool)params[1]);
const plPythonSDLModifier *sdlMod = ExternFindAgePySDL();
if (!sdlMod)
return;
plSimpleStateVariable *var = sdlMod->GetStateCache()->FindVar((const char*)params[0]);
if (!var)
return;
bool v;
var->Get(&v, index);
var->Set((bool)params[1], index);
// set the variable in the pythonSDL also
((plPythonSDLModifier*)sdlMod)->SetItemFromSDLVar(var);
plSynchedObject* p = plSynchedObject::ConvertNoRef(((plSDLModifier*)sdlMod)->GetStateOwnerKey()->GetObjectPtr());
if (p)
p->DirtySynchState(sdlMod->GetSDLName(),plSynchedObject::kSendImmediately|plSynchedObject::kSkipLocalOwnershipCheck|plSynchedObject::kForceFullSend);
} }
#endif // LIMIT_CONSOLE_COMMANDS #endif // LIMIT_CONSOLE_COMMANDS

57
Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.cpp

@ -166,18 +166,23 @@ void plPythonSDLModifier::SetItem(const plString& key, PyObject* value)
IDirtySynchState(key); IDirtySynchState(key);
} }
void plPythonSDLModifier::SetItemFromSDLVar(plSimpleStateVariable* var) template<>
void plPythonSDLModifier::SetItem(const plString& key, int index, bool value)
{ {
plString name = var->GetName(); SetItemIdx(key, index, PyBool_FromLong(value), true);
}
// Get the SDL value in Python format
PyObject* pyVar = ISDLVarToPython(var);
ISetItem(name, pyVar); template<>
Py_XDECREF(pyVar); void plPythonSDLModifier::SetItem(const plString& key, int index, float value)
// let the sender do the dirty sync state stuff {
SetItemIdx(key, index, PyFloat_FromDouble(value), true);
} }
template<>
void plPythonSDLModifier::SetItem(const plString& key, int index, int value)
{
SetItemIdx(key, index, PyLong_FromLong(value), true);
}
void plPythonSDLModifier::SetDefault(const plString& key, PyObject* value) void plPythonSDLModifier::SetDefault(const plString& key, PyObject* value)
{ {
@ -578,12 +583,12 @@ const plSDLModifier *ExternFindAgeSDL()
return plPythonSDLModifier::FindAgeSDL(); return plPythonSDLModifier::FindAgeSDL();
} }
const plPythonSDLModifier *ExternFindAgePySDL() plPythonSDLModifier* ExternFindAgePySDL()
{ {
return plPythonSDLModifier::FindAgeSDL(); return plPythonSDLModifier::FindAgeSDL();
} }
const plPythonSDLModifier* plPythonSDLModifier::FindAgeSDL() plPythonSDLModifier* plPythonSDLModifier::FindAgeSDL()
{ {
const char* ageName = cyMisc::GetAgeName(); const char* ageName = cyMisc::GetAgeName();
@ -694,48 +699,48 @@ PyObject* pySDLModifier::GetAgeSDL()
} }
void pySDLModifier::SetDefault(pySDLModifier& self, std::string key, PyObject* value) void pySDLModifier::SetDefault(pySDLModifier& self, const plString& key, PyObject* value)
{ {
self.fRecord->SetDefault(key.c_str(), value); self.fRecord->SetDefault(key, value);
} }
void pySDLModifier::SendToClients(pySDLModifier& self, std::string key) void pySDLModifier::SendToClients(pySDLModifier& self, const plString& key)
{ {
self.fRecord->SendToClients(key.c_str()); self.fRecord->SendToClients(key);
} }
void pySDLModifier::SetNotify(pySDLModifier& self, pyKey& selfkey, std::string key, float tolerance) void pySDLModifier::SetNotify(pySDLModifier& self, pyKey& selfkey, const plString& key, float tolerance)
{ {
self.fRecord->SetNotify(selfkey, key.c_str(), tolerance); self.fRecord->SetNotify(selfkey, key, tolerance);
} }
PyObject* pySDLModifier::GetItem(pySDLModifier& self, std::string key) PyObject* pySDLModifier::GetItem(pySDLModifier& self, const plString& key)
{ {
return self.fRecord->GetItem(key.c_str()); return self.fRecord->GetItem(key);
} }
void pySDLModifier::SetItem(pySDLModifier& self, std::string key, PyObject* value) void pySDLModifier::SetItem(pySDLModifier& self, const plString& key, PyObject* value)
{ {
self.fRecord->SetItem(key.c_str(), value); self.fRecord->SetItem(key, value);
} }
void pySDLModifier::SetItemIdx(pySDLModifier& self, std::string key, int idx, PyObject* value) void pySDLModifier::SetItemIdx(pySDLModifier& self, const plString& key, int idx, PyObject* value)
{ {
self.fRecord->SetItemIdx(key.c_str(), idx, value); self.fRecord->SetItemIdx(key, idx, value);
} }
void pySDLModifier::SetItemIdxImmediate(pySDLModifier& self, std::string key, int idx, PyObject* value) void pySDLModifier::SetItemIdxImmediate(pySDLModifier& self, const plString& key, int idx, PyObject* value)
{ {
self.fRecord->SetItemIdx(key.c_str(), idx, value, true); self.fRecord->SetItemIdx(key, idx, value, true);
} }
void pySDLModifier::SetFlags(pySDLModifier& self, const char* name, bool sendImmediate, bool skipOwnershipCheck) void pySDLModifier::SetFlags(pySDLModifier& self, const plString& name, bool sendImmediate, bool skipOwnershipCheck)
{ {
self.fRecord->SetFlags(name,sendImmediate,skipOwnershipCheck); self.fRecord->SetFlags(name,sendImmediate,skipOwnershipCheck);
} }
void pySDLModifier::SetTagString(pySDLModifier& self, const char* name, const char* tag) void pySDLModifier::SetTagString(pySDLModifier& self, const plString& name, const plString& tag)
{ {
self.fRecord->SetTagString(name,tag); self.fRecord->SetTagString(name,tag);
} }

25
Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h

@ -99,11 +99,10 @@ public:
GETINTERFACE_ANY(plPythonSDLModifier, plSDLModifier); GETINTERFACE_ANY(plPythonSDLModifier, plSDLModifier);
virtual const char* GetSDLName() const; virtual const char* GetSDLName() const;
virtual void SetItemFromSDLVar(plSimpleStateVariable* var);
static bool HasSDL(const plString& pythonFile); static bool HasSDL(const plString& pythonFile);
// find the Age global SDL guy... if there is one // find the Age global SDL guy... if there is one
static const plPythonSDLModifier* FindAgeSDL(); static plPythonSDLModifier* FindAgeSDL();
static plKey FindAgeSDLTarget(); static plKey FindAgeSDLTarget();
void SetDefault(const plString& key, PyObject* value); void SetDefault(const plString& key, PyObject* value);
@ -111,7 +110,11 @@ public:
void SetNotify(pyKey& selfkey, const plString& key, float tolerance); void SetNotify(pyKey& selfkey, const plString& key, float tolerance);
PyObject* GetItem(const plString& key); PyObject* GetItem(const plString& key);
template<typename T>
void SetItem(const plString& key, int index, T value);
void SetItem(const plString& key, PyObject* value); void SetItem(const plString& key, PyObject* value);
void SetItemIdx(const plString& key, int idx, PyObject* value, bool sendImmediate = false); void SetItemIdx(const plString& key, int idx, PyObject* value, bool sendImmediate = false);
void SetFlags(const plString& name, bool sendImmediate, bool skipOwnershipCheck); void SetFlags(const plString& name, bool sendImmediate, bool skipOwnershipCheck);
void SetTagString(const plString& name, const plString& tag); void SetTagString(const plString& name, const plString& tag);
@ -139,16 +142,16 @@ public:
// global function to get the GrandMaster Age SDL object // global function to get the GrandMaster Age SDL object
static PyObject* GetAgeSDL(); static PyObject* GetAgeSDL();
static void SetDefault(pySDLModifier& self, std::string key, PyObject* value); static void SetDefault(pySDLModifier& self, const plString& key, PyObject* value);
static void SendToClients(pySDLModifier& self, std::string key); static void SendToClients(pySDLModifier& self, const plString& key);
static void SetNotify(pySDLModifier& self, pyKey& selfkey, std::string key, float tolerance); static void SetNotify(pySDLModifier& self, pyKey& selfkey, const plString& key, float tolerance);
static PyObject* GetItem(pySDLModifier& self, std::string key); static PyObject* GetItem(pySDLModifier& self, const plString& key);
static void SetItem(pySDLModifier& self, std::string key, PyObject* value); static void SetItem(pySDLModifier& self, const plString& key, PyObject* value);
static void SetItemIdx(pySDLModifier& self, std::string key, int idx, PyObject* value); static void SetItemIdx(pySDLModifier& self, const plString& key, int idx, PyObject* value);
static void SetItemIdxImmediate(pySDLModifier& self, std::string key, int idx, PyObject* value); static void SetItemIdxImmediate(pySDLModifier& self, const plString& key, int idx, PyObject* value);
static void SetFlags(pySDLModifier& self, const char* name, bool sendImmediate, bool skipOwnershipCheck); static void SetFlags(pySDLModifier& self, const plString& name, bool sendImmediate, bool skipOwnershipCheck);
static void SetTagString(pySDLModifier& self, const char* name, const char* tag); static void SetTagString(pySDLModifier& self, const plString& name, const plString& tag);
}; };

20
Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifierGlue.cpp

@ -76,7 +76,7 @@ PYTHON_METHOD_DEFINITION(ptSDL, setIndexNow, args)
char* key; char* key;
int idx; int idx;
PyObject* value = NULL; PyObject* value = NULL;
if (!PyArg_ParseTuple(args, "siO", &key, &idx, &value)) if (!PyArg_ParseTuple(args, "etiO", "utf8", &key, &idx, &value))
{ {
PyErr_SetString(PyExc_TypeError, "setIndexNow expects a string, int, and an object"); PyErr_SetString(PyExc_TypeError, "setIndexNow expects a string, int, and an object");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -89,7 +89,7 @@ PYTHON_METHOD_DEFINITION(ptSDL, setDefault, args)
{ {
char* key; char* key;
PyObject* value = NULL; PyObject* value = NULL;
if (!PyArg_ParseTuple(args, "sO", &key, &value)) if (!PyArg_ParseTuple(args, "etO", "utf8", &key, &value))
{ {
PyErr_SetString(PyExc_TypeError, "setDefault expects a string and a tuple"); PyErr_SetString(PyExc_TypeError, "setDefault expects a string and a tuple");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -106,7 +106,7 @@ PYTHON_METHOD_DEFINITION(ptSDL, setDefault, args)
PYTHON_METHOD_DEFINITION(ptSDL, sendToClients, args) PYTHON_METHOD_DEFINITION(ptSDL, sendToClients, args)
{ {
char* key; char* key;
if (!PyArg_ParseTuple(args, "s", &key)) if (!PyArg_ParseTuple(args, "et", "utf8", &key))
{ {
PyErr_SetString(PyExc_TypeError, "sendToClients expects a string"); PyErr_SetString(PyExc_TypeError, "sendToClients expects a string");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -120,7 +120,7 @@ PYTHON_METHOD_DEFINITION(ptSDL, setNotify, args)
PyObject* selfKeyObj; PyObject* selfKeyObj;
char* key; char* key;
float tolerance; float tolerance;
if (!PyArg_ParseTuple(args, "Osf", &selfKeyObj, &key, &tolerance)) if (!PyArg_ParseTuple(args, "Oetf", &selfKeyObj, "utf8", &key, &tolerance))
{ {
PyErr_SetString(PyExc_TypeError, "setNotify expects a ptKey, string, and float"); PyErr_SetString(PyExc_TypeError, "setNotify expects a ptKey, string, and float");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -139,7 +139,7 @@ PYTHON_METHOD_DEFINITION(ptSDL, setFlags, args)
{ {
char* key; char* key;
char sendImmediate, skipOwnershipCheck; char sendImmediate, skipOwnershipCheck;
if (!PyArg_ParseTuple(args, "sbb", &key, &sendImmediate, &skipOwnershipCheck)) if (!PyArg_ParseTuple(args, "etbb", "utf8", &key, &sendImmediate, &skipOwnershipCheck))
{ {
PyErr_SetString(PyExc_TypeError, "setFlags expects a string and two booleans"); PyErr_SetString(PyExc_TypeError, "setFlags expects a string and two booleans");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -152,7 +152,7 @@ PYTHON_METHOD_DEFINITION(ptSDL, setTagString, args)
{ {
char* key; char* key;
char* tag; char* tag;
if (!PyArg_ParseTuple(args, "ss", &key, &tag)) if (!PyArg_ParseTuple(args, "etet", "utf8", &key, "utf8", &tag))
{ {
PyErr_SetString(PyExc_TypeError, "setTagString expects two strings"); PyErr_SetString(PyExc_TypeError, "setTagString expects two strings");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
@ -179,12 +179,12 @@ PYTHON_END_METHODS_TABLE;
PyObject* ptSDL_subscript(ptSDL* self, PyObject* key) PyObject* ptSDL_subscript(ptSDL* self, PyObject* key)
{ {
if (!PyString_Check(key)) if (!PyString_CheckEx(key))
{ {
PyErr_SetString(PyExc_TypeError, "SDL indexes must be strings"); PyErr_SetString(PyExc_TypeError, "SDL indexes must be strings");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
char *keyStr = PyString_AsString(key); plString keyStr = PyString_AsStringEx(key);
return pySDLModifier::GetItem(*(self->fThis), keyStr); return pySDLModifier::GetItem(*(self->fThis), keyStr);
} }
@ -195,7 +195,7 @@ int ptSDL_ass_subscript(ptSDL* self, PyObject* key, PyObject* value)
PyErr_SetString(PyExc_RuntimeError, "Cannot remove sdl records"); PyErr_SetString(PyExc_RuntimeError, "Cannot remove sdl records");
return -1; // error return return -1; // error return
} }
if (!PyString_Check(key)) if (!PyString_CheckEx(key))
{ {
PyErr_SetString(PyExc_TypeError, "SDL indexes must be strings"); PyErr_SetString(PyExc_TypeError, "SDL indexes must be strings");
return -1; // error return return -1; // error return
@ -205,7 +205,7 @@ int ptSDL_ass_subscript(ptSDL* self, PyObject* key, PyObject* value)
PyErr_SetString(PyExc_TypeError, "SDL values must be tuples"); PyErr_SetString(PyExc_TypeError, "SDL values must be tuples");
return -1; // error return return -1; // error return
} }
char* keyStr = PyString_AsString(key); plString keyStr = PyString_AsStringEx(key);
pySDLModifier::SetItem(*(self->fThis), keyStr, value); pySDLModifier::SetItem(*(self->fThis), keyStr, value);
return 0; // success return return 0; // success return
} }

Loading…
Cancel
Save