Example #1
0
nodachi2D::nodachi2D()
{
    initializePhysics();
    loadLevel();

    intitializeRenderContext();
    initializeThreads();
}
Example #2
0
void Scene::load(void)
{
    //#ifdef GAMEPLAY_EDITION_ND
    // cache default desktop texture
    engine::ITexture* desktopTexture = Gameplay::iGui->getDesktop()->getTexture();
    gui::Rect desktopTextureRect = Gameplay::iGui->getDesktop()->getTextureRect();
    // enumerate slides
    std::vector<std::string> slides;
    WIN32_FIND_DATA findData;
    HANDLE findHandle = FindFirstFile( "./res/slides/*.dds", &findData );
    if( findHandle != INVALID_HANDLE_VALUE )
    {
        slides.push_back( findData.cFileName );
        while( FindNextFile( findHandle, &findData ) ) slides.push_back( findData.cFileName );
        FindClose( findHandle );
    }
    // select slide texture
    engine::ITexture* slideTexture = NULL;
    if( slides.size() )
    {
        unsigned int slideId = getCore()->getRandToolkit()->getUniformInt() % slides.size();
        std::string resourceName = "./res/slides/" + slides[slideId];
        slideTexture = Gameplay::iEngine->createTexture( resourceName.c_str() );
        assert( slideTexture );
    }
    // replace desktop texture
    if( slideTexture )
    {
        Gameplay::iGui->getDesktop()->setTexture( slideTexture );
        Gameplay::iGui->getDesktop()->setTextureRect(
            gui::Rect( 0,0, slideTexture->getWidth(), slideTexture->getHeight() )
        );
    }
    //#endif

    callback::BSPL   bsps;
    callback::ClumpL clumps;
    callback::ClumpI clumpI;
    callback::AtomicL atomicL;
    callback::AtomicI atomicI;

    // insert loading window in Gui
    Gameplay::iGui->getDesktop()->insertPanel( _loadingWindow->getPanel() );
    _loadingWindow->align( gui::atBottom, 4, gui::atCenter, 0 );

    // database record for scene location
    database::LocationInfo* locationInfo = database::LocationInfo::getRecord( _location->getDatabaseId() );

    // load local textures
    if( locationInfo->localTextures )
    {
        const char** resourceName = locationInfo->localTextures;
        while( *resourceName != NULL )
        {
            engine::ITexture* texture = Gameplay::iEngine->createTexture( *resourceName );
            assert( texture );
            texture->addReference();
            texture->setMagFilter( engine::ftLinear );
            texture->setMinFilter( engine::ftLinear );
            texture->setMipFilter( engine::ftLinear );
            _localTextures.push_back( texture );
            resourceName++;
        }
    }


    // retrieve weather options
    database::LocationInfo::Weather* weatherOption = NULL;
    if( locationInfo->weathers )
    {
        database::LocationInfo::Weather* currentOption = locationInfo->weathers;
        while( currentOption->weather != ::wtDatabaseEnding )
        {
            if( currentOption->weather == _location->getWeather() )
            {
                weatherOption = currentOption;
                break;
            }
            currentOption++;
        }
    }

    // retrieve weather option
    if( _locationWeather )
    {
        // load panorama
        _panoramaNearClip = _locationWeather->panorama.zNear;
        _panoramaFarClip  = _locationWeather->panorama.zFar;
        _panoramaAsset    = Gameplay::iEngine->createAsset( engine::atBinary, _locationWeather->panorama.resource );
        assert( _panoramaAsset );
        _panoramaAsset->forAllBSPs( callback::enumerateBSPs, &bsps );
        assert( bsps.size() );
        _panoramaAsset->forAllClumps( callback::enumerateClumps, &clumps );
        _panorama = *( bsps.begin() );

        for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
        {
            _panorama->add( *( clumpI ) );
        }
        bsps.clear();
        clumps.clear();
    }

    //_panorama->forAllClumps( adjustSunLightCCB, &sunMute );
    //_panorama->forAllClumps( adjustAmbientLightCCB, &ambientMute );

    // load stage
    _stageNearClip = locationInfo->stage.zNear;
    _stageFarClip = locationInfo->stage.zFar;
    _stageAsset = Gameplay::iEngine->createAsset( engine::atBinary, locationInfo->stage.resource );
    assert( _stageAsset );
    //_stageAsset = Gameplay::iEngine->createAsset( engine::atBinary, "./res/dropzone/burjdubai.ba" ); assert( _stageAsset );

    _stageAsset->forAllBSPs( callback::enumerateBSPs, &bsps );
    assert( bsps.size() );
    _stageAsset->forAllClumps( callback::enumerateClumps, &clumps );
    _stage = *( bsps.begin() );
    for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
    {
        _stage->add( *( clumpI ) );
    }
    bsps.clear();
    clumps.clear();

    // modify rendering options
    if( weatherOption )
    {
        assert( weatherOption->fogType != engine::fogLinear );
        _stage->setFogType( weatherOption->fogType );
        _stage->setFogDensity( weatherOption->fogDensity );
        _stage->setFogColor( weatherOption->fogColor );
        _stage->forAllClumps( adjustSunLightCCB, &weatherOption->sunMute );
        _stage->forAllClumps( adjustAmbientLightCCB, &weatherOption->ambientMute );
    }

    // load extras
    _extrasAsset = Gameplay::iEngine->createAsset( engine::atBinary, locationInfo->extras.resource );
    assert( _extrasAsset );

    // load local assets
    database::LocationInfo::AssetInfo* assetInfo = locationInfo->localAssets;
    while( assetInfo->name != NULL )
    {
        // load asset
        engine::IAsset* asset = Gameplay::iEngine->createAsset( engine::atXFile, assetInfo->resource );
        assert( asset );
        // rename clumps
        asset->forAllClumps( callback::enumerateClumps, &clumps );
        for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
        {
            (*( clumpI ))->setName( assetInfo->name );
        }
        // preprocess asset
        xpp::preprocessXAsset( asset );
        // insert asset in scene storage
        _localAssets.push_back( asset );
        clumps.clear();
        assetInfo++;
    }

    // initialize afterfx
    _brightPass = locationInfo->afterFx.brightPass;
    _bloom = locationInfo->afterFx.bloom;

    // initialize grass
    TiXmlElement* details = Gameplay::iGameplay->getConfigElement( "details" );
    int grass = 0;
    details->Attribute( "grass", &grass );
    if( grass != 0 )
    {
        _grassTexture = NULL;
        if( locationInfo->grass.scheme != NULL )
        {
            // load grass texture
            _grassTexture = Gameplay::iEngine->getTexture( locationInfo->grass.textureName );
            if( !_grassTexture )
            {
                _grassTexture = Gameplay::iEngine->createTexture( locationInfo->grass.textureResource );
                assert( _grassTexture );
            }
            _grassTexture->addReference();
            _grassTexture->setMagFilter( engine::ftLinear );
            _grassTexture->setMinFilter( engine::ftLinear );
            _grassTexture->setMipFilter( engine::ftLinear );
            _grassTexture->setMipmapLODBias( -2 );

            // locate template atomic
            callback::Locator locator;
            engine::IClump* templateClump = locator.locate( _extrasAsset, locationInfo->grass.templ );
            assert( templateClump );
            templateClump->getFrame()->translate( Vector3f(0,0,0) );
            templateClump->getFrame()->getLTM();
            templateClump->forAllAtomics( callback::enumerateAtomics, &atomicL );
            assert( atomicL.size() == 1 );

            // generate (load) grass
            _grass = Gameplay::iEngine->createGrass(
                         locationInfo->grass.cache,
                         *atomicL.begin(),
                         _grassTexture,
                         locationInfo->grass.scheme,
                         locationInfo->grass.fadeStart,
                         locationInfo->grass.fadeEnd
                     );
            assert( _grass );
            _stage->add( _grass );
        }
    }

    // generate rain settings
    unsigned int numParticles = 0;
    switch( _location->getWeather() )
    {
    case ::wtLightRain:
        numParticles = 1024;
        break;
    case ::wtHardRain:
        numParticles = 2048;
        break;
    case ::wtThunder:
        numParticles = 3072;
        break;
    }

    // initialize rain
    if( numParticles )
    {
        // load rain texture
        _rainTexture = Gameplay::iEngine->createTexture( "./res/particles/rain.dds" );
        assert( _rainTexture );
        _rainTexture->addReference();
        _rainTexture->setMagFilter( engine::ftLinear );
        _rainTexture->setMinFilter( engine::ftLinear );
        _rainTexture->setMipFilter( engine::ftLinear );
        _rainTexture->setMipmapLODBias( -2 );

        // create rain
        _rain = Gameplay::iEngine->createRain( numParticles, 1250.0f, _rainTexture, Vector4f( 1,1,1,1 ) );
        assert( _rain );
        _stage->add( _rain );
    }

    // initialize exit points
    clumps.clear();
    _extrasAsset->forAllClumps( callback::enumerateClumps, &clumps );
    database::LocationInfo::ExitPoint* exitPoint = locationInfo->exitPoints;
    while( exitPoint->nameId != 0 )
    {
        // search for enclosure clump
        bool creationFlag = false;
        for( clumpI = clumps.begin(); clumpI != clumps.end(); clumpI++ )
        {
//			getCore()->logMessage((*clumpI)->getName());
            if( strcmp( (*clumpI)->getName(), exitPoint->extras ) == 0 )
            {
                _enclosures.insert( EnclosureT( exitPoint, new Enclosure( *clumpI, exitPoint->delay ) ) );
                creationFlag = true;
                break;
            }
        }
        assert( creationFlag );
        // next exit point
        exitPoint++;
    }

    // initialize physics
    initializePhysics();

    // casting
    if( locationInfo->castingCallback ) locationInfo->castingCallback( getScenery() );

    // remove loading window from Gui
    Gameplay::iGui->getDesktop()->removePanel( _loadingWindow->getPanel() );

#ifdef GAMEPLAY_EDITION_ND
    // remove slide
    if( slideTexture )
    {
        Gameplay::iGui->getDesktop()->setTexture( desktopTexture );
        Gameplay::iGui->getDesktop()->setTextureRect( desktopTextureRect );
        slideTexture->release();
    }
#endif


    // CLEAN VERSION
    //updateDaytime();
}
void GameCore::startOgre()
{
    reader=new ConfigReader(gameConfigFile);
    if(reader->readFile())
    {
        writer=new ConfigWriter(gameConfigFile);
        writer->importConfigReader(reader);
        reader->pushConfigFile("GameSettings");
        std::string pluginsConfig = reader->getFieldValueAsString("ConfigFiles", "plugins-configfile");
        std::string resourcesConfig = reader->getFieldValueAsString("ConfigFiles", "resources-configfile");
        std::string ogreConfig = reader->getFieldValueAsString("ConfigFiles", "ogre-config");
        std::string ogreLogFile = reader->getFieldValueAsString("LogFiles", "ogre-logfile");
        std::string gameLogFile = reader->getFieldValueAsString("LogFiles", "game-logfile");

        serverTcpPort= reader->getFieldValueAsInteger("NetworkSettings", "tcp-port");
        ttftpPort = reader->getFieldValueAsInteger("NetworkSettings", "ttftp-client-port");
        nickname=reader->getFieldValueAsString("MultiplayerSettings","nickname");
        wallHeight = reader->getFieldValueAsDouble("MapSettings", "wall-height");
        mapPath = reader->getFieldValueAsString("MapSettings", "map-lookup-directory");
        shadowsEnabled = reader->getFieldValueAsBool("GraphicsSettings", "shadows");
        menuBackgroundMusic = reader->getFieldValueAsString("GameSounds", "menu-background");
        gameBackgroundMusic = reader->getFieldValueAsString("GameSounds", "game-background");
        lmgFireSound = reader->getFieldValueAsString("GameSounds", "lmg-fire");
        bgSoundVolume=reader->getFieldValueAsDouble("GameSounds","bg-sound-volume");
        bgSoundVolume=(bgSoundVolume<-1?.1:bgSoundVolume);
		(reader->getFieldValueAsString("MultiplayerSettings","player-color")=="blue"?color=0:color=1);

        maxDecals=reader->getFieldValueAsInteger("GraphicsSettings","max-decals");
        if(maxDecals==-1)
            maxDecals=30;

        sensivity=((reader->getFieldValueAsDouble("MultiplayerSettings","mouse-sensivity")<=0?5:reader->getFieldValueAsDouble("MultiplayerSettings","mouse-sensivity")));


        moveAnimationSpeed = reader->getFieldValueAsDouble("AnimationSpeeds", "move-speed");
        fireAnimationSpeed = reader->getFieldValueAsDouble("AnimationSpeeds", "fire-speed");
        moveSpeed=125;

        buildMap = true;
        singlePlayerMode = reader->getFieldValueAsBool("Debug", "singleplayer");
        if (buildMap)
            mapFileName = reader->getFieldValueAsString("MapSettings", "map-file-name");
        if (mapPath == "NULL")
            mapPath = "Map/";
        else
            mapPath = mapPath.find("/") == std::string::npos ? mapPath.substr(mapPath.find("/")) : mapPath;
		
        gameStarted = teamDM = gameLoaded=false;

        initializeLogger(gameLogFile);
        logger->addLine("game config file " + gameConfigFile + " loaded to memory & logger initialized");
		LogManager* logManager=new LogManager();
		logManager->createLog(ogreLogFile,true,false,false);
        root = OGRE_NEW Root(pluginsConfig,ogreConfig, "");
        ConfigFile configFile;
        configFile.load(resourcesConfig);

        //[start]taken from ogre framework
        Ogre::ConfigFile::SectionIterator seci = configFile.getSectionIterator();
        Ogre::String secName, typeName, archName;
        while (seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
            Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
            Ogre::ConfigFile::SettingsMultiMap::iterator i;
            for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                archName = i->second;
                Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                    archName, typeName, secName);
			}
        }
        //[END]

            logger->addLine("ogre configuration has been read");
        root->showConfigDialog();
        renderWindow=root->initialise(true,"Team-Two");
            logger->addLine("window created");
        sceneManager=root->createSceneManager(ST_EXTERIOR_FAR,"core");
        localPlayer=NULL;
        mapMode=false;



        mainCamera=sceneManager->createCamera("MainCam");
        
        mainCamera->setNearClipDistance(1);mainCamera->setLodBias(2);
        mainCamera->setFarClipDistance(100000000);
        mainCamera->setAspectRatio(renderWindow->getWidth()/(float)renderWindow->getHeight());


        menuSceneManager=root->createSceneManager(ST_GENERIC,"menu");
        menuCamera=menuSceneManager->createCamera("MenuCam");
        menuCamera->setNearClipDistance(1);
        menuMode=true;


        viewPort=renderWindow->addViewport(mainCamera);
        dynamics=NULL;


        if(shadowsEnabled)
            sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
        else
            sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_NONE);

        ResourceGroupManager::getSingletonPtr()->initialiseAllResourceGroups();

		logger->addLine("GameCore: scanning map files");
        lookupMapFiles(mapPath);
		logger->addLine("GameCore: --ok");
		logger->addLine("GameCore: initializing event listeners");
        initializeEventListeners();
		logger->addLine("GameCore: --ok");
		logger->addLine("GameCore: initializing CEGUI");
        initializeCEGUI();
		logger->addLine("GameCore: --ok");
		logger->addLine("GameCore: initializing menu");
        initializeMenu();
		menuController->showLoading();	
		root->renderOneFrame();
#if WINDOWS_PLATFORM
		//Sleep(5000);
#else 
		sleep(5);
#endif
		logger->addLine("GameCore: --ok");	
		logger->addLine("GameCore: initializing ingamemenu");
		initializeInGameGUI();
		logger->addLine("GameCore: --ok");	
		logger->addLine("GameCore: initializing networking");
        initializeNetworking();
		logger->addLine("GameCore: --ok");

        //=================================================DEBUG
        if (singlePlayerMode)
        {
            initializePhysics();
            logger->addLine("Physics initialized");
            initializeScene();
            logger->addLine("Scene initialized");
            if (buildMap)
                initializeMap(mapPath + mapFileName);
            logger->addLine("Map initialized");
            _initializeSinglePlayer();
            initializeItems();
            initializeTeleporters();

        }
             
         //=================================================
		logger->addLine("GameCore: initializing sounds");
        initializeSounds();
		logger->addLine("GameCore: --ok");
		root->addFrameListener(this);
        logger->addLine("GameLoop starting...");
		menuController->hideLoading();
        gameLoop();
    }
    else
        std::cout<<"configuration file not found!...\n";
}