| 734 | |
| 735 | |
| 736 | PyObject *TileEngine::getTileData( |
| 737 | PyObject *tileFunction, |
| 738 | PyObject *tileMap, |
| 739 | int col, |
| 740 | int row, |
| 741 | int cols, |
| 742 | int rows, |
| 743 | int code, |
| 744 | PyObject *tileViewCache) |
| 745 | { |
| 746 | if ((tileFunction != Py_None) && |
| 747 | !PyCallable_Check(tileFunction)) { |
| 748 | PyErr_SetString( |
| 749 | PyExc_TypeError, |
| 750 | "expected tileFunction to be a callable function or None"); |
| 751 | Py_INCREF(Py_None); |
| 752 | return Py_None; |
| 753 | } |
| 754 | |
| 755 | const int *tileMapData = NULL; |
| 756 | unsigned int tileMapCount = 0; |
| 757 | |
| 758 | if (tileMap != Py_None) { |
| 759 | |
| 760 | if (!PySequence_Check(tileMap)) { |
| 761 | PyErr_SetString( |
| 762 | PyExc_TypeError, |
| 763 | "expected tileMap to be an array " |
| 764 | "of 4 byte integers or None"); |
| 765 | Py_INCREF(Py_None); |
| 766 | return Py_None; |
| 767 | } |
| 768 | |
| 769 | tileMapCount = (unsigned int)PySequence_Size(tileMap); |
| 770 | Py_ssize_t tileMapLength = 0; |
| 771 | if (PyObject_AsReadBuffer( |
| 772 | tileMap, |
| 773 | (const void **)&tileMapData, |
| 774 | &tileMapLength) != 0) { |
| 775 | PyErr_SetString( |
| 776 | PyExc_TypeError, |
| 777 | "expected tileMap with read buffer"); |
| 778 | Py_INCREF(Py_None); |
| 779 | return Py_None; |
| 780 | } |
| 781 | |
| 782 | int tileMapDataCount = |
| 783 | (int)tileMapLength / sizeof(unsigned int); |
| 784 | |
| 785 | if (tileMapDataCount != (int)tileMapCount) { |
| 786 | PyErr_SetString( |
| 787 | PyExc_TypeError, |
| 788 | "expected tileMap read buffer of 4 byte integers"); |
| 789 | Py_INCREF(Py_None); |
| 790 | return Py_None; |
| 791 | } |
| 792 | } |
| 793 | |