Animation* EffectManager::loadAnimation(std::string &s) { if (s != "") { AnimationSet *animationSet = anim->getAnimationSet(s); return animationSet->getAnimation(); } return NULL; }
int PreviewWindow::handle(int nEvent) { int nRet = Fl_Double_Window::handle(nEvent); switch(nEvent){ case FL_PUSH: if(Fl::event_clicks()){ extern AnimationPreviewWindow *g_AnimationPreviewWindow; int nFileIndex = g_AnimationPreviewWindow->FileIndex(); int nAnimationIndex = g_AnimationPreviewWindow->AnimationIndex(); extern AnimationSet g_AnimationSet; g_AnimationSet.ImportMir2Animation(nFileIndex, nAnimationIndex); { static AnimationInfoWindow *pWin = nullptr; delete pWin; pWin = new AnimationInfoWindow; pWin->Set(12); pWin->RedrawAll(); pWin->ShowAll(); } hide(); } break; default: break; } return nRet; }
void Loot::loadAnimation(std::string _gfx) { gfx = _gfx; if (gfx != "") { anim->increaseCount(gfx); AnimationSet *as = anim->getAnimationSet(gfx); animation = as->getAnimation(); } }
/// Retursn NULL upon failure and a new AnimationSet upon success! AnimationSet * AnimationManager::LoadAnimationSet(String fromFolder) { AnimationSet * animSet = new AnimationSet(); bool result = animSet->Load(fromFolder); if (!result) { delete animSet; return NULL; } this->animationSets.Add(animSet); return animSet; }
void Hazard::loadAnimation(std::string &s) { if (activeAnimation) { anim->decreaseCount(animation_name); delete activeAnimation; activeAnimation = 0; } animation_name = s; if (animation_name != "") { anim->increaseCount(animation_name); AnimationSet *animationSet = anim->getAnimationSet(animation_name); activeAnimation = animationSet->getAnimation(); } }
/* If there is more than one animation then the first is returned */ Animation* TextureManager::GetAnimation(std::string _xml_animation) { if(GetInstance()->animations_.find(_xml_animation) != GetInstance()->animations_.end()) { return GetInstance()->animations_[_xml_animation]->GetDefaultAnimation(); } else { AnimationSet* as = GetInstance()->AddAnimationSet(_xml_animation); if(as) return as->GetDefaultAnimation(); else return NULL; } }
void PendingAnimationTracker::AddPending(dom::Animation& aAnimation, AnimationSet& aSet) { aSet.PutEntry(&aAnimation); // Schedule a paint. Otherwise animations that don't trigger a paint by // themselves (e.g. CSS animations with an empty keyframes rule) won't // start until something else paints. EnsurePaintIsScheduled(); }
bool PendingAnimationTracker::IsWaiting(const dom::Animation& aAnimation, const AnimationSet& aSet) const { return aSet.Contains(const_cast<dom::Animation*>(&aAnimation)); }
void PendingAnimationTracker::RemovePending(dom::Animation& aAnimation, AnimationSet& aSet) { aSet.RemoveEntry(&aAnimation); }
XAsset::XAsset(const char* resourcePath) { // report progress if( Engine::instance->progressCallback ) { Engine::instance->progressCallback( wstrformat( Gui::iLanguage->getUnicodeString(4), asciizToUnicode(resourcePath).c_str() ).c_str(), 0.0f, Engine::instance->progressCallbackUserData ); } IResource* resource = getCore()->getResource( resourcePath, "rb" ); assert( resource ); // retrieve file size FILE* file = resource->getFile(); fseek( file, 0, SEEK_END ); int fileSize = ftell( file ); fseek( file, 0, SEEK_SET ); // create buffer & load file data in buffer char* buffer = new char[fileSize]; fread( buffer, 1, fileSize, file ); resource->release(); // report progress if( Engine::instance->progressCallback ) { Engine::instance->progressCallback( wstrformat( Gui::iLanguage->getUnicodeString(4), asciizToUnicode(resourcePath).c_str() ).c_str(), 0.25f, Engine::instance->progressCallbackUserData ); } // create hierarchy allocation interface XAllocateHierarchy xAlloc; // load hierarchy from file D3DXFRAME* rootFrame; ID3DXAnimationController* animController; _dxCR( D3DXLoadMeshHierarchyFromXInMemory( buffer, fileSize, D3DXMESH_MANAGED, iDirect3DDevice, &xAlloc, NULL, &rootFrame, &animController ) ); delete[] buffer; // report progress if( Engine::instance->progressCallback ) { Engine::instance->progressCallback( wstrformat( Gui::iLanguage->getUnicodeString(4), asciizToUnicode(resourcePath).c_str() ).c_str(), 0.5f, Engine::instance->progressCallbackUserData ); } // create D3 animation objects Clump* clump = new Clump( "SCENE_ROOT" ); clump->setFrame( static_cast<Frame*>( rootFrame ) ); if( animController ) { ID3DXAnimationSet* animationSet; const char* animationName; animController->GetAnimationSet( 0, &animationSet ); unsigned int numAnimations = animationSet->GetNumAnimations(); float period = float( animationSet->GetPeriod() ); float numFramesPerSecond = 100.0f/3.0f; float frameTime = 1.0f / numFramesPerSecond; unsigned int numFrames = unsigned int( period * numFramesPerSecond ); if( !numFrames ) numFrames++; AnimationSet* as = new AnimationSet( numAnimations ); for( unsigned int i=0; i<numAnimations; i++ ) { SRT srt; animationSet->GetAnimationNameByIndex( i, &animationName ); Animation* animation = new Animation( animationName, numFrames ); for( unsigned int j=0; j<numFrames; j++ ) { srt.time = j * frameTime; _dxCR( animationSet->GetSRT( srt.time, i, &srt.scale, &srt.rotation, &srt.translation ) ); animation->setKey( j, &srt ); } assert( animation->validateKeys() ); as->setAnimation( i, animation ); } clump->setAnimation( as ); animationSet->Release(); animController->Release(); } // report progress if( Engine::instance->progressCallback ) { Engine::instance->progressCallback( wstrformat( Gui::iLanguage->getUnicodeString(4), asciizToUnicode(resourcePath).c_str() ).c_str(), 0.75f, Engine::instance->progressCallbackUserData ); } // create D3 classes for hierarchy createD3HierarchyClasses( clump, rootFrame ); // resolve nameless phenomena resolveNamelessFrames( clump ); _clumps.push_back( clump ); static_cast<Frame*>( rootFrame )->dirty(); // report progress if( Engine::instance->progressCallback ) { Engine::instance->progressCallback( wstrformat( Gui::iLanguage->getUnicodeString(4), asciizToUnicode(resourcePath).c_str() ).c_str(), 1.0f, Engine::instance->progressCallbackUserData ); } }
void Game::Start() { m_sm->initializeAll(); m_animationSystem->setAnimationMap(m_animationMap); sf::Texture* texture = new sf::Texture();; if (!texture->loadFromFile("Media/Textures/player.png")) { std::cout << "Failed to load player spritesheet!" << std::endl; } sf::Sprite* sprite = new sf::Sprite(*texture); AnimationSet* walk = new AnimationSet(); walk->setSpriteSheet(sprite); walk->addFrame(sf::IntRect(32, 0, 32, 32)); walk->addFrame(sf::IntRect(64, 0, 32, 32)); walk->addFrame(sf::IntRect(32, 0, 32, 32)); walk->addFrame(sf::IntRect(0, 0, 32, 32)); walk->setDuration(sf::seconds(1.f)); m_animationMap->addAnimationSet(AnimationType::Walk_Nord, *walk); artemis::Entity & player = m_em->create(); player.addComponent(new cAnimation()); player.addComponent(new cRender()); player.addComponent(new cTransform()); player.addComponent(new cVelocity()); player.refresh(); cAnimation* comp = (cAnimation*) player.getComponent<cAnimation>(); comp->setAnimationType(AnimationType::Walk_Nord); cTransform* transform = (cTransform*)player.getComponent<cTransform>(); cVelocity* velocity = (cVelocity*) player.getComponent < cVelocity>(); /*transform->setOrigin(20, 20);*/ /*velocity->setVelocity(20, 0);*/ sf::Texture* texture2 = new sf::Texture();; if (!texture2->loadFromFile("Media/Textures/monster.png")) { std::cout << "Failed to load enemy spritesheet!" << std::endl; } sf::Sprite* sprite2 = new sf::Sprite(*texture2); artemis::Entity& enemy = m_em->create(); enemy.addComponent(new cRender()); enemy.addComponent(new cTransform()); enemy.addComponent(new cCollider()); enemy.refresh(); cRender* render = (cRender*) enemy.getComponent<cRender>(); render->setSprite(sprite2); transform = (cTransform*) enemy.getComponent<cTransform>(); transform->move(100, 0); transform->setScale(0.5f, 0.5f); sf::Texture* texture3 = new sf::Texture();; if (!texture3->loadFromFile("Media/Textures/monster.png")) { std::cout << "Failed to load enemy spritesheet!" << std::endl; } sf::Sprite* sprite3 = new sf::Sprite(*texture3); artemis::Entity& enemy2 = m_em->create(); enemy2.addComponent(new cRender()); enemy2.addComponent(new cTransform()); enemy2.addComponent(new cCollider()); enemy2.refresh(); cRender* render2 = (cRender*)enemy2.getComponent<cRender>(); render2->setSprite(sprite3); transform = (cTransform*)enemy2.getComponent<cTransform>(); transform->move(0, 100); transform->setScale(0.5f, 0.5f); m_movementSystem->setInaction(0.4f); /*sf::RenderStates states; while (true) { m_window->clear(); m_window->draw(*comp->getSprite(), states); m_window->display(); }*/ m_playerManager->setPlayer(&player); m_actionMap["up"] = Action(sf::Keyboard::W, Action::ActionType::Hold) && !(Action(sf::Keyboard::A, Action::ActionType::Hold) && Action(sf::Keyboard::D, Action::ActionType::Hold) && Action(sf::Keyboard::S, Action::ActionType::Hold)); m_actionMap["down"] = Action(sf::Keyboard::S, Action::ActionType::Hold) && !(Action(sf::Keyboard::A, Action::ActionType::Hold) && Action(sf::Keyboard::W, Action::ActionType::Hold) && Action(sf::Keyboard::D, Action::ActionType::Hold)); m_actionMap["right"] = Action(sf::Keyboard::D, Action::ActionType::Hold) && !(Action(sf::Keyboard::A, Action::ActionType::Hold) && Action(sf::Keyboard::W, Action::ActionType::Hold) && Action(sf::Keyboard::S, Action::ActionType::Hold)); m_actionMap["left"] = Action(sf::Keyboard::A, Action::ActionType::Hold) && !(Action(sf::Keyboard::W, Action::ActionType::Hold) && Action(sf::Keyboard::S, Action::ActionType::Hold) && Action(sf::Keyboard::D, Action::ActionType::Hold)); m_actionMap["down_right"] = Action(sf::Keyboard::S, Action::ActionType::Hold) && Action(sf::Keyboard::D, Action::ActionType::Hold); m_actionMap["down_left"] = Action(sf::Keyboard::S, Action::ActionType::Hold) && Action(sf::Keyboard::A, Action::ActionType::Hold); m_actionMap["up_right"] = Action(sf::Keyboard::W, Action::ActionType::Hold) && Action(sf::Keyboard::D, Action::ActionType::Hold); m_actionMap["up_left"] = Action(sf::Keyboard::W, Action::ActionType::Hold) && Action(sf::Keyboard::A, Action::ActionType::Hold); m_callBacks.connect("up", std::bind(&PlayerManager::move, *m_playerManager, 0, -20)); m_callBacks.connect("down", std::bind(&PlayerManager::move, *m_playerManager, 0, 20)); m_callBacks.connect("right", std::bind(&PlayerManager::move, *m_playerManager, 20, 0)); m_callBacks.connect("left", std::bind(&PlayerManager::move, *m_playerManager, -20, 0)); m_callBacks.connect("up_right", std::bind(&PlayerManager::move, *m_playerManager, 20, -20)); m_callBacks.connect("up_left", std::bind(&PlayerManager::move, *m_playerManager, -20, -20)); m_callBacks.connect("down_right", std::bind(&PlayerManager::move, *m_playerManager, 20, 20)); m_callBacks.connect("down_left", std::bind(&PlayerManager::move, *m_playerManager, -20, 20)); }