| 52 | } |
| 53 | |
| 54 | GameStatePython* DoomGamePython::getState() { |
| 55 | if (!this->isRunning()) throw ViZDoomIsNotRunningException(); |
| 56 | if (this->state == nullptr) return nullptr; |
| 57 | |
| 58 | // TODO: the following line causes: |
| 59 | // Fatal Python error: PyEval_SaveThread: NULL tstate |
| 60 | //ReleaseGIL gil = ReleaseGIL(); |
| 61 | this->pyState = new GameStatePython(); |
| 62 | |
| 63 | this->pyState->number = this->state->number; |
| 64 | this->pyState->tic = this->state->tic; |
| 65 | |
| 66 | /* Update buffers */ |
| 67 | this->updateBuffersShapes(); |
| 68 | |
| 69 | if (this->state->screenBuffer != nullptr) |
| 70 | this->pyState->screenBuffer = this->dataToNumpyArray(this->colorShape, this->state->screenBuffer->data()); |
| 71 | else this->pyState->screenBuffer = pyb::none(); |
| 72 | |
| 73 | if (this->state->audioBuffer != nullptr) |
| 74 | this->pyState->audioBuffer = this->dataToNumpyArray(this->audioShape, this->state->audioBuffer->data()); |
| 75 | else this->pyState->audioBuffer = pyb::none(); |
| 76 | |
| 77 | if (this->state->depthBuffer != nullptr) |
| 78 | this->pyState->depthBuffer = this->dataToNumpyArray(this->grayShape, this->state->depthBuffer->data()); |
| 79 | else this->pyState->depthBuffer = pyb::none(); |
| 80 | |
| 81 | if (this->state->labelsBuffer != nullptr) { |
| 82 | this->pyState->labelsBuffer = this->dataToNumpyArray(this->grayShape, this->state->labelsBuffer->data()); |
| 83 | |
| 84 | /* Update labels */ |
| 85 | this->pyState->labels = DoomGamePython::vectorToPyList<Label>(this->state->labels); |
| 86 | } else { |
| 87 | this->pyState->labelsBuffer = pyb::none(); |
| 88 | this->pyState->labels = pyb::none(); |
| 89 | } |
| 90 | |
| 91 | if (this->state->automapBuffer != nullptr) |
| 92 | this->pyState->automapBuffer = this->dataToNumpyArray(this->colorShape, this->state->automapBuffer->data()); |
| 93 | else this->pyState->automapBuffer = pyb::none(); |
| 94 | |
| 95 | /* Update notifications buffer */ |
| 96 | if (this->doomController->isNotificationsEnabled()) |
| 97 | this->pyState->notificationsBuffer = pyb::str(this->state->notificationsBuffer); |
| 98 | else this->pyState->notificationsBuffer = pyb::none(); |
| 99 | |
| 100 | /* Updates vars */ |
| 101 | if (!this->state->gameVariables.empty()) { |
| 102 | // Numpy array version |
| 103 | this->variablesShape[0] = this->state->gameVariables.size(); |
| 104 | this->pyState->gameVariables = dataToNumpyArray(this->variablesShape, this->state->gameVariables.data()); |
| 105 | |
| 106 | // Python list version |
| 107 | //this->pyState->gameVariables = DoomGamePython::vectorToPyList<double>(this->state->gameVariables); |
| 108 | } |
| 109 | else this->pyState->gameVariables = pyb::none(); |
| 110 | |
| 111 | /* Update objects */ |
nothing calls this directly
no test coverage detected