Ejemplo n.º 1
0
void XYStateVariables::decode(Variables *var, RawVariables *raw)
{
    for (RawVariables::iterator ra = raw->begin(); ra != raw->end(); ++ra) {
        Models models = find<Model*>(ra->modelPath);
		
		int noOfVariables = 0;
        for (Models::iterator mo = models.begin(); mo != models.end(); ++mo) {
			if (ra->stateName == "*") {
				for (Model::States::const_iterator st = (*mo)->states().begin(); st != (*mo)->states().end(); ++st) {
                    Identifier stateId = st.key();
                    Variable  v = {ra->variableName, stateId.key(), *mo, st.value()};
					var->append(v);
					++noOfVariables;
				}
			}
			else {
				const double *statePtr = (*mo)->statePtr(ra->stateName);
				if (statePtr) {
					Variable v = {ra->variableName, ra->stateName, *mo, statePtr};
					var->append(v);
					++noOfVariables;
				}
			}
		}
		if (noOfVariables == 0)
			throw Exception("Could not find variable: " + rawVariableAsText(*ra));
	}
}
Ejemplo n.º 2
0
GameController::GameController()
{
  // TODO: All this static initialization will have to be done through some other
  //       means. This is just for testing purposes.
  Box areaSize(100, 100);
  
  _player = new Character("Trey Cucco", Traits(5, 7, 6, 7, 8, 7, 5), Character::Gender::Male);
  _player->currentPosition(areaSize.center());
  _area = new Area(areaSize, "The Arena!", "The arena is where we test out moving, fighting and NPC AI. We hope to use this as the primary test bed for much of the game engine.");

  _area->npcs().push_back(new Character("Johnny Ringo", Traits(2, 2, 2, 2, 2, 6, 2), Character::Gender::Male));
  _area->npcs().push_back(new Character("Ike Clanton", Traits(3, 3, 3, 3, 3, 6, 3), Character::Gender::Male));
  _area->npcs()[0]->currentPosition(areaSize.center() + Point(areaSize.width() / 10, areaSize.height() / 8));
  _area->npcs()[1]->currentPosition(areaSize.center() + Point(-areaSize.width() / 7, -areaSize.height() / 15));

  double radius = areaSize.width() / 2;
  for (int c = 0; c < areaSize.width(); ++c)
  {
    for (int r = 0; r < areaSize.height(); ++r)
    {
      Point p(c, r);
      if (Components::dist(p, areaSize.center()) > radius)
      {
        _area->location(p).locationType(Models::AreaLocationType::Barrier);
      }
    }
  }
  
  for (auto i = _area->npcs().begin(); i != _area->npcs().end(); ++i)
  {
    _area->location((*i)->currentPosition()).occupyingCharacter(*i);
  }
  _area->location(_player->currentPosition()).occupyingCharacter(_player);
}
void TestSimulationMakerFromFile::testModelsFromFileOneLevel() {
    createSimulation("models_from_file.xml");
    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 2*4+1+1);
    QVERIFY(sim->peekOneDescendant<Model*>("A"));
    QVERIFY(sim->peekOneDescendant<Model*>("D/stat"));
    QCOMPARE(sim->seekOneDescendant<Model*>("A")->pullValue<int>("farmRealId"),
             474840);
    QCOMPARE(sim->seekOneDescendant<Model*>("D")->pullValue<QString>("soilType"),
             QString("Clay"));
    delete sim;
}
void TestSimulationMakerFromFile::testModelInstances() {
    createSimulation("model_instances.xml");
    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 3*(4*4+3)+1);
    QVERIFY(sim->peekOneChild<Model*>("generations(1)"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(2)/egg"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(3)/pupa"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(1)/larva(1)"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(2)/larva(2)/kidney"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(3)/larva(4)/ovary(2)"));

    delete sim;
}
Ejemplo n.º 5
0
void realise(){
	if ( --m_unrealised == 0 ) {
		globalOutputStream() << "searching vfs directory " << makeQuoted( "def" ) << " for *.def\n";
		GlobalFileSystem().forEachFile( "def/", "def", makeCallbackF(EntityClassDoom3_loadFile) );

		{
			for ( Models::iterator i = g_models.begin(); i != g_models.end(); ++i )
			{
				Model_resolveInheritance( ( *i ).first.c_str(), ( *i ).second );
			}
		}
		{
			for ( EntityClasses::iterator i = g_EntityClassDoom3_classes.begin(); i != g_EntityClassDoom3_classes.end(); ++i )
			{
				EntityClass_resolveInheritance( ( *i ).second );
				if ( !string_empty( ( *i ).second->m_modelpath.c_str() ) ) {
					Models::iterator j = g_models.find( ( *i ).second->m_modelpath );
					if ( j != g_models.end() ) {
						( *i ).second->m_modelpath = ( *j ).second.m_mesh;
						( *i ).second->m_skin = ( *j ).second.m_skin;
					}
				}
				eclass_capture_state( ( *i ).second );

				StringOutputStream usage( 256 );

				usage << "-------- NOTES --------\n";

				if ( !string_empty( ( *i ).second->m_comments.c_str() ) ) {
					usage << ( *i ).second->m_comments.c_str() << "\n";
				}

				usage << "\n-------- KEYS --------\n";

				for ( EntityClassAttributes::iterator j = ( *i ).second->m_attributes.begin(); j != ( *i ).second->m_attributes.end(); ++j )
				{
					const char* name = EntityClassAttributePair_getName( *j );
					const char* description = EntityClassAttributePair_getDescription( *j );
					if ( !string_equal( name, description ) ) {
						usage << EntityClassAttributePair_getName( *j ) << " : " << EntityClassAttributePair_getDescription( *j ) << "\n";
					}
				}

				( *i ).second->m_comments = usage.c_str();
			}
		}

		m_observers.realise();
	}
}
void TestSimulationMakerFromFile::testModelsFromCondensedFileParameterKey() {
    createSimulation("models_from_condensed_file_parameter_key.xml");

    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 1+1+4*5);

    Model *crop = sim->seekOneDescendant<Model*>("landscape/C/WBarley");
    QCOMPARE(crop->pullValue<double>("nitrogenNorm"), 130.);

    crop = sim->seekOneDescendant<Model*>("landscape/D/SBarley");
    QCOMPARE(crop->pullValue<double>("nitrogenNorm"), 90.);

    delete sim;
}
Ejemplo n.º 7
0
void GraphGenerator::generateDot()
{
	QFile f(_dotFilePath);
	if (!f.open(QIODevice::Text | QIODevice::WriteOnly))   
		throw UniSim::Exception("Could not open output file to draw graph:\n'" + _dotFilePath + "'");

	_nodeNumber = 0;
    f.write("digraph G {size=\"16,24\";graph[rankdir=LR];\n");

    Models models = seekChildren<Model*>("*", _simulation);
    for (Models::const_iterator mo = models.begin(); mo != models.end(); ++mo) {
		writeModel(&f, _simulation, *mo, 0);
	}
	f.write("\n}\n");
}
void TestSimulationMakerFromFile::testModelsFromFileCondensed() {
    createSimulation("models_from_file_condensed.xml");

    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 1+1+4*5);
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/Oats"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/stat"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/C/stat"));

    Model *crop = sim->peekOneDescendant<Model*>("landscape/B/WBarley");
    QCOMPARE(crop->pullValue<int>("Area"), 40);
    crop = sim->peekOneDescendant<Model*>("landscape/D/SBarley");
    QCOMPARE(crop->pullValue<int>("Area"), 15);

    delete sim;
}
Ejemplo n.º 9
0
void Model_resolveInheritance( const char* name, Model& model ){
	if ( model.m_resolved == false ) {
		model.m_resolved = true;

		if ( !string_empty( model.m_parent.c_str() ) ) {
			Models::iterator i = g_models.find( model.m_parent );
			if ( i == g_models.end() ) {
				globalErrorStream() << "model " << name << " inherits unknown model " << model.m_parent.c_str() << "\n";
			}
			else
			{
				Model_resolveInheritance( ( *i ).first.c_str(), ( *i ).second );
				model.m_mesh = ( *i ).second.m_mesh;
				model.m_skin = ( *i ).second.m_skin;
			}
		}
	}
}
void TestSimulationMakerFromFile::testModelsFromFileTwoLevels() {
    createSimulation("models_from_file_nested.xml");

    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 1+1+4+7+4);
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/Oats"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/stat"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/C/stat"));

    try {
        Model *crop = sim->seekOneDescendant<Model*>("landscape/B/WBarley");
        QCOMPARE(crop->pullValue<int>("Area"), 40);
    }
    catch (Exception &ex) {
        QString msg = "Unexpected exception. " + ex.message();
        QFAIL(qPrintable(msg));
    }

    delete sim;
}
void TestSimulationMakerFromFile::testModelsFromFileThreeLevels()
{
    createSimulation("models_from_file_nested_twice.xml");
    Models all = sim->seekDescendants<Model*>("*");
//        std::cout << "\n";
//        for (int i = 0; i < all.size(); ++i)
//            std::cout << i << " " << qPrintable(all[i]->fullLabel()) << "\n";
//        std::cout << "\n";
    QCOMPARE(all.size(), 1+1+1+4+7+4+16);
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/Oats/Harvest"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/stat"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/C/stat"));

    Model *harvest = sim->peekOneDescendant<Model*>("landscape/A/Oats/Harvest");
    QCOMPARE(harvest->pullValue<QDate>("Date"), QDate(2010,8,15));

    delete sim;
//    std::cout << "\n";
//    for (int i = 0; i < all.size(); ++i)
//        std::cout << i << " " << qPrintable(all[i]->fullLabel()) << "\n";
//    std::cout << "\n";
}
Ejemplo n.º 12
0
int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc, argv);

    // construct the viewer.
    osgViewer::CompositeViewer viewer(arguments);
    
    if (arguments.argc()<=1)
    {
        std::cout<<"Please supply an image filename on the commnand line."<<std::endl;
        return 1;
    }
    
    std::string filename = arguments[1];
    osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
    
    if (!image)
    {
        std::cout<<"Error: unable able to read image from "<<filename<<std::endl;
        return 1;
    }

    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
    if (!wsi) 
    {
        osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
        return 1;
    }


    unsigned int width, height;
    wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
    traits->x = 0;
    traits->y = 0;
    traits->width = width;
    traits->height = height;
    traits->windowDecoration = false;
    traits->doubleBuffer = true;
    
    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
    if (!gc)
    {
        std::cout<<"Error: GraphicsWindow has not been created successfully."<<std::endl;
    }

    gc->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
    gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    osg::ref_ptr<osgGA::TrackballManipulator> trackball = new osgGA::TrackballManipulator;
    
    typedef std::vector< osg::ref_ptr<osg::Node> > Models;
    
    Models models;
    models.push_back(creatQuad("no compression", image.get(), osg::Texture::USE_IMAGE_DATA_FORMAT, osg::Texture::LINEAR));
    models.push_back(creatQuad("ARB compression", image.get(), osg::Texture::USE_ARB_COMPRESSION, osg::Texture::LINEAR));
    models.push_back(creatQuad("DXT1 compression", image.get(), osg::Texture::USE_S3TC_DXT1_COMPRESSION, osg::Texture::LINEAR));
    models.push_back(creatQuad("DXT3 compression", image.get(), osg::Texture::USE_S3TC_DXT3_COMPRESSION, osg::Texture::LINEAR));
    models.push_back(creatQuad("DXT5 compression", image.get(), osg::Texture::USE_S3TC_DXT5_COMPRESSION, osg::Texture::LINEAR));
    
    int numX = 1;
    int numY = 1;

    // compute the number of views up and across that are need
    {
        float aspectRatio = float(width)/float(height);
        float multiplier = sqrtf(float(models.size())/aspectRatio);;
        float multiplier_x = multiplier*aspectRatio;
        float multiplier_y = multiplier;


        if ((multiplier_x/ceilf(multiplier_x)) > (multiplier_y/ceilf(multiplier_y)))
        {
            numX = int(ceilf(multiplier_x));
            numY = int(ceilf(float(models.size())/float(numX)));
        }
        else
        {
            numY = int(ceilf(multiplier_y));
            numX = int(ceilf(float(models.size())/float(numY)));
        }
    }

    // populate the view with the required view to view each model.
    for(unsigned int i=0; i<models.size(); ++i)
    {
        osgViewer::View* view = new osgViewer::View;
        
        int xCell = i % numX;
        int yCell = i / numX;

        int vx = int((float(xCell)/float(numX)) * float(width));
        int vy = int((float(yCell)/float(numY)) * float(height));
        int vw =  int(float(width) / float(numX));
        int vh =  int(float(height) / float(numY));

        view->setSceneData(models[i].get());
        view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(vw) / double(vh), 1.0, 1000.0);
        view->getCamera()->setViewport(new osg::Viewport(vx, vy, vw, vh));    
        view->getCamera()->setGraphicsContext(gc.get());
        view->getCamera()->setClearMask(0);
        view->setCameraManipulator(trackball.get());

        viewer.addView(view);
    }

    return viewer.run();
}
Ejemplo n.º 13
0
/**************************************************************************************
                                    INITIAL SETUP
 **************************************************************************************/
void initial_setup() {
    
    // Random seed
    srand(time(NULL));
    
    // Loading my models and textures
    myModels.loadModels();
    myModels.loadTextures();
    
    // Creating shader program
    texLightProgramID = readAndCompileShader("Shaders/texture_light_vs.txt", "Shaders/texture_light_fs.txt");
    
    // Loading font and creating text labels
    assert(init_text_rendering("Fonts/freemono.png", "Fonts/freemono.meta", width, height));
    score_txtLabel = add_text("Score: 0", -0.2, 0.8, 30.0f, 1.0f, 0.0f, 0.0f, 1.0f);
    speed_txtLabel = add_text("", -0.2, 0.9, 30.0f, 1.0f, 0.0f, 0.0f, 1.0f);
    
    // Setting View and Perspective matrices
    mat4 view_matrix = look_at(vec3(0.0f, 10.0f, -40.0f), vec3(0, 0, 0), vec3(0.0f, 1.0f, 0.0f));
    mat4 persp_matrix = perspective(45.0, (float)width/(float)height, 0.1, 900.0);
    camera.setViewMatrix(&view_matrix);
    camera.setPerspMatrix(&persp_matrix);
    
    // Setting the hero
    hero = Hero(vec3(0.0f, 0.0f, 0.0f), hero_vao, hero_point_count, texLightProgramID, camera.getViewMatrix(), camera.getPerspMatrix());
    hero.setSpeed(game_speed);
    hero.setTextureID(hero_tex, hero_texture_active);
    hero.setRadius(3.0f);
    hero.attachArm(hero_arm_vao, hero_arm_point_count);
    hero.attachArmTex(arm_tex, arm_texture_active);

    // Setting the floor
    game_floor = Object(vec3(0.0f, 0.0f, 0.0f), gameFloor_vao, gameFloor_point_count, texLightProgramID, camera.getViewMatrix(), camera.getPerspMatrix());
    game_floor.setTextureID(gameFloor_tex, gameFloor_texture_active);
    
    // Setting Pine to be collected
    float x = rand()%200 - 100;
    float z = rand()%200 - 100;
    pine = Pine(vec3(x, 0.0f, z), gamePine_vao, gamePine_point_count, texLightProgramID, camera.getViewMatrix(), camera.getPerspMatrix());
    pine.setRadius(4.0f);
    pine.setTextureID(pine_tex, pine_texture_active);
    pine.setBounce(GL_TRUE);
    
    // Creating the queue
    for(int i=0; i<WIN_CONDITION; i++) {
        pines_collected[i] = Pine(vec3(x, 0.0f, z), gamePine_vao, gamePine_point_count, texLightProgramID, camera.getViewMatrix(), camera.getPerspMatrix());
        pines_collected[i].setRadius(4.0f);
        pines_collected[i].setTextureID(pine_tex, pine_texture_active);
    }
    
    // Creating the monster
    for(int i=0; i<NUMBER_OF_MONSTERS; i++) {
        x = rand()%200 - 100;
        z = rand()%200 - 100;
        monster[i] = Pine(vec3(x, -1.0f, z), monster_vao, monster_point_count, texLightProgramID, camera.getViewMatrix(), camera.getPerspMatrix());
        monster[i].setRadius(5.0f);
        monster[i].setTextureID(monster_tex, monster_texture_active);
        monster[i].setSpeed(30.0f);
        monster[i].setTargetToFollow(NULL);
        monster[i].hitted = GL_TRUE;
        monster[i].isPine = GL_FALSE;
    }
    
    // Creating snow
    for(int i=0; i<NUMBER_PARTICLES; i++) {
        float x = rand()%400 - 200;
        float z = rand()%400 - 200;
        snow[i] = Particle(vec3(x, 30.0f, z), particle_vao, particle_point_count, texLightProgramID, camera.getViewMatrix(), camera.getPerspMatrix());
        snow[i].setTextureID(particle_tex, particle_texture_active);
        snow[i].setMaxSpeed(20.0f);
        snow[i].setRespawn(2);
    }
    
    camera.setSpeedRotation(5.0f);
    camera.rotation360();
    camera.initial_rotation = GL_TRUE;
}