Esempio n. 1
0
void SoundManager::initialize()
{
	Ogre::Log* log = GameEngine::getSingleton().getLog();

	log->logMessage("Creating FMOD system", Ogre::LML_NORMAL);
	checkFmodResult(FMOD::System_Create(&fmodSystem));
	
	log->logMessage("Checking FMOD version", Ogre::LML_NORMAL);
	
	unsigned int version;
	checkFmodResult(fmodSystem->getVersion(&version));
	
	if(version < FMOD_VERSION)
	{
		log->logMessage("You are using an old version of FMOD. This program requires FMOD >= 4.08.07.");
		throw std::runtime_error("You are using an old version of FMOD. This program requires FMOD >= 4.08.07.");
	}
	
	log->logMessage("Setting FMOD output type", Ogre::LML_NORMAL);
	
#ifdef WIN32
	checkFmodResult(fmodSystem->setOutput(FMOD_OUTPUTTYPE_DSOUND));
#else
	checkFmodResult(fmodSystem->setOutput(FMOD_OUTPUTTYPE_ALSA));
#endif

	log->logMessage("Initializing FMOD system", Ogre::LML_NORMAL);
	checkFmodResult(fmodSystem->init(32, FMOD_INIT_NORMAL, 0));
}
Esempio n. 2
0
int main(int argc, char **argv)
#endif
{
    int ret = 0;
    Ogre::Log * log = NULL;
    Ogre::Root * root = NULL;
    GameManager* game = NULL;
    Ogre::LogManager * logMgr = NULL;
    bool configCreated = false;
    std::string ogreLogPath, ogreCfgPath;
    
    srand(time(NULL));
    
    using namespace boost::filesystem;
    // Creates the Lost Marbles directory to write to
    path lostMarblesDir(utils::getLostMarblesWriteDir());
    
    try {
        if(! exists(lostMarblesDir))
            create_directories(lostMarblesDir);
    } catch(const filesystem_error& ex) {
        #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBoxA(NULL, ex.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
        #else
        std::cerr << "An exception has occured: " << ex.what() << std::endl;
        #endif
        ret = 1;
        goto gracefulexit;
    }
    

    ogreLogPath = (lostMarblesDir / "Ogre.log").string();
    logMgr = new Ogre::LogManager();
    log = logMgr->createLog(ogreLogPath, true, true, false);
    
    ogreCfgPath = (lostMarblesDir / "Ogre.cfg").string();
    root = new Ogre::Root("Plugins.cfg",ogreCfgPath);

    log->logMessage("Main Lost Marbles write directory " + lostMarblesDir.string());
    log->logMessage("Log Path: " + ogreLogPath);
    log->logMessage("Config Path: " + ogreCfgPath);

    if(!root->restoreConfig()) {
        configCreated = root->showConfigDialog();
        root->saveConfig();
    } else
        configCreated = true;

    if(configCreated) {
        game = new GameManager();

        try {
            // initialize the game and switch to the first state
            game->start(LogoState::getInstance());
        } catch (Ogre::Exception& e) {
            #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
            #else
            std::cerr << "An exception has occured: " << e.getFullDescription() << std::endl;
            #endif
            ret = 1;
            goto gracefulexit;
        } 
    }

gracefulexit:
    if(game) delete game;
    if(root) delete root;
    if(logMgr) delete logMgr;
    return ret;
}
void BouwplaatsGameClient::loadLogin()
{
	Ogre::Log* log = Ogre::LogManager::getSingleton().getDefaultLog();
	log->logMessage("BOUW: Ogre loaded");

	// setup main window; hardcode some defaults for the sake of presentation
	Ogre::NameValuePairList opts;
	opts["resolution"] = "1024x700";
	opts["fullscreen"] = "false";
	opts["vsync"] = "false";

	// create a rendering window with the title "CDK"
	window = ogre->createRenderWindow("Bouwgame Client v0.1", 1024, 700, false, &opts);

	log->logMessage("BOUW: Window Created");

	
	// since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article 
	// we'll see how to change this
	mainSceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
	ModelLibrary::Load(mainSceneMgr);
	
	//secSceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
	//secCamera = secSceneMgr->createCamera("secCamera");
	//secCamera->setNearClipDistance(5);


	mainCamera = mainSceneMgr->createCamera("mainCamera");
	mainCamera->setNearClipDistance(5);
	mainCamera->setFrustumOffset(0.125f);
/*
    The ratio between the x and y dimensions of the rectangular area 
	visible through the frustum is known as aspect ratio: aspect = width / height . 

    The default for most fullscreen windows is 1.3333 - this is also assumed by Ogre 
	unless you use this method to state otherwise. 
*/   
	mainVp = window->addViewport(mainCamera);
	mainVp->setBackgroundColour(Ogre::ColourValue(0.476f,0.550f,0.683f,0.0f));

	mainSceneMgr->setAmbientLight(Ogre::ColourValue(0.8, 0.8, 0.8));
	mainSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

	log->logMessage("BOUW: Scene created");

	soundManager = new OgreAL::SoundManager();

	log->logMessage("BOUW: Sound Manager created");

	node = mainSceneMgr->getRootSceneNode()->createChildSceneNode("CameraNode");
	//node->setPosition(0, 15, 300);
	node = node->createChildSceneNode("PitchNode");
	node->attachObject(mainCamera);
	node->attachObject(soundManager->getListener());
	node->setPosition(0, 15, 300);

	// this next bit is for the sake of the input handler
	
	window->getCustomAttribute("WINDOW", &hWnd);
	
	log->logMessage("BOUW: Nodes created");
	gui = new GuiManager(soundManager);

	dataMan->gui = gui;

	// set up the input handlers
	sim = new Simulation();
	entityController = new EntityController(dataMan, mainSceneMgr, soundManager);
	dataMan->entityController = entityController;
	gameAI = new GameAI(dataMan, entityController);
	entityController->setGameAI(gameAI);
	//handler = new InputHandler(sim, hWnd, mainCamera, entityController, dataMan, mainSceneMgr);
	handler = new InputHandler(sim, hWnd, mainCamera, entityController);
	gui->setSimulation(sim);
	gui->init("", ogre, mainSceneMgr, window, dataMan, handler);
	gui->changeLayout(LOGINLAYOUT);

	//sim->requestStateChange(GUIKEYINPUT);
	// wat entities
	//entityController->createPersonel(3, gameAI, 10, 10);
	//entityController->createOnsite(4, 0, 0);
	//entityController->createOnsite(5, 0, 0);
	//gui->activate("main");
	log->logMessage("BOUW: Stuff set up");

	handler->setWindowExtents(window->getWidth(),window->getHeight());

	Ogre::WindowEventUtilities::addWindowEventListener(window, handler);

	if(node->getName() == "LogoNode")
	{
		node->setPosition(0,0,0);
	}
	else
	{
		ent = mainSceneMgr->createEntity( "LogoEntity", "logo.mesh" );
		node = mainSceneMgr->getRootSceneNode()->createChildSceneNode("LogoNode", Ogre::Vector3(0, 0, 0));
		node->attachObject(ent);
	}
	dataMan->sim = sim;

	try
	{
		sound = soundManager->createSound("LogoSound", "logo.wav", false);
	}
	catch(...)
	{
		log->logMessage("audio file not found");
		sound = 0;
	}

	if(sound)
	{
		sound->play();
	}

	log->logMessage("BOUW: Init done");
}