void AIDeadState::onEnter() { auto spr = getContext().lock()->getSprite(); if (spr->hasSequence(HashedString("dead"))) { spr->play(HashedString("dead")); } }
void AIStateMachine::initStates() { addState(HashedString("idle"), std::make_shared<AIIdleState>(getContext())); addState(HashedString("hurt"), std::make_shared<AIHurtState>(getContext())); addState(HashedString("dead"), std::make_shared<AIDeadState>(getContext())); }
void AIHurtState::onEnter() { auto spr = getContext().lock()->getSprite(); if (spr->hasSequence(HashedString("hurt"))) { spr->setLooping(false); spr->play(HashedString("hurt")); } }
MainMenuScene::MainMenuScene(AppContext& appContext): appContext(appContext) { staticImages = appContext.getDevice()->getVideoDriver()->getTexture("graphics/mainmenu.png"); // load positions of static images from XML file irr::io::IFileSystem* filesys = appContext.getDevice()->getFileSystem(); irr::io::IReadFile* rectanglesFile = filesys->createAndOpenFile(L"graphics/mainmenu.xml"); irr::io::IXMLReader* reader = filesys->createXMLReader(rectanglesFile); loadRectangleList(reader, staticImagesRects); reader->drop(); rectanglesFile->drop(); // create menu arcadeMenu = std::make_shared<ArcadeMenu>(appContext.getDevice()->getTimer(), appContext.getDevice()->getVideoDriver()); addListener(arcadeMenu); ArcadeMenuNode* rootNode = new ArcadeMenuNode(); ArcadeMenuNode* pressStartNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("pressstart")]); ArcadeMenuNode* newGameNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("newgame")]); newGameNode->onClickAction = [this]{ onNewGame(); }; ArcadeMenuNode* optionsNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("options")]); ArcadeMenuNode* quitNode = new ArcadeMenuNode(staticImages, staticImagesRects[HashedString("quit")]); quitNode->onClickAction = [this]{ onQuitGame(); }; rootNode->addChild(pressStartNode); pressStartNode->addChild(newGameNode); pressStartNode->addChild(optionsNode); pressStartNode->addChild(quitNode); arcadeMenu->setRootNode(rootNode); if (!loadControlSchemes(L"save/controls.xml", appContext.getDevice()->getFileSystem(), controlSchemes)) { std::cout << "Failed to load controls." << std::endl; } else { for (size_t i = 0; i < controlSchemes.size(); i++) { arcadeMenu->addControlScheme(&controlSchemes[i]); } } objectEngine.addObject(arcadeMenu); auto fpsDisplay = std::make_shared<FPSDisplay>(appContext); objectEngine.addObject(fpsDisplay); }
void PlayerIdleState::onEnter() { getContext().lock()->getParticle().setVelocity(irr::core::vector3df()); auto spr = getContext().lock()->getSprite(); spr->setLooping(true); spr->play(HashedString("idle")); }
void PlayerMobileState::onEnter() { // GameApp::getSingleton().getLogger()->log("void PlayerMobileState::onEnter()"); auto spr = getContext().lock()->getSprite(); spr->setLooping(true); spr->play(HashedString("mobile")); }
namespace hikari { const EventType ObjectRemovedEventData::Type = HashedString("ObjectRemovedEventData").getHash(); ObjectRemovedEventData::ObjectRemovedEventData(int objectId) : BaseEventData(0.0f) , objectId(objectId) { } int ObjectRemovedEventData::getObjectId() const { return objectId; } ObjectRemovedEventData::~ObjectRemovedEventData() { // Do nothing! HIKARI_LOG(debug1) << "~ObjectRemovedEventData()"; } const EventType & ObjectRemovedEventData::getEventType() const { return ObjectRemovedEventData::Type; } EventDataPtr ObjectRemovedEventData::copy() const { return EventDataPtr(new ObjectRemovedEventData(getObjectId())); } const char * ObjectRemovedEventData::getName() const { return "ObjectRemovedEventData"; } } // hikari
std::shared_ptr<Actor> AIFactory::create() { irr::scene::ISceneManager* smgr = GameApp::getSingleton().getSceneManager(); std::string animDataPath = "../../../art/" + aiName + ".xml"; auto sprData = animationEngine.load(animDataPath.c_str()); assert(sprData); auto spr = std::make_shared<AnimatedSprite>(sprData, smgr->getRootSceneNode(), smgr); spr->setAnchor(irr::core::vector3df(spr->getSize().Width/2, 0.f, spr->getSize().Height)); animationEngine.addSprite(spr); std::shared_ptr<Actor> ai = std::make_shared<Actor>(); // initialize state machine auto stateMachine = std::make_shared<AIStateMachine>(ai, HashedString("idle")); stateMachine->setTeamMembership(membershipSupplier->requestMembership()); stateMachine->initStates(); ai->setStateMachine(stateMachine); ai->setSprite(spr); aiEventSource->addListener(ai); ai->start(); return ai; }
static void writeSurfaces( const char *filename, std::vector< RenderSurface > &surfaces ) { uint64_t hashedName = HashedString( 0, filename ); char outfile[256]; PHYSFS_mkdir( "static_models/" ); sprintf( outfile, "static_models/%08x_%08x.sm", (uint32_t)(hashedName>>32), (uint32_t)(hashedName&0xffffffff) ); PHYSFS_File *model = PHYSFS_openWrite( outfile ); if ( model ) { PHYSFS_writeULE32( model, 0x090 ); PHYSFS_writeULE32( model, surfaces.size() ); for ( uint32_t i=0; i<surfaces.size(); i++ ) { RenderSurface const &surf = surfaces[i]; PHYSFS_writeCStr( model, surf.name.c_str() ); PHYSFS_writeCStr( model, surf.mat->Name() ); const ModelGeometry *geom = surf.geom; PHYSFS_writeSLE32( model, geom->m_numIndices ); PHYSFS_writeSLE32( model, geom->m_numVerts ); PHYSFS_write( model, geom->m_indices, sizeof(uint16_t)*geom->m_numIndices, 1 ); PHYSFS_write( model, geom->m_verts, sizeof(geom->m_verts[0])*geom->m_numVerts, 1 ); } PHYSFS_close( model ); } }
static bool readSurfaces( const char *filename, std::vector< RenderSurface > &surfaces ) { uint64_t hashedName = HashedString( 0, filename ); char outfile[256]; PHYSFS_mkdir( "static_models/" ); sprintf( outfile, "static_models/%08x_%08x.sm", (uint32_t)(hashedName>>32), (uint32_t)(hashedName&0xffffffff) ); PHYSFS_File *model = PHYSFS_openRead( outfile ); if ( model ) { unsigned int ver, numSurf; PHYSFS_readULE32( model, &ver ); PHYSFS_readULE32( model, &numSurf ); surfaces.resize( numSurf ); for ( uint32_t i=0; i<surfaces.size(); i++ ) { RenderSurface &surf = surfaces[i]; PHYSFS_readCStr( model, surf.name ); std::string mat; PHYSFS_readCStr( model, mat ); surf.mat = materialManager()->Load( mat.c_str() ); ModelGeometry *geom = new ModelGeometry; surf.geom = geom; PHYSFS_readSLE32( model, &geom->m_numIndices ); PHYSFS_readSLE32( model, &geom->m_numVerts ); geom->m_indices = new unsigned short[geom->m_numIndices]; geom->m_verts = new ModelVert[geom->m_numVerts]; PHYSFS_read( model, geom->m_indices, sizeof(uint16_t)*geom->m_numIndices, 1 ); PHYSFS_read( model, geom->m_verts, sizeof(geom->m_verts[0])*geom->m_numVerts, 1 ); } PHYSFS_close( model ); return true; } return false; }
void AIHurtState::onUpdate(GameTime& time) { if (!getContext().lock()->getSprite()->getPlaying()) { // TODO: consider that you may get hurt in the air or die or something getContext().lock()->getStateMachine()->switchToState(HashedString("idle")); } }
void MainMenuScene::onRedraw() { video::IVideoDriver* driver = appContext.getDevice()->getVideoDriver(); core::dimension2du screenSize(driver->getScreenSize()); const core::recti headerRect = staticImagesRects[HashedString("title")]; const core::position2di headerPos( screenSize.Width/2 - headerRect.getWidth()/2, 0); driver->beginScene(true, true, COLOR_CORNFLOWER_BLUE); const core::recti tileRect = staticImagesRects[HashedString("tile")]; irr::u32 time = appContext.getDevice()->getTimer()->getTime(); irr::u32 offset = (time/30) % tileRect.getWidth(); // draw tiled background for (int x = -1; x < (int)screenSize.Width/tileRect.getWidth() + 1; x++) { for (int y = -1; y < (int)screenSize.Height/tileRect.getHeight() + 1; y++) { driver->draw2DImage(staticImages, core::position2di(offset + x * tileRect.getWidth(), offset + y * tileRect.getHeight()), tileRect, 0, video::SColor(255,255,255,255), false); } } // draw header driver->draw2DImage(staticImages, headerPos, headerRect, 0, video::SColor(255,255,255,255), true); core::dimension2du bounds(arcadeMenu->getBounds()); core::vector2df topLeft( screenSize.Width/2 - bounds.Width/2, screenSize.Height*2/3 - bounds.Height/2); arcadeMenu->render(topLeft); appContext.getDevice()->getSceneManager()->drawAll(); appContext.getDevice()->getGUIEnvironment()->drawAll(); driver->endScene(); }
void PlayerIdleState::onUpdate(GameTime& time) { const KeyMap* k = appContext.getKeyMap(); // example: won't switch to mobile state if you're pressing both left and right at the same time. if ((k->isKeyDown(scheme.upKey) != k->isKeyDown(scheme.downKey) || (k->isKeyDown(scheme.leftKey) != k->isKeyDown(scheme.rightKey)))) { getContext().lock()->getStateMachine()->switchToState(HashedString("mobile")); } }
bool PlayerMobileState::onEvent(const Event& e) { if (e.getType() == HashedString("IrrlichtEvent")) { const irr::SEvent& se = static_cast<const IrrlichtEvent&>(e).getEvent(); if (se.EventType == irr::EET_KEY_INPUT_EVENT) { if (se.KeyInput.PressedDown) { if (scheme.getActionKeyIndex(se.KeyInput.Key) == 0) { getContext().lock()->getStateMachine()->switchToState(HashedString("attacking")); return true; } } } } return false; }
void loadRectangleList( irr::io::IXMLReader* reader, std::map<HashedString, irr::core::recti>& rectangles) { const wchar_t* rectstr = L"rectangles"; // fast forward reader to next "rectangles" section while ((reader->getNodeType() != irr::io::EXN_ELEMENT || irr::core::stringw(reader->getNodeName()) != rectstr) && reader->read()); while (reader->read()) { switch (reader->getNodeType()) { case irr::io::EXN_ELEMENT: break; case irr::io::EXN_ELEMENT_END: // found end of rectangles. done! if (irr::core::stringw(reader->getNodeName()) == rectstr) { return; } break; case irr::io::EXN_TEXT: { std::wstringstream entry(reader->getNodeData()); while (true) { std::wstring rectName; int left=0.f, top=0.f, bottom=0.f, right=0.f; entry >> rectName; entry >> left; entry >> top; entry >> bottom; entry >> right; if (entry.eof()) break; const irr::core::recti rect(left,top,bottom,right); rectangles[HashedString(rectName.c_str())] = rect; std::wcout << L"Read rectangle: " << rectName << L" "; std::cout << rect << std::endl; } } break; default: break; } } }
bool KeyMap::onEvent(const Event& e) { if (e.getType() == HashedString("IrrlichtEvent")) { const IrrlichtEvent& ie = static_cast<const IrrlichtEvent&>(e); const irr::SEvent& se = ie.getEvent(); if (se.EventType == irr::EET_KEY_INPUT_EVENT) { keyDownMap[se.KeyInput.Key] = se.KeyInput.PressedDown; } } return false; }
void PlayerMobileState::onUpdate(GameTime& time) { // GameApp::getSingleton().getLogger()->log("void PlayerMobileState::onUpdate()"); irr::core::vector3df movementDirection; const float velocityMagnitude = 225.f; const std::shared_ptr<KeyMap>& k = GameApp::getSingleton().getKeyMap(); irr::core::vector3df currVel; if (k->isKeyDown(scheme.upKey) != k->isKeyDown(scheme.downKey)) { if (k->isKeyDown(scheme.upKey)) { movementDirection.Y -= 1.0f; } if (k->isKeyDown(scheme.downKey)) { movementDirection.Y += 1.0f; } } if (k->isKeyDown(scheme.leftKey) != k->isKeyDown(scheme.rightKey)) { if (k->isKeyDown(scheme.leftKey)) { movementDirection.X -= 1.0f; getContext().lock()->getSprite()->setFlipHorizontal(true); } if (k->isKeyDown(scheme.rightKey)) { movementDirection.X += 1.0f; getContext().lock()->getSprite()->setFlipHorizontal(false); } } // if velocity is 0, set flag that movement is done. if (movementDirection == irr::core::vector3df()) { getContext().lock()->getStateMachine()->switchToState(HashedString("idle")); } else { movementDirection.normalize(); movementDirection *= velocityMagnitude; getContext().lock()->getParticle().setVelocity(movementDirection); } }
ParseHelper( const QString& fileName, bool force, Driver* driver, bool reportMessages = true, QString includedFrom = QString() ) : m_wasReset( false ), m_fileName( fileName ), m_previousFileName( driver->m_currentFileName ), m_previousLexer( driver->lexer ), m_previousParsedFile( driver->m_currentParsedFile ), m_previousCachedLexedFile( driver->m_currentLexerCache ), m_force( force ), m_driver( driver ), m_lex( m_driver ) { QFileInfo fileInfo( fileName ); m_driver->m_currentParsedFile = new ParsedFile( fileName, fileInfo.lastModified() ); if( !includedFrom.isEmpty() ) m_driver->m_currentParsedFile->setIncludedFrom( includedFrom ); #ifdef CACHELEXER m_driver->m_currentLexerCache = new CachedLexedFile( fileName, &m_driver->m_lexerCache ); #endif m_absFilePath = fileInfo.absFilePath(); QMap<QString, ParsedFilePointer>::Iterator it = m_driver->m_parsedUnits.find( m_absFilePath ); if ( force && it != m_driver->m_parsedUnits.end() ) { m_driver->takeTranslationUnit( m_absFilePath ); } else if ( it != m_driver->m_parsedUnits.end() && *it != 0 ) { // file already processed return ; } CachedLexedFilePointer lexedFileP = m_driver->m_lexerCache.lexedFile( HashedString( fileName ) ); m_driver->m_dependences.remove( fileName ); m_driver->m_problems.remove( fileName ); driver->m_currentFileName = fileName; m_driver->lexer = &m_lex; m_driver->setupLexer( &m_lex ); m_lex.setReportMessages( reportMessages ); //kdDebug( 9007 ) << "lexing file " << fileName << endl; m_lex.setSource( m_driver->sourceProvider() ->contents( fileName ) ); if(m_previousCachedLexedFile) m_previousCachedLexedFile->merge( *m_driver->m_currentLexerCache ); else m_driver->findOrInsertProblemList( m_driver->m_currentMasterFileName ) += m_driver->m_currentLexerCache->problems(); if( !lexedFileP && m_previousParsedFile ) //only add the new cache-instance if a fitting isn't already stored, and if this file was included by another one. m_driver->m_lexerCache.addLexedFile( m_driver->m_currentLexerCache ); //Copy the recursive include-files into the ParsedFile m_driver->m_currentParsedFile->addIncludeFiles( m_driver->m_currentLexerCache->includeFiles() ); m_driver->m_currentParsedFile->setSkippedLines( m_lex.skippedLines() ); }
void Sprite::InitializeAnimations( const SimpleString& SpriteName ) { STATICHASH( Width ); STATICHASH( Height ); STATICHASH( NumAnimations ); MAKEHASH( SpriteName ); m_Width = ConfigManager::GetInt( sWidth, m_pSurface->GetWidth(), sSpriteName ); m_Height = ConfigManager::GetInt( sHeight, m_pSurface->GetHeight(), sSpriteName ); m_Animations.Clear(); ASSERT( m_pSurface ); ASSERT( m_Width <= m_pSurface->GetWidth() ); ASSERT( m_Height <= m_pSurface->GetHeight() ); int FrameColumns = m_pSurface->GetWidth() / m_Width; int NumAnimations = ConfigManager::GetInt( sNumAnimations, 0, sSpriteName ); for( int AnimIndex = 0; AnimIndex < NumAnimations; ++AnimIndex ) { Sprite::Animation* Animation = new Sprite::Animation; SimpleString AnimationName = ConfigManager::GetSequenceString( "Animation%d", AnimIndex, "", sSpriteName ); STATICHASH( NumFrames ); MAKEHASH( AnimationName ); int NumFrames = ConfigManager::GetInt( sNumFrames, 0, sAnimationName ); for( int FrameIndex = 0; FrameIndex < NumFrames; ++FrameIndex ) { Sprite::Frame Frame; int FrameNum = ConfigManager::GetSequenceInt( "Frame%d", FrameIndex, 0, sAnimationName ); Frame.Duration = ConfigManager::GetSequenceFloat( "Duration%d", FrameIndex, 0.0f, sAnimationName ); Frame.x = ( FrameNum % FrameColumns ) * m_Width; Frame.y = ( FrameNum / FrameColumns ) * m_Height; ASSERT( Frame.Duration > 0.0f || NumFrames == 1 ); Animation->m_Frames.PushBack( Frame ); } m_Animations.Insert( HashedString( AnimationName ), Animation ); } }
void MeshCompiler::CompileArmature( TiXmlElement* Arm ) { if( Arm ) { m_Header.m_HasSkeleton = true; TiXmlAttribute* ArmAttr = Arm->FirstAttribute(); // "frames" m_Header.m_NumFrames = ArmAttr->IntValue() + 1; // + 1 for T-pose at frame 0 for( TiXmlElement* Bone = Arm->FirstChildElement( "bonedef" ); Bone; Bone = Bone->NextSiblingElement( "bonedef" ) ) { SNamedBone sbone; TiXmlAttribute* BoneAttr = Bone->FirstAttribute(); const char* pName = BoneAttr->Value(); sbone.m_Name = HashedString( pName ); // Push an identity so frame 0 is the T-pose sbone.m_FrameQuats.PushBack( Quat() ); sbone.m_FrameTransVecs.PushBack( Vector() ); for( TiXmlElement* Frame = Bone->FirstChildElement( "frame" ); Frame; Frame = Frame->NextSiblingElement( "frame" ) ) { Matrix FrameMatrix; TiXmlAttribute* FrameAttr = Frame->FirstAttribute(); // In case I ever need separate frame values int FrameNum = FrameAttr->IntValue(); Unused( FrameNum ); FrameAttr = FrameAttr->Next(); GetXMLMatrix( FrameAttr, FrameMatrix ); Quat FrameQuat = FrameMatrix.ToQuaternion(); Vector FrameTransVec = FrameMatrix.GetTranslationElements(); sbone.m_FrameQuats.PushBack( FrameQuat ); sbone.m_FrameTransVecs.PushBack( FrameTransVec ); } m_Bones.PushBack( sbone ); ++m_Header.m_NumBones; } CompileAnimations( Arm ); } }
bool PlayerIdleState::onEvent(const Event& e) { if (auto ie = dynamic_downcast<const IrrlichtEvent*>(&e)) { const irr::SEvent& se = ie->getEvent(); if (se.EventType == irr::EET_KEY_INPUT_EVENT) { if (se.KeyInput.PressedDown) { if (scheme.getActionKeyIndex(se.KeyInput.Key) == 0) { getContext().lock()->getStateMachine()->switchToState(HashedString("attacking")); return true; } } } } return false; }
HashedString DamageZoneCreationEvent::getType() const { return HashedString("DamageZoneCreationEvent"); }
void AIIdleState::onEnter() { getContext().lock()->getSprite()->play(HashedString("idle")); }
void MeshCompiler::CompileFace( TiXmlElement* Face ) { uint NumVertsInFace = 0; uint TempIndices[4]; Vector TempPositions[4]; for( TiXmlElement* Vert = Face->FirstChildElement( "vert" ); Vert; Vert = Vert->NextSiblingElement( "vert" ) ) { // Push back cached indices to handle 4-sided faces if( NumVertsInFace == 3 ) { m_Indices.PushBack( TempIndices[0] ); m_Indices.PushBack( TempIndices[2] ); } m_TempPos = Vector( 0.f, 0.f, 0.f ); m_TempUV = Vector2( 0.f, 0.f ); m_TempNorm = Vector( 0.f, 0.f, 0.f ); m_TempBoneIndex = SBoneData(); m_TempBoneWeight = SBoneWeights(); TiXmlElement* Pos = Vert->FirstChildElement( "pos" ); if( Pos ) { TiXmlAttribute* PosAttr = Pos->FirstAttribute(); m_TempPos.x = (float)PosAttr->DoubleValue(); PosAttr = PosAttr->Next(); m_TempPos.y = (float)PosAttr->DoubleValue(); PosAttr = PosAttr->Next(); m_TempPos.z = (float)PosAttr->DoubleValue(); } TempPositions[ NumVertsInFace ] = m_TempPos; TiXmlElement* UVEl = Vert->FirstChildElement( "uv" ); if( UVEl ) { m_Header.m_HasUVs = true; TiXmlAttribute* UVAttr = UVEl->FirstAttribute(); m_TempUV.x = (float)UVAttr->DoubleValue(); UVAttr = UVAttr->Next(); m_TempUV.y = (float)UVAttr->DoubleValue(); // Blender uses OpenGL-style (bottom-to-top) texture coordinates; // For now, at least, always convert to Direct3D-style. m_TempUV.y = 1.0f - m_TempUV.y; } TiXmlElement* Norm = Vert->FirstChildElement( "norm" ); if( Norm ) { m_Header.m_HasNormals = true; TiXmlAttribute* NormAttr = Norm->FirstAttribute(); m_TempNorm.x = (float)NormAttr->DoubleValue(); NormAttr = NormAttr->Next(); m_TempNorm.y = (float)NormAttr->DoubleValue(); NormAttr = NormAttr->Next(); m_TempNorm.z = (float)NormAttr->DoubleValue(); } int bIdx = 0; for( TiXmlElement* Bone = Vert->FirstChildElement( "bone" ); Bone; Bone = Bone->NextSiblingElement( "bone" ) ) { TiXmlAttribute* BoneAttr = Bone->FirstAttribute(); m_TempBoneIndex.m_Data[ bIdx ] = GetIndexForBone( HashedString( BoneAttr->Value() ) ); BoneAttr = BoneAttr->Next(); m_TempBoneWeight.m_Data[ bIdx ] = static_cast<float>( BoneAttr->DoubleValue() ); ++bIdx; } uint32 Index = GetIndexForTempVertex(); if( Index == 65536 && !m_Header.m_LongIndices ) { PRINTF( "Warning: Exceeded 65536 indices.\n" ); PRINTF( "\tUse -l to compile with long indices.\n" ); } m_Indices.PushBack( Index ); // Cache indices to handle 4-side faces TempIndices[ NumVertsInFace++ ] = Index; } if( NumVertsInFace == 4 ) { m_RawTris.PushBack( Triangle( TempPositions[0], TempPositions[1], TempPositions[2] ) ); m_RawTris.PushBack( Triangle( TempPositions[0], TempPositions[2], TempPositions[3] ) ); } else { m_RawTris.PushBack( Triangle( TempPositions[0], TempPositions[1], TempPositions[2] ) ); } }
SimpleString GetTempFileForPatchFile( const SimpleString& PatchFile ) { return SimpleString::PrintF( "PATCH-%08X", HashedString( PatchFile ) ); }
void Driver::addDependence( const QString & fileName, const Dependence & dep ) { // this can happen if the parser was invoked on a snippet of text and not a file if ( fileName.isEmpty() || !m_currentParsedFile ) return; //@todo prevent cyclic dependency-loops QFileInfo fileInfo( dep.first ); QString fn = fileInfo.absFilePath(); if ( !depresolv ) { findOrInsertDependenceList( fileName ).insert( fn, dep ); m_currentParsedFile->addIncludeFile( dep.first, 0, dep.second == Dep_Local ); return ; } QString file = findIncludeFile( dep ); findOrInsertDependenceList( fileName ).insert( file, dep ); m_currentParsedFile->addIncludeFile( file, 0, dep.second == Dep_Local ); if ( !QFile::exists( file ) ) { Problem p( i18n( "Could not find include file %1" ).arg( dep.first ), lexer ? lexer->currentLine() : -1, lexer ? lexer->currentColumn() : -1, Problem::Level_Warning ); addProblem( fileName, p ); return ; } if( m_currentLexerCache ) m_currentLexerCache->addIncludeFile( file, QDateTime() ); ///The time will be overwritten in CachedLexedFile::merge(...) /**What should be done: * 1. Lex the file to get all the macros etc. * 2. TODO: Check what previously set macros the file was affected by, and compare those macros to any previously parsed instances of this file. * 2.1 If there is a parse-instance of the file where all macros that played a role had the same values, we do not need to reparse this file. * 2.2 If there is no such fitting instance, the file needs to be parsed and put to the code-model. * * It'll be necessary to have multiple versions of one file in the code-model. */ IntIncreaser i( m_dependenceDepth ); if( m_dependenceDepth > m_maxDependenceDepth ) { //kdDebug( 9007 ) << "maximum dependence-depth of " << m_maxDependenceDepth << " was reached, " << fileName << " will not be processed" << endl; return; } CachedLexedFilePointer lexedFileP = m_lexerCache.lexedFile( HashedString( file ) ); if( lexedFileP ) { CachedLexedFile& lexedFile( *lexedFileP ); m_currentLexerCache->merge( lexedFile ); //The ParseHelper will will copy the include-files into the result later for( MacroSet::Macros::const_iterator it = lexedFile.definedMacros().macros().begin(); it != lexedFile.definedMacros().macros().end(); ++it ) { addMacro( (*it) ); } ///@todo fill usingMacro(...) return; } ParseHelper h( file, true, this, false, m_currentMasterFileName ); /*if ( m_parsedUnits.find(file) != m_parsedUnits.end() ) return;*/ if( shouldParseIncludedFile( m_currentParsedFile ) ) ///Until the ParseHelper is destroyed, m_currentParsedFile will stay the included file h.parse(); }
HashedString WBEvent::SParameter::CoerceHash() const { return m_Type == EWBEPT_Hash ? GetHash() : HashedString(); }
HashedString WBEvent::GetHash( const HashedString& Name ) const { TParameterMap::Iterator ParamIter = m_Parameters.Search( Name ); return ParamIter.IsValid() ? ParamIter.GetValue().CoerceHash() : HashedString(); }
#include "pch.h" #include "Events\PointerMovedEvent.h" const HashedString PinnedDownClient::Events::PointerMovedEvent::PointerMovedEventType = HashedString("PointerMoved");
/*virtual*/ void EldritchFramework::Initialize() { XTRACE_FUNCTION; XTRACE_BEGIN(PreFramework3D); ReverseHash::Initialize(); PackStream::StaticAddPackageFile("eldritch-base.cpk"); FrameworkUtil::MinimalLoadConfigFiles("Config/default.ccf"); InitializePackages(); InitializeDLC(); // Load prefs over anything in the defaults. LoadPrefsConfig(); LOADPRINTLEVELS; STATICHASH(Version); STATICHASH(ContentSyncer); SimpleString LocalVersion = ConfigManager::GetString(sVersion, "", sContentSyncer); PRINTF("Version: %s\n", LocalVersion.CStr()); XTRACE_BEGIN(InitializeFactories); PRINTF("Initializing factories...\n"); PRINTF("Initializing SDP factories.\n"); SDPFactory::InitializeBaseFactories(); #define ADDSDPFACTORY(type) \ SDPFactory::RegisterSDPFactory(#type, SDP##type::Factory); #include "eldritchsdps.h" #undef ADDSDPFACTORY PRINTF("Initializing UI factories.\n"); UIFactory::InitializeBaseFactories(); #define ADDUISCREENFACTORY(type) \ UIFactory::RegisterUIScreenFactory(#type, UIScreen##type::Factory); #include "eldritchuiscreens.h" #undef ADDUISCREENFACTORY PRINTF("Initializing anim event factories.\n"); #define ADDANIMEVENTFACTORY(type) \ AnimEventFactory::GetInstance()->Register(#type, AnimEvent##type::Factory); #include "eldritchanimevents.h" #undef ADDANIMEVENTFACTORY PRINTF("Initializing PE factories.\n"); WBParamEvaluatorFactory::InitializeBaseFactories(); #define ADDWBPEFACTORY(type) \ WBParamEvaluatorFactory::RegisterFactory(#type, WBPE##type::Factory); #include "rodinwbpes.h" #include "eldritchwbpes.h" #undef ADDWBPEFACTORY PRINTF("Initializing action factories.\n"); WBActionFactory::InitializeBaseFactories(); #define ADDWBACTIONFACTORY(type) \ WBActionFactory::RegisterFactory(#type, WBAction##type::Factory); #include "uiwbactions.h" #include "rodinwbactions.h" #include "eldritchwbactions.h" #undef ADDWBPEFACTORY PRINTF("Initializing BT factories.\n"); RodinBTNodeFactory::InitializeBaseFactories(); #define ADDRODINBTNODEFACTORY(type) \ RodinBTNodeFactory::RegisterFactory(#type, RodinBTNode##type::Factory); #include "eldritchrodinbtnodes.h" #undef ADDRODINBTNODEFACTORY // Initialize core and Eldritch Workbench component factories. PRINTF("Initializing component factories.\n"); WBComponent::InitializeBaseFactories(); #define ADDWBCOMPONENT(type) \ WBComponent::RegisterWBCompFactory(#type, WBComp##type::Factory); #include "rodinwbcomponents.h" #include "eldritchwbcomponents.h" #undef ADDWBCOMPONENT XTRACE_END; PRINTF("Factories initialized.\n"); // Create input system before framework so it will exist for UI. But don't // attach devices yet, as they don't exist. PRINTF("Initializing input system.\n"); m_InputSystem = new InputSystem; m_InputSystem->Initialize("EldritchInput"); XTRACE_END; Framework3D::Initialize(); STATICHASH(DisplayWidth); STATICHASH(DisplayHeight); m_DisplayWidth = ConfigManager::GetInt(sDisplayWidth); m_DisplayHeight = ConfigManager::GetInt(sDisplayHeight); #if BUILD_WINDOWS m_CheckForUpdates = new CheckForUpdates(m_UIManager); #endif m_Controller = new XInputController; m_TargetManager = new EldritchTargetManager(m_Renderer); m_TargetManager->CreateTargets(m_Display->m_Width, m_Display->m_Height); m_Audio3DListener = new EldritchSound3DListener; m_Audio3DListener->Initialize(); ASSERT(m_AudioSystem); m_AudioSystem->Set3DListener(m_Audio3DListener); STATICHASH(FOV); const float FOV = ConfigManager::GetFloat(sFOV, 90.0f); STATICHASH(ForegroundFOV); const float FGFOV = ConfigManager::GetFloat(sForegroundFOV, 60.0f); STATICHASH(NearClip); const float NearClip = ConfigManager::GetFloat(sNearClip, 0.1f); STATICHASH(FarClip); const float FarClip = ConfigManager::GetFloat(sFarClip, 0.1f); const float fDisplayWidth = static_cast<float>(m_DisplayWidth); const float fDisplayHeight = static_cast<float>(m_DisplayHeight); const float AspectRatio = fDisplayWidth / fDisplayHeight; m_MainView = new View(Vector(), Angles(), FOV, AspectRatio, NearClip, FarClip); m_FGView = new View(Vector(), Angles(), FGFOV, AspectRatio, NearClip, FarClip); CreateHUDView(); CreateMirrorView(); CreateMinimapView(); CreateBuckets(); m_InputSystem->SetKeyboard(m_Keyboard); m_InputSystem->SetMouse(m_Mouse); m_InputSystem->SetController(m_Controller); m_InputSystem->SetClock(m_Clock); WBActionStack::Initialize(); PRINTF("Initializing Eldritch.\n"); InitializeWorld(HashedString(), false); m_Game = new EldritchGame; m_Game->RefreshRTDependentSystems(); m_Game->Initialize(); // Initialize config stuff { STATICHASH(InvertY); const bool InvertY = ConfigManager::GetBool(sInvertY); STATIC_HASHED_STRING(TurnY); m_InputSystem->SetMouseInvert(sTurnY, InvertY); m_InputSystem->SetControllerInvert(sTurnY, InvertY); STATICHASH(ControllerPower); const float ControllerPower = ConfigManager::GetFloat(sControllerPower); STATIC_HASHED_STRING(MoveX); m_InputSystem->SetControllerPower(sMoveX, ControllerPower); STATIC_HASHED_STRING(MoveY); m_InputSystem->SetControllerPower(sMoveY, ControllerPower); STATIC_HASHED_STRING(TurnX); m_InputSystem->SetControllerPower(sTurnX, ControllerPower); m_InputSystem->SetControllerPower(sTurnY, ControllerPower); } // Initialize UI sliders. This could be neater. // This also pushes the initial values to their respective systems, which is // pret-ty terrible design. { WBEventManager* pEventManager = WBWorld::GetInstance()->GetEventManager(); { STATICHASH(MouseSpeed); const float MouseSpeed = ConfigManager::GetFloat(sMouseSpeed, 1.0f); STATIC_HASHED_STRING(ControlsOptionsScreen); STATIC_HASHED_STRING(MouseSpeedSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sControlsOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sMouseSpeedSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromMouseSpeed(MouseSpeed)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(ControllerSpeed); const float ControllerSpeed = ConfigManager::GetFloat(sControllerSpeed, 1.0f); STATIC_HASHED_STRING(ControlsOptionsScreen); STATIC_HASHED_STRING(ControllerSpeedSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sControlsOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sControllerSpeedSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromControllerSpeed(ControllerSpeed)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(Brightness); const float Brightness = ConfigManager::GetFloat(sBrightness, 1.0f); STATIC_HASHED_STRING(BrightnessScreen); STATIC_HASHED_STRING(BrightnessSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sBrightnessScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sBrightnessSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromBrightness(Brightness)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATIC_HASHED_STRING(DisplayOptionsScreen); STATIC_HASHED_STRING(FOVSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sDisplayOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sFOVSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, GetSliderValueFromFOV(FOV)); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(MasterVolume); const float MasterVolume = ConfigManager::GetFloat(sMasterVolume); STATIC_HASHED_STRING(AudioOptionsScreen); STATIC_HASHED_STRING(VolumeSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sAudioOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sVolumeSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, MasterVolume); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } { STATICHASH(MusicVolume); const float MusicVolume = ConfigManager::GetFloat(sMusicVolume); STATIC_HASHED_STRING(AudioOptionsScreen); STATIC_HASHED_STRING(MusicVolumeSlider); WB_MAKE_EVENT(SetUISliderValue, NULL); WB_SET_AUTO(SetUISliderValue, Hash, Screen, sAudioOptionsScreen); WB_SET_AUTO(SetUISliderValue, Hash, Widget, sMusicVolumeSlider); WB_SET_AUTO(SetUISliderValue, Float, SliderValue, MusicVolume); WB_DISPATCH_EVENT(pEventManager, SetUISliderValue, NULL); } } // Initialize UI callbacks { UIScreenEldSetRes* pSetRes = m_UIManager->GetScreen<UIScreenEldSetRes>("SetResScreen"); pSetRes->SetUICallback(SUICallback(EldritchFramework::OnSetRes, nullptr)); UIScreenFade* pFade = m_UIManager->GetScreen<UIScreenFade>("Fade"); pFade->SetFadeCallback( SUICallback(EldritchFramework::OnFadeFinished, nullptr)); } WB_MAKE_EVENT(ResetToInitialScreens, NULL); WB_DISPATCH_EVENT(WBWorld::GetInstance()->GetEventManager(), ResetToInitialScreens, NULL); { // HACK: Too content aware STATIC_HASHED_STRING(MKGLogoScreen); WB_MAKE_EVENT(PushUIScreen, NULL); WB_SET_AUTO(PushUIScreen, Hash, Screen, sMKGLogoScreen); WB_DISPATCH_EVENT(WBWorld::GetInstance()->GetEventManager(), PushUIScreen, NULL); } // Tick world once to pump the event queue. Fixes title screen bugs. m_World->Tick(0.0f); // All done, show the window finally. SafeDelete(m_SplashWindow); #if BUILD_WINDOWS_NO_SDL m_Window->Show(m_CmdShow); #elif BUILD_SDL m_Window->Show(); #endif // Reattach GL context if needed. m_Renderer->Refresh(); PRINTF("Eldritch initialization complete.\n"); }