bool Animation::loadAnimationFromFile(std::string path) { bool temp = true; freeAnimation(); for(int i = 0; i < NUMBER_ANIMATION; ++i) { SDL_Texture* newTexture = NULL; std::stringstream tempPath; tempPath.str(""); tempPath << path << i << ".png"; SDL_Surface* loadedSurface = IMG_Load( tempPath.str().c_str() ); if( loadedSurface == NULL ) { printf( "Unable to load image %s! SDL_image Error: %s\n", tempPath.str().c_str(), IMG_GetError() ); } else { //Color key image SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) ); //Create texture from surface pixels newTexture = SDL_CreateTextureFromSurface( gRenderer, loadedSurface ); if( newTexture == NULL ) { printf( "Unable to create texture from %s! SDL Error: %s\n", tempPath.str().c_str(), SDL_GetError() ); } else { //Get image dimensions mWidth = loadedSurface->w; mHeight = loadedSurface->h; } //Get rid of old loaded surface SDL_FreeSurface( loadedSurface ); } animations[i] = newTexture; temp = (animations[i] != NULL); if(!temp) { return temp; } } std::stringstream tempPath; tempPath.str(""); tempPath << path << "0.png"; temp = loadFromFile(tempPath.str()); return temp; }
void Scene::loadAnimation(const Common::String &resName, int trigger) { // WORKAROUND: If there's already a previous active animation used by the // scene, then free it before we create the new one if (_activeAnimation) freeAnimation(); DepthSurface depthSurface; UserInterface interfaceSurface(_vm); _activeAnimation = Animation::init(_vm, this); _activeAnimation->load(interfaceSurface, depthSurface, resName, _vm->_dithering ? ANIMFLAG_DITHER : 0, nullptr, nullptr); _activeAnimation->startAnimation(trigger); }
int Scene::loadAnimation(const Common::String &resName, int trigger) { // WORKAROUND: If there's already a previous active animation used by the // scene, then free it before we create the new one if ((_vm->getGameID() == GType_RexNebular) && _animation[0]) freeAnimation(0); DepthSurface depthSurface; UserInterface interfaceSurface(_vm); for (int i = 0; i < 10; i++) { if (!_animation[i]) { _animation[i] = Animation::init(_vm, this); _animation[i]->load(interfaceSurface, depthSurface, resName, _vm->_dithering ? ANIMFLAG_DITHER : 0, nullptr, nullptr); _animation[i]->startAnimation(trigger); return i; } } error("Unable to find an available animation slot"); return -1; }
/** * \fn int closeInterface(sInterface *p_interface) * \brief Fonction de desallocation de structure de type sInterface * * \param *p_interface pointeur vers une structure de type sInterface * \return int représentant le déroulement de la fonction */ int closeInterface(sInterface *p_interface) { int l_i; for (l_i = 0; l_i < CASE_TYPE_AMOUNT; ++l_i) { SDL_DestroyTexture(p_interface->caseSprite[l_i]); } for (l_i = 0; l_i < 4; ++l_i) { SDL_DestroyTexture(p_interface->player.playerSprite[l_i]); } freeAnimation(p_interface->effect.l_mountain); freeAnimation(p_interface->effect.l_tuto); freeAnimation(p_interface->effect.l_raccoon); freeAnimation(p_interface->effect.l_logo); freeAnimation(p_interface->effect.l_play); freeAnimation(p_interface->effect.l_congrate); SDL_DestroyRenderer(p_interface->renderer); SDL_DestroyWindow(p_interface->window); return 0; }
void MadsScene::updateState() { if (!_abortTimers && !_madsVm->_player._unk3) { if (_dynamicHotspots._changed) _dynamicHotspots.refresh(); // int v = (_madsVm->_player._stepEnabled && !_action._startWalkFlag && !_abortTimers2) ? 1 : 0; // _screenObjects.check(v, false); } // Handle starting off any selected action bool doPreAction = false; if ((_action._selectedAction != 0) && _madsVm->_player._stepEnabled && !_action._startWalkFlag && !_abortTimers && !_madsVm->_player._unk3) { // Start the action _action.startAction(); if (_action._action.verbId == kVerbLookAt) { _action._action.verbId = kVerbLook; _action._savedFields.selectedRow = 0; } doPreAction = true; } if (doPreAction || ((_abortTimers != 0) && (_abortTimersMode == ABORTMODE_2))) doPreactions(); checkStartWalk(); if (_action._inProgress && !_madsVm->_player._moving && !_action._startWalkFlag && (_madsVm->_player._newDirection == _madsVm->_player._direction)) { // Reached the end of action movement, so ready to actually do action doAction(); } else if ((_abortTimers != 0) && (_abortTimersMode == ABORTMODE_0)) // Do an action designated by scripts doAction(); bool freeFlag = false; if (_currentScene != _nextScene) freeFlag = true; else { doSceneStep(); if (_currentScene != _nextScene) freeFlag = true; else { // Update the player _madsVm->_player.nextFrame(); // Handle updating the animation if (!_abortTimers && (_activeAnimation)) _activeAnimation->update(); // Handle refreshing the mouse position display if (_mouseMsgIndex != -1) _madsVm->scene()->_kernelMessages.remove(_mouseMsgIndex); if (_showMousePos) { char buffer[20]; sprintf(buffer, "(%d,%d)", _madsVm->_mouse->currentPos().x, _madsVm->_mouse->currentPos().y); _mouseMsgIndex = _madsVm->scene()->_kernelMessages.add(Common::Point(5, 5), 0x203, 0, 0, 1, buffer); } } } if (_madsVm->globals()->_config.easyMouse) _action.refresh(); if ((_activeAnimation) && !_abortTimers) { _activeAnimation->update(); if (((MadsAnimation *) _activeAnimation)->freeFlag() || freeFlag) { delete _activeAnimation; _activeAnimation = NULL; } } MadsView::update(); // Remove the animation if it's been completed if ((_activeAnimation) && ((MadsAnimation *)_activeAnimation)->freeFlag()) freeAnimation(); if ((_action._selectedAction != 0) || !_madsVm->_player._stepEnabled) { _action.clear(); _action._selectedAction = 0; } }
void Scene::doFrame() { Player &player = _vm->_game->_player; bool flag = false; if (_action._selectedAction || !player._stepEnabled) { _action.clear(); _action._selectedAction = 0; } if (!_vm->_game->_trigger && !player._trigger) { // Refresh the dynamic hotspots if they've changed if (_dynamicHotspots._changed) _dynamicHotspots.refresh(); // Check all on-screen visual objects _vm->_game->_screenObjects.check(player._stepEnabled && !player._needToWalk && !_vm->_game->_fx); } if (_action._selectedAction && player._stepEnabled && !player._needToWalk && !_vm->_game->_trigger && !player._trigger) { _action.startAction(); if (_action._activeAction._verbId == Nebular::VERB_LOOK_AT) { _action._activeAction._verbId = VERB_LOOK; _action._savedFields._command = false; } flag = true; } if (flag || (_vm->_game->_trigger && _vm->_game->_triggerMode == SEQUENCE_TRIGGER_PREPARE)) { doPreactions(); } player.newWalk(); if (!_vm->_game->_fx) _frameStartTime = _vm->_events->getFrameCounter(); // Handle parser actions as well as game triggers if ((_action._inProgress && !player._moving && !player._needToWalk && (player._facing == player._turnToFacing) && !_vm->_game->_trigger) || (_vm->_game->_trigger && (_vm->_game->_triggerMode == SEQUENCE_TRIGGER_PARSER))) { doAction(); } if (_currentSceneId != _nextSceneId) { _freeAnimationFlag = true; } else { doSceneStep(); checkKeyboard(); if (_currentSceneId != _nextSceneId) { _freeAnimationFlag = true; } else { player.nextFrame(); // Cursor update code updateCursor(); if (!_vm->_game->_trigger) { // Handle any active sequences _sequences.tick(); // Handle any active animation if (_activeAnimation) _activeAnimation->update(); } // If the debugget flag is set, show the mouse position int mouseTextIndex = 0; if (_vm->_debugger->_showMousePos) { Common::Point pt = _vm->_events->mousePos(); Common::String msg = Common::String::format("(%d,%d)", pt.x, pt.y); mouseTextIndex = _kernelMessages.add(Common::Point(5, 5), 0x203, 0, 0, 1, msg); } if (!_vm->_game->_trigger) { if (_reloadSceneFlag || _currentSceneId != _nextSceneId) _kernelMessages.reset(); _kernelMessages.update(); } _userInterface._uiSlots.draw(!_vm->_game->_fx, _vm->_game->_fx); // Write any text needed by the interface if (_vm->_game->_fx) _userInterface.drawTextElements(); // Draw any elements drawElements((ScreenTransition)_vm->_game->_fx, _vm->_game->_fx); // Handle message updates if (_vm->_game->_fx) { uint32 priorTime = _vm->_game->_priorFrameTimer; uint32 newTime = _vm->_events->getFrameCounter(); _sequences.delay(priorTime, newTime); _kernelMessages.delay(priorTime, newTime); } if (_vm->_debugger->_showMousePos) // Mouse position display isn't persistent, so remove it _kernelMessages.remove(mouseTextIndex); // Original had a debugger check/call here to allow pausing after // drawing each frame. Not implemented under ScummVM } } if (_vm->_game->_fx) _cyclingActive = true; _vm->_game->_fx = kTransitionNone; // Handle freeing animation if necessary if (_activeAnimation && _activeAnimation->freeFlag()) _freeAnimationFlag = true; if (_freeAnimationFlag) freeAnimation(); }
void Scene::freeAnimation() { for (int j = 0; j < 10; j++) freeAnimation(j); _freeAnimationFlag = false; }
Animation::~Animation() { freeAnimation(); }