MCPcopy Create free account
hub / github.com/SimHacker/micropolis / renderPixels

Method renderPixels

MicropolisCore/src/TileEngine/src/tileengine.cpp:638–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

636
637
638void TileEngine::renderPixels(
639 cairo_surface_t *destSurf,
640 cairo_surface_t *cmapSurf,
641 PyObject *tileFunction,
642 PyObject *tileMap,
643 int renderCol,
644 int renderRow,
645 int renderCols,
646 int renderRows)
647{
648 if ((tileFunction != Py_None) &&
649 !PyCallable_Check(tileFunction)) {
650 PyErr_SetString(
651 PyExc_TypeError,
652 "expected tileFunction to be a callable function or None");
653 return;
654 }
655
656 // The tileMap should be None, or an array of 4 byte integers,
657 // mapping virtual tiles indices to absolute tile numbers.
658
659 const int *tileMapData = NULL;
660 unsigned int tileMapCount = 0;
661
662 if (tileMap != Py_None) {
663
664 if (!PySequence_Check(tileMap)) {
665 PyErr_SetString(
666 PyExc_TypeError,
667 "expected tileMap to be an array "
668 "of 4 byte integers or None");
669 return;
670 }
671
672 tileMapCount = (unsigned int)PySequence_Size(tileMap);
673 Py_ssize_t tileMapLength = 0;
674 if (PyObject_AsReadBuffer(
675 tileMap,
676 (const void **)&tileMapData,
677 &tileMapLength) != 0) {
678 PyErr_SetString(
679 PyExc_TypeError,
680 "expected tileMap with read buffer");
681 return;
682 }
683
684 int tileMapDataCount =
685 (int)tileMapLength / sizeof(unsigned int);
686
687 if (tileMapDataCount != (int)tileMapCount) {
688 PyErr_SetString(
689 PyExc_TypeError,
690 "expected tileMap read buffer of 4 byte integers");
691 return;
692 }
693 }
694
695 unsigned char *destData = cairo_image_surface_get_data(destSurf);

Calls

no outgoing calls

Tested by

no test coverage detected