Skip to content

Commit

Permalink
UPBGE: Replace py_repr override by GetName and GetText.
Browse files Browse the repository at this point in the history
Dirty override of py_repr are removed in favour of GetName and
GetText functions herited from CValue which are handled in a
unique py_repr correclty.
  • Loading branch information
panzergame committed Aug 20, 2017
1 parent 80b3eb8 commit 54424e1
Show file tree
Hide file tree
Showing 39 changed files with 103 additions and 138 deletions.
5 changes: 0 additions & 5 deletions source/gameengine/Converter/BL_ArmatureChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ PyTypeObject BL_ArmatureChannel::Type = {
py_base_new
};

PyObject *BL_ArmatureChannel::py_repr(void)
{
return PyUnicode_FromString(m_posechannel->name);
}

PyObject *BL_ArmatureChannel::GetProxy()
{
return GetProxyPlus_Ext(this, &Type, m_posechannel);
Expand Down
2 changes: 0 additions & 2 deletions source/gameengine/Converter/BL_ArmatureChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class BL_ArmatureChannel : public CValue

#ifdef WITH_PYTHON
// Python access
virtual PyObject *py_repr(void);

static PyObject *py_attr_getattr(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static int py_attr_setattr(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject *py_attr_get_joint_rotation(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
Expand Down
5 changes: 0 additions & 5 deletions source/gameengine/Converter/BL_ArmatureConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ PyTypeObject BL_ArmatureConstraint::Type = {
py_base_new
};

PyObject *BL_ArmatureConstraint::py_repr(void)
{
return PyUnicode_FromStdString(m_name);
}

#endif // WITH_PYTHON

BL_ArmatureConstraint::BL_ArmatureConstraint(
Expand Down
2 changes: 0 additions & 2 deletions source/gameengine/Converter/BL_ArmatureConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ class BL_ArmatureConstraint : public CValue
#ifdef WITH_PYTHON

// Python access
virtual PyObject *py_repr(void);

static PyObject *py_attr_getattr(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static int py_attr_setattr(PyObjectPlus *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
#endif /* WITH_PYTHON */
Expand Down
11 changes: 1 addition & 10 deletions source/gameengine/Expressions/EXP_BaseListValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CBaseListValue : public CPropValue

virtual int GetValueType();
virtual CValue *GetReplica() = 0;
virtual const std::string GetText();
virtual std::string GetText();

void SetReleaseOnDestruct(bool bReleaseContents);

Expand All @@ -59,15 +59,6 @@ class CBaseListValue : public CPropValue
int GetCount() const;

#ifdef WITH_PYTHON
virtual PyObject *py_repr()
{
PyObject *py_proxy = this->GetProxy();
PyObject *py_list = PySequence_List(py_proxy);
PyObject *py_string = PyObject_Repr(py_list);
Py_DECREF(py_list);
Py_DECREF(py_proxy);
return py_string;
}

KX_PYMETHOD_O(CBaseListValue, append);
KX_PYMETHOD_NOARGS(CBaseListValue, reverse);
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_BoolValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CBoolValue : public CPropValue
CBoolValue(bool inBool);
CBoolValue(bool innie, const std::string& name);

virtual const std::string GetText();
virtual std::string GetText();
virtual double GetNumber();
virtual int GetValueType();
bool GetBool();
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_EmptyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CEmptyValue : public CPropValue
CEmptyValue();
virtual ~CEmptyValue();

virtual const std::string GetText();
virtual std::string GetText();
virtual double GetNumber();
virtual int GetValueType();
virtual CValue *Calc(VALUE_OPERATOR op, CValue *val);
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_ErrorValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CErrorValue : public CPropValue
CErrorValue(const std::string& errmsg);
virtual ~CErrorValue();

virtual const std::string GetText();
virtual std::string GetText();
virtual int GetValueType();
virtual CValue *Calc(VALUE_OPERATOR op, CValue *val);
virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_FloatValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CFloatValue : public CPropValue
CFloatValue(float fl);
CFloatValue(float fl, const std::string& name);

virtual const std::string GetText();
virtual std::string GetText();

virtual double GetNumber();
virtual int GetValueType();
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_IntValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CIntValue : public CPropValue
CIntValue(cInt innie, const std::string& name);
virtual ~CIntValue();

virtual const std::string GetText();
virtual std::string GetText();
virtual double GetNumber();
virtual int GetValueType();

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_ListWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class CListWrapper : public CValue

/// \section CValue Inherited Functions.
virtual std::string GetName();
virtual std::string GetText();
virtual int GetValueType();
virtual PyObject *py_repr();

// Python list operators.
static PySequenceMethods py_as_sequence;
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_StringValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CStringValue : public CPropValue

/// CValue implementation
virtual bool IsEqual(const std::string & other);
virtual const std::string GetText();
virtual std::string GetText();
virtual double GetNumber();
virtual int GetValueType();

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/EXP_Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CValue : public PyObjectPlus, public CM_RefCount<CValue>

virtual CValue *FindIdentifier(const std::string& identifiername);

virtual const std::string GetText();
virtual std::string GetText();
virtual double GetNumber();
/// Get Prop value type.
virtual int GetValueType();
Expand Down
6 changes: 3 additions & 3 deletions source/gameengine/Expressions/intern/BaseListValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@ bool CBaseListValue::CheckEqual(CValue *first, CValue *second)
if (eqval == NULL) {
return false;
}
const std::string& text = eqval->GetText();
std::string text = eqval->GetText();
if (text == CBoolValue::sTrueString) {
result = true;
}
eqval->Release();
return result;
}

const std::string CBaseListValue::GetText()
std::string CBaseListValue::GetText()
{
std::string strListRep = "[";
std::string commastr = "";

for (CValue *item : m_pValueArray) {
strListRep += commastr;
strListRep += item->GetText();
commastr = ",";
commastr = ", ";
}
strListRep += "]";

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/BoolValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int CBoolValue::GetValueType()
return VALUE_BOOL_TYPE;
}

const std::string CBoolValue::GetText()
std::string CBoolValue::GetText()
{
return m_bool ? sTrueString : sFalseString;
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/EmptyValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int CEmptyValue::GetValueType()
return VALUE_EMPTY_TYPE;
}

const std::string CEmptyValue::GetText()
std::string CEmptyValue::GetText()
{
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/ErrorValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int CErrorValue::GetValueType()
return VALUE_ERROR_TYPE;
}

const std::string CErrorValue::GetText()
std::string CErrorValue::GetText()
{
return m_strErrorText;
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/FloatValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void CFloatValue::SetValue(CValue *newval)
m_float = (float)newval->GetNumber();
}

const std::string CFloatValue::GetText()
std::string CFloatValue::GetText()
{
return std::to_string(m_float);
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/IntValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int CIntValue::GetValueType()
return VALUE_INT_TYPE;
}

const std::string CIntValue::GetText()
std::string CIntValue::GetText()
{
return (boost::format("%lld") % m_int).str();
}
Expand Down
28 changes: 13 additions & 15 deletions source/gameengine/Expressions/intern/ListWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,25 @@ std::string CListWrapper::GetName()
return "ListWrapper";
}

int CListWrapper::GetValueType()
std::string CListWrapper::GetText()
{
return -1;
}
std::string strListRep = "[";
std::string commastr = "";

// We convert all elements to python objects to make a proper repr string.
PyObject *CListWrapper::py_repr()
{
if (!CheckValid()) {
PyErr_SetString(PyExc_SystemError, "CListWrapper : repr, " BGE_PROXY_ERROR_MSG);
return nullptr;
for (unsigned int i = 0, size = GetSize(); i < size; ++i) {
strListRep += commastr;
strListRep += _PyUnicode_AsString(PyObject_Repr(GetItem(i)));
commastr = ", ";
}
strListRep += "]";

PyObject *py_proxy = GetProxy();
PyObject *py_list = PySequence_List(py_proxy);
PyObject *py_string = PyObject_Repr(py_list);
Py_DECREF(py_list);
Py_DECREF(py_proxy);
return py_string;
return strListRep;
}

int CListWrapper::GetValueType()
{
return -1;
}

Py_ssize_t CListWrapper::py_len(PyObject *self)
{
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/StringValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int CStringValue::GetValueType()
return VALUE_STRING_TYPE;
}

const std::string CStringValue::GetText()
std::string CStringValue::GetText()
{
return m_strString;
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Expressions/intern/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void CValue::SetValue(CValue *newval)
BLI_assert(false);
}

const std::string CValue::GetText()
std::string CValue::GetText()
{
return GetName();
}
Expand Down
9 changes: 0 additions & 9 deletions source/gameengine/GameLogic/SCA_ILogicBrick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ SCA_ILogicBrick::SCA_ILogicBrick(SCA_IObject* gameobj)
m_bActive(false),
m_eventval(0)
{
m_text = "KX_LogicBrick";
}


Expand Down Expand Up @@ -81,14 +80,6 @@ void SCA_ILogicBrick::Relink(std::map<SCA_IObject *, SCA_IObject *>& obj_map)
// nothing to do
}

const std::string SCA_ILogicBrick::GetText()
{
if (m_name.size())
return m_name;

return m_text;
}

std::string SCA_ILogicBrick::GetName()
{
return m_name;
Expand Down
2 changes: 0 additions & 2 deletions source/gameengine/GameLogic/SCA_ILogicBrick.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class SCA_ILogicBrick : public CValue, public SG_QList

bool m_bActive;
CValue* m_eventval;
std::string m_text;
std::string m_name;
//unsigned long m_drawcolor;
void RemoveEvent();
Expand All @@ -69,7 +68,6 @@ class SCA_ILogicBrick : public CValue, public SG_QList
virtual void Relink(std::map<SCA_IObject *, SCA_IObject *>& obj_map);
virtual void Delete() { Release(); }

virtual const std::string GetText();
virtual std::string GetName();
virtual void SetName(const std::string& name);

Expand Down
5 changes: 5 additions & 0 deletions source/gameengine/GameLogic/SCA_InputEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ SCA_InputEvent::SCA_InputEvent(int type)
m_values.push_back(0);
}

std::string SCA_InputEvent::GetName()
{
return "SCA_InputEvent";
}

void SCA_InputEvent::Clear()
{
SCA_EnumInputs status = m_status[m_status.size() - 1];
Expand Down
11 changes: 4 additions & 7 deletions source/gameengine/GameLogic/SCA_InputEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#ifndef __SCA_INPUTEVENT_H__
#define __SCA_INPUTEVENT_H__

#include "EXP_PyObjectPlus.h"
#include "EXP_Value.h"

#include <vector>

class SCA_InputEvent : public PyObjectPlus
class SCA_InputEvent : public CValue
{
Py_Header
public:
Expand All @@ -45,6 +45,8 @@ Py_Header
SCA_InputEvent();
SCA_InputEvent(int type);

virtual std::string GetName();

/// Clear status, values and queue but keep status and value from before.
void Clear();

Expand All @@ -66,11 +68,6 @@ Py_Header
int m_type;

#ifdef WITH_PYTHON
virtual PyObject *py_repr()
{
return PyUnicode_FromString("SCA_InputEvent");
}

static int get_status_size_cb(void *self_v);
static PyObject *get_status_item_cb(void *self_v, int index);
static int get_queue_size_cb(void *self_v);
Expand Down
13 changes: 6 additions & 7 deletions source/gameengine/GameLogic/SCA_PythonJoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
/* ------------------------------------------------------------------------- */

SCA_PythonJoystick::SCA_PythonJoystick(DEV_Joystick* joystick, int joyindex)
: PyObjectPlus(),
m_joystick(joystick),
:m_joystick(joystick),
m_joyindex(joyindex)
{
#ifdef WITH_PYTHON
Expand All @@ -53,16 +52,16 @@ SCA_PythonJoystick::~SCA_PythonJoystick()
#endif
}

std::string SCA_PythonJoystick::GetName()
{
return m_joystick->GetName();
}

#ifdef WITH_PYTHON

/* ------------------------------------------------------------------------- */
/* Python functions */
/* ------------------------------------------------------------------------- */
PyObject* SCA_PythonJoystick::py_repr(void)
{
return PyUnicode_FromStdString(m_joystick->GetName());
}


/* Integration hooks ------------------------------------------------------- */
PyTypeObject SCA_PythonJoystick::Type = {
Expand Down
Loading

0 comments on commit 54424e1

Please sign in to comment.