Ejemplo n.º 1
0
const Process::Return GameLoadingProcess::update(const float deltaTime)
{
	StateManager& stateManager(StateManager::instance());
	GameState* gameState(stateManager.getState<GameState>("GameState"));
	assert(gameState);
	
	EntitySystem& entitySystem(EntitySystem::instance());
	PlayerShip* playerShip(entitySystem.add<PlayerShip>("Player"));
	playerShip->setGraphicObject(new SDLGraphicObject);
	playerShip->writeGraphicObject<SDLGraphicObject>().load("data/playership.bmp");
	playerShip->setInputObject(new SDLInputObject(playerShip));
	playerShip->writeInputObject<SDLInputObject>().setup();
	playerShip->writePosition() = Vector2D(300.0F, 200.0F);
	playerShip->setMass(3.0F);
	//playerShip->writeVelocity() = Vector2D(100.0F, 300.0F);
	entitySystem.addToList(playerShip, "Renderable");
	entitySystem.addToList(playerShip, "Collidable");
	entitySystem.addToList(playerShip, "Movable");
	entitySystem.addToList(playerShip, "Ship");
	
	Bullet* enemyShip(entitySystem.add<Bullet>("Renderable"));
	enemyShip->setGraphicObject(new SDLGraphicObject);
	enemyShip->writeGraphicObject<SDLGraphicObject>().load("data/enemy.bmp");
	enemyShip->writePosition() = Vector2D(150.0F, 300.0F);
	enemyShip->setMass(3.0F);
	entitySystem.addToList(enemyShip, "Movable");
	//entitySystem.addToList(enemyShip, "Ship");
	
	GrappleHook* grapple(entitySystem.add<GrappleHook>("Renderable"));
	grapple->setGraphicObject(new SDLGraphicObject);
	grapple->writeGraphicObject<SDLGraphicObject>().load("data/hook.bmp");
	grapple->setSource(playerShip);
	grapple->setTarget(enemyShip);
	
	for (Uint segment(0U); segment < 10U; ++segment) {
		HookSegment* hookSegment(entitySystem.add<HookSegment>("Renderable"));
		hookSegment->setGraphicObject(new SDLGraphicObject);
		hookSegment->writeGraphicObject<SDLGraphicObject>().load("data/segment.bmp");
		grapple->addSegment(hookSegment);
	}

	entitySystem.addToList(grapple, "Grapple");
	grapple->setSpeed(100.0F);
	grapple->writePosition() = playerShip->readPosition();
	grapple->fire();
	
	std::vector<Process*> processList;
	processList.push_back(new GameInputProcess);
	processList.push_back(new GamePhysicsProcess);
	processList.push_back(new GameRenderProcess);
	gameState->setProcessor(new Processor(processList));
	
	return Process::STOP;
}
Ejemplo n.º 2
0
const Process::Return GameInputProcess::update(const float deltaTime)
{	
	InputSystem& inputSystem(InputSystem::instance());
	inputSystem.update();
	
	if (inputSystem.hasQuit()) {
		StateManager& stateManager(StateManager::instance());
		stateManager.remove("GameState");
		stateManager.remove("MenuState");
		
		return Process::STOP;
	}
	
	return Process::SUCCESS;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
	// Setup and initialise the Logger
	Logger& logger(Logger::instance());
	//logger.setFile(".html", Logger::LOG_FILE_HTML);
	//logger.setOutput(Logger::LOG_OUTPUT_FILE_AND_TERMINAL);
	logger.setOutput(Logger::LOG_OUTPUT_SILENT);
	//logger.setType(Logger::LOG_TYPE_INFO);
	
	// Check the Config Manager and get it to parse the configuration files.
	ConfigManager& configManager(ConfigManager::instance());
	configManager.loadConfig();
	
	// Start up the Graphics System.
	GraphicsSystem& graphicsSystem(GraphicsSystem::instance());
	graphicsSystem.initialise(640U, 480U, 32U);
	
	// Start and setup the Entity System with some lists.
	EntitySystem& entitySystem(EntitySystem::instance());
	entitySystem.createList("Player");
	entitySystem.createList("Enemy");
	entitySystem.createList("Renderable");
	entitySystem.createList("Movable");
	entitySystem.createList("Collidable");
	entitySystem.createList("Grapple");
	entitySystem.createList("Ship");
	
	// Start up the State Manager, and feed it the Main States.
	StateManager& stateManager(StateManager::instance());
	stateManager.add<MenuState>("MenuState");
	stateManager.add<GameState>("GameState");
	stateManager.launch("GameState");
	
	// Tick over the State Manager while we have any States.
	Timer mainTimer;
	while (true == stateManager.hasStates()) {
		stateManager.update(mainTimer.processDelta());
	}

	// Cleanup
	configManager.saveConfig();
	
	// Goodbye World
	return 0;
}
Ejemplo n.º 4
0
void PoleVaultControl::act() {
	char *stateString;
	stateManager();
	switch (currentState) {
	default:
//	case DEFAULT_STATE:
//		stateString = "Default";
//		defaultControl();
//		break;
	case RETRACT_STATE:
		stateString = "Retract";
		retractControl();
		break;
	case DEPLOY_STATE:
		stateString = "Deploy";
		deployControl();
		break;
	}
	dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, "%8s", stateString);
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{

    // initialize QT
    QApplication app(argc, argv);

    QString globalConfigFile = QDir::homePath () + "/.sfviewer.config";

    // setup debugging
    if( GlobalSettings::isDebug()) {
        Debug::verbocity = 10;
        Debug::displayLevel = true;
        Debug::displaySource = true;
        Debug::setReceiver ( new MyDebugReceiver( "/tmp/fitsviewer.dbg.txt"));
    } else {
        Debug::verbocity = 0;
        Debug::displayLevel = false;
        Debug::displaySource = false;
    }

    dbg(1) << "*******************************************************************\n";
    dbg(1) << "                    FitsViewer starting\n";
    dbg(1) << "*******************************************************************\n";
    dbg(1) << "Ideal thread count (qt): " << QThread::idealThreadCount() << "\n";
    dbg(1) << "Ideal thread count (c++11): " << std::thread::hardware_concurrency() << "\n";
    dbg(1) << "Global thread pool: " << QThreadPool::globalInstance()->maxThreadCount() << "\n";
    {
        int nt = 0;
#pragma omp parallel
        {
#pragma omp critical
            {
                nt ++;
                dbg(1) << "thread " << nt << " reporting\n";
            }
        }
        dbg(1) << "detected " << nt << "OMP threads\n";

    }

    // install QT error handler
    qInstallMsgHandler(myMessageOutput);

    // install GSL error handler
    gsl_set_error_handler( gslErrorHandler);

    try {
        // initialize PureWeb
        CSI::Library::Initialize();
        CSI::Threading::UiDispatcher::InitMessageThread();
        CSI::PureWeb::Server::StateManagerServer server;
        CSI::PureWeb::Server::StateManager stateManager("fitsviewer");
        // add a callback to listen to PureWeb shutdown event
        server.ShutdownRequested() += OnPureWebShutdown;
        // register tickler
        stateManager.PluginManager().RegisterPlugin("QTMessageTickler", new QTMessageTickler());
        // connect
        server.Start(&stateManager);

        // DEBUG
        if(1){
            ScopedDebug dbg__( "Startup paramters:", 1);
            for( auto kv : server.StartupParameters()) {
                std::string key = kv.first.ToAscii().begin();
                std::string val = kv.second.ToAscii().begin();
                dbg(1) << "key/val = " << key << " / " << val << "\n";
            }
        }

        // figure out which file to load
        FitsFileLocation flocToLoad;
        VisualizationStartupParameters vsp;
        {
            // convert PureWeb params to std::map, so that we don't propagate dependencies
            // on PureWeb all across the system
            std::map< QString, QString > myMap;
            for( auto kv : server.StartupParameters())
                myMap[ kv.first.ToAscii().begin() ] = kv.second.ToAscii().begin();
            vsp = determineStartupParameters( myMap);
        }

        // check for errors
        if( vsp.error) {
            dbg(0) << ConsoleColors::error()
                   << "Error: could not figure out startup parameters."
                   << ConsoleColors::resetln()
                   << "  -> " << vsp.errorString << "\n"
                   << "Will try to load the default file\n";
            flocToLoad = FitsFileLocation::fromLocal( GlobalSettings::defaultImage());
        } else {
            dbg(1) << "Startup parameters ===================================\n"
                   << "  title: " << vsp.title << "\n"
                   << "  path:  " << vsp.path << "\n"
                   << "  id:    " << vsp.id << "\n"
                   << "  stamp: " << vsp.stamp << "\n"
                   << "======================================================\n"
                      ;
            flocToLoad = FitsFileLocation::fromElgg( vsp.id, vsp.path, vsp.stamp);
        }

        if( vsp.title.isEmpty()) vsp.title = "N/A";

//        const Collections::Map<CSI::String, CSI::String> & pars =
//                server.StartupParameters();

//        {
//            QString fileId, stamp, path;
//            if( pars.ContainsKey( "fileid"))
//                fileId = pars["fileid"].ToAscii().begin();
//            if( pars.ContainsKey( "timestamp"))
//                stamp = pars["timestamp"].ToAscii().begin();
//            if( pars.ContainsKey( "filepath"))
//                path = pars["filepath"].ToAscii().begin();
//            //            dbg(1) << "fileId = " << fileId << "\n"
//            //                   << "stamp = " << stamp << "\n"
//            //                   << "path = " << path << "\n";
//            if( !( fileId.isEmpty() || stamp.isEmpty() || path.isEmpty())) {
//                flocToLoad = FitsFileLocation::fromElgg( fileId, path, stamp);
//                dbg(1) << "floc2load = " << flocToLoad.toStr() << "\n";
//            }
//        }

        dbg(1) << "will try to load file: " << flocToLoad.toStr() << "\n";
        dbg(1) << " ... i.e: " << flocToLoad.getLocalFname() << "\n";
        dbg(1) << "if that fails, will load: " << GlobalSettings::defaultImage() << "\n";
        dbg(1) << "if that fails too, i'll probably crash :(\n";

        // start up the controller
        FvController fvc ( app.arguments ());
        fvc.setDefaultFileToOpen( FitsFileLocation::fromLocal( GlobalSettings::defaultImage()));
        fvc.start ();
        fvc.setTitle( vsp.title);
        fvc.loadFileAuto( flocToLoad);

        // give up control to Qt event loop
        int ret = app.exec();
        s_stop.Set();
        return ret;
    }
    catch (QString s) {
        fatalError( s);
    } catch (const char * s) {
        fatalError( s);
    } catch (const std::string & s) {
        fatalError(s);
    } catch (const std::runtime_error & err) {
        fatalError ( err.what());
    } catch (const std::exception & err) {
        fatalError ( err.what());
    } catch (...) {
        fatalError( "Unknown exception occured");
    }

    // test
    std::function< void(double) > f;
    class ABC {
    public:
        void operator()(double val) { dbg(1) << "Yay " << val; }
    };
    ABC abc;
    abc(7.1);
    f = abc;
    f(1.7);
}