~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/gameengine/Expressions/Value.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 */
20
20
#include "Value.h"
 
21
#include "BoolValue.h"
21
22
#include "FloatValue.h"
22
23
#include "IntValue.h"
23
24
#include "VectorValue.h"
134
135
}
135
136
 
136
137
 
137
 
 
138
 
 
 
138
/* UNUSED */
 
139
#if 0
139
140
#define VALUE_SUB(val1, val2) (val1)->Calc(VALUE_SUB_OPERATOR, val2)
140
141
#define VALUE_MUL(val1, val2) (val1)->Calc(VALUE_MUL_OPERATOR, val2)
141
142
#define VALUE_DIV(val1, val2) (val1)->Calc(VALUE_DIV_OPERATOR, val2)
142
143
#define VALUE_NEG(val1)       (val1)->Calc(VALUE_NEG_OPERATOR, val1)
143
144
#define VALUE_POS(val1)       (val1)->Calc(VALUE_POS_OPERATOR, val1)
144
 
 
145
 
 
146
 
STR_String CValue::op2str (VALUE_OPERATOR op)
 
145
#endif
 
146
 
 
147
STR_String CValue::op2str(VALUE_OPERATOR op)
147
148
{
148
149
        //pre:
149
150
        //ret: the stringrepresentation of operator op
530
531
        { NULL }        //Sentinel
531
532
};
532
533
 
533
 
PyObject *CValue::pyattr_get_name(void * self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 
534
PyObject *CValue::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
534
535
{
535
536
        CValue * self = static_cast<CValue *> (self_v);
536
537
        return PyUnicode_From_STR_String(self->GetName());
537
538
}
538
539
 
539
 
CValue* CValue::ConvertPythonToValue(PyObject *pyobj, const char *error_prefix)
 
540
/**
 
541
 * There are 2 reasons this could return NULL
 
542
 * - unsupported type.
 
543
 * - error converting (overflow).
 
544
 *
 
545
 * \param do_type_exception Use to skip raising an exception for unknown types.
 
546
 */
 
547
CValue *CValue::ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix)
540
548
{
541
549
 
542
 
        CValue* vallie = NULL;
 
550
        CValue *vallie;
543
551
        /* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */
544
552
#if 0
545
553
        if (PyList_Check(pyobj))
573
581
 
574
582
        } else
575
583
#endif
 
584
        /* note: Boolean check should go before Int check [#34677] */
 
585
        if (PyBool_Check(pyobj))
 
586
        {
 
587
                vallie = new CBoolValue( (bool)PyLong_AsLongLong(pyobj) );
 
588
        } else
576
589
        if (PyFloat_Check(pyobj))
577
590
        {
578
 
                vallie = new CFloatValue( (float)PyFloat_AsDouble(pyobj) );
 
591
                const double tval = PyFloat_AsDouble(pyobj);
 
592
                if (tval > (double)FLT_MAX || tval < (double)-FLT_MAX) {
 
593
                        PyErr_Format(PyExc_OverflowError, "%soverflow converting from float, out of internal range", error_prefix);
 
594
                        vallie = NULL;
 
595
                }
 
596
                else {
 
597
                        vallie = new CFloatValue((float)tval);
 
598
                }
579
599
        } else
580
600
        if (PyLong_Check(pyobj))
581
601
        {
588
608
        if (PyObject_TypeCheck(pyobj, &CValue::Type)) /* Note, don't let these get assigned to GameObject props, must check elsewhere */
589
609
        {
590
610
                vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
591
 
        } else
592
 
        {
593
 
                /* return an error value from the caller */
594
 
                PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix);
 
611
        }
 
612
        else {
 
613
                if (do_type_exception) {
 
614
                        /* return an error value from the caller */
 
615
                        PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix);
 
616
                }
 
617
                vallie = NULL;
595
618
        }
596
619
        return vallie;
597
620