i4_bool i4_x11_opengl_display_class::initialize_mode(mode * m)
{

	// this sets up the window for us
	if (!input.open_display())
	{
		return i4_F;
	}



	if (!i4_opengl_display_class::initialize_mode(m))
	{
		return i4_F;
	}

	if (visual())
	{
		glx_cx = glXCreateContext(input.display, visual(), NULL, True);
		if (!glx_cx)
		{
			i4_error("WARNING: Could not create glX rendering context");
			//return;
		}
	}
	else
	{
		i4_warning("WARNING: OpenGl renderer is possibly not functional.");
		i4_warning("WARNING: Golgotha will most probably revert to software rendering.");
	}

	glXMakeCurrent(input.display,input.mainwin,glx_cx);

	return i4_T;
}
Exemple #2
0
bool Fluids3DWindow::CreateNestedBoxes()
{
    std::string path = mEnvironment.GetPath("VolumeRender.hlsl");
    std::shared_ptr<VisualProgram> program =
        mProgramFactory.CreateFromFiles(path, path, "");
    if (!program)
    {
        return false;
    }

    mPVWMatrixBuffer = std::make_shared<ConstantBuffer>(
        sizeof(Matrix4x4<float>), true);
    *mPVWMatrixBuffer->Get<Matrix4x4<float>>() = Matrix4x4<float>::Identity();

    mTrilinearClampSampler = std::make_shared<SamplerState>();
    mTrilinearClampSampler->filter = SamplerState::MIN_L_MAG_L_MIP_P;
    mTrilinearClampSampler->mode[0] = SamplerState::CLAMP;
    mTrilinearClampSampler->mode[1] = SamplerState::CLAMP;
    mTrilinearClampSampler->mode[2] = SamplerState::CLAMP;

    program->GetVShader()->Set("PVWMatrix", mPVWMatrixBuffer);
    program->GetPShader()->Set("volumeTexture", mFluid.GetState());
    program->GetPShader()->Set("trilinearClampSampler",
        mTrilinearClampSampler);

    std::shared_ptr<VisualEffect> effect =
        std::make_shared<VisualEffect>(program);

    struct Vertex { Vector3<float> position, tcoord; };
    VertexFormat vformat;
    vformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0);
    vformat.Bind(VA_TEXCOORD, DF_R32G32B32_FLOAT, 0);

    MeshFactory mf;
    mf.SetVertexFormat(vformat);
    int const numBoxes = 128;
    for (int i = 1; i <= numBoxes; ++i)
    {
        float extent = 0.5f*i/(numBoxes - 1.0f);
        std::shared_ptr<Visual> visual(mf.CreateBox(extent, extent, extent));
        VertexBuffer* vbuffer = visual->GetVertexBuffer().get();
        Vertex* vertex = vbuffer->Get<Vertex>();
        for (unsigned int j = 0; j < vbuffer->GetNumElements(); ++j, ++vertex)
        {
            Vector3<float>& tcd = vertex->tcoord;
            Vector3<float> pos = vertex->position;
            Vector4<float> tmp{ pos[0] + 0.5f, pos[1] + 0.5f, pos[2] + 0.5f,
                0.0f };
            for (int k = 0; k < 3; ++k)
            {
                tcd[k] = 0.5f*(tmp[k] + 1.0f);
            }
        }

        visual->SetEffect(effect);
        mVisible.push_back(visual);
    }

    return true;
}
Exemple #3
0
Workspace::Workspace() : mDamage( None ), mWaitForClients( false ), mInitialRepaint( true )
{
    Extensions::initialize();

	XGrabServer( dpy );

	// Redirect all toplevel window contents to offscreen storage
	XCompositeRedirectSubwindows( dpy, rootId(), CompositeRedirectManual );

    initClientList();

	// Request notification about toplevel window state changes
	XSelectInput( dpy, rootId(),
			SubstructureNotifyMask | ExposureMask |
			StructureNotifyMask | PropertyChangeMask );

	XUngrabServer( dpy );

	// Get the picture format for the root window
	mFormat = XRenderFindVisualFormat( dpy, visual() );

	// Create an unclipped picture for drawing on the root window
	XRenderPictureAttributes pa;
	pa.subwindow_mode = IncludeInferiors;
	mFrontbuffer = XRenderCreatePicture( dpy, rootId(), format(), CPSubwindowMode, &pa );

	createBackbuffer();

	XSync( dpy, false );
}
CovarianceProperty::CovarianceVisualPtr CovarianceProperty::createAndPushBackVisual(Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node)
{
  bool use_rotating_frame = ( orientation_frame_property_->getOptionInt() == Local );
  CovarianceVisualPtr visual(new CovarianceVisual(scene_manager, parent_node, use_rotating_frame) );
  updateVisibility(visual);
  updateOrientationFrame(visual);
  updateColorAndAlphaAndScaleAndOffset(visual);
  covariances_.push_back(visual);
  return visual;
}
HsvChannelConfigWidget::HsvChannelConfigWidget(const QModelIndex &index, QWidget *parent)
	: ChannelConfigWidget(index, parent),
	ui(new Ui::HsvChannelConfigWidget),
	m_numpad(new NumpadDialog("Enter Value"))
{
	ui->setupUi(this);
	
	Config deviceConfig;
	deviceConfig.beginGroup(CAMERA_GROUP);
	deviceConfig.setValue(CAMERA_NUM_CHANNELS_KEY, 1);
	deviceConfig.beginGroup((QString(CAMERA_CHANNEL_GROUP_PREFIX) + "0").toStdString());
	deviceConfig.setValue(CAMERA_CHANNEL_TYPE_KEY, CAMERA_CHANNEL_TYPE_HSV_KEY);
	deviceConfig.clearGroup();
	ui->camera->setConfig(&deviceConfig);
	
	visual();
	
	connect(ui->manualButton, SIGNAL(clicked()), SLOT(manual()));
	connect(ui->visualButton, SIGNAL(clicked()), SLOT(visual()));
	
	connect(ui->th, SIGNAL(textChanged(QString)), SLOT(manualEntry(QString)));
	connect(ui->ts, SIGNAL(textChanged(QString)), SLOT(manualEntry(QString)));
	connect(ui->tv, SIGNAL(textChanged(QString)), SLOT(manualEntry(QString)));
	connect(ui->bh, SIGNAL(textChanged(QString)), SLOT(manualEntry(QString)));
	connect(ui->bs, SIGNAL(textChanged(QString)), SLOT(manualEntry(QString)));
	connect(ui->bv, SIGNAL(textChanged(QString)), SLOT(manualEntry(QString)));
	
	connect(ui->visual, SIGNAL(minChanged(QColor)), SLOT(visualChanged()));
	connect(ui->visual, SIGNAL(maxChanged(QColor)), SLOT(visualChanged()));
	
	connect(ui->camera, SIGNAL(pressed(cv::Mat, int, int)), SLOT(imagePressed(cv::Mat, int, int)));
	
	connect(ui->done, SIGNAL(clicked()), SLOT(done()));
	
	ui->th->setInputProvider(m_numpad);
	ui->ts->setInputProvider(m_numpad);
	ui->tv->setInputProvider(m_numpad);
	ui->bh->setInputProvider(m_numpad);
	ui->bs->setInputProvider(m_numpad);
	ui->bv->setInputProvider(m_numpad);
  
  ui->camera->setTrackBlobs(true);
}
Exemple #6
0
void vision_client::eye_pp_s2					()
{
	Device.Statistic->AI_Vis_RayTests.Begin	();

	u32							dwTime = Device.dwTimeGlobal;
	u32							dwDT = dwTime - m_time_stamp;
	m_time_stamp				= dwTime;
	feel_vision_update			(m_object,m_position,float(dwDT)/1000.f,visual().transparency_threshold());

	Device.Statistic->AI_Vis_RayTests.End	();
}
void i4_x11_opengl_display_class::setup_modes()
{
	if (!input.display)
	{
		// should have been opened already
		return;
	}

	XVisualInfo * v = visual();
	if (!v)
	{
		i4_warning("Attempting to guess a video mode.");
		n_modes=2;
		modes=new mode[n_modes];
		modes[0].bits_per_pixel=16;
		modes[1].bits_per_pixel=8;
		modes[0].red_mask=0x7B00;
		modes[0].green_mask=0x3E0;
		modes[0].blue_mask=0x1F;
		modes[1].red_mask=0xE0;
		modes[1].green_mask=0x18;
		modes[1].blue_mask=0x07;
		modes[0].xres=modes[1].xres=640;
		modes[0].yres=modes[1].yres=480;
		sprintf(modes[0].name,"Guessed 16Bit 640x480 mode");
		sprintf(modes[1].name,"Guessed 8Bit 640x480 mode");
		return;
	}

	int cxres[] = {
		640, 800, 1024, 1280
	};
	int cyres[] = {
		480, 600, 768, 1024
	};
	n_modes = sizeof(cxres)/sizeof(int);
	modes = new mode[n_modes];

	for (int i=0; i<n_modes; i++)
	{

		modes[i].bits_per_pixel = v->depth;
		modes[i].red_mask =   v->red_mask;
		modes[i].green_mask = v->green_mask;
		modes[i].blue_mask =  v->blue_mask;

		modes[i].xres = cxres[i];
		modes[i].yres = cyres[i];
		sprintf(modes[i].name, "glX Window: %dx%d, %ud bpp",cxres[i], cyres[i], v->depth);
	}

}
Exemple #8
0
  void add_visual(Surface& surface, const D2D_POINT_2F& offset) {
    plx::ComPtr<IDCompositionVisual2> icv = plx::CreateDCoVisual(dc_device_);
    icv->SetContent(surface.ics_.Get());
    root_->AddVisual(icv.Get(), FALSE, nullptr);

    icv->SetOffsetX(dpi_.to_physical_x(offset.x));
    icv->SetOffsetY(dpi_.to_physical_y(offset.y));
    
    auto rect = D2D1::RectF(offset.x, offset.y,
                            offset.x + surface.size.x, offset.y + surface.size.y);
    Visual visual(icv, rect);
    visual.ics = surface.ics_;
    child_visuals_.push_back(visual);
  }
void send_notification(const std::string & owner, const std::string & message, bool with_history)
{
	DBusConnection *connection = get_dbus_connection();
	if (!connection) return;

	wnotify_by_owner & noticias = notifications.get<by_owner>();

	wnotify_owner_it i = noticias.find(owner);

	if (i != noticias.end()) {
		if (with_history) {
			i->message = message + "\n" + i->message;

			size_t endl_pos = i->message.find('\n');
			size_t ctr = 1;

			while (ctr < MAX_MSG_LINES && endl_pos != std::string::npos) {
				endl_pos = i->message.find('\n', endl_pos+1);
				ctr++;
			}

			i->message = i->message.substr(0,endl_pos);
		} else {
			i->message = message;
		}

		send_dbus_notification(connection, i->id, owner, i->message);
		return;
	} else {
		uint32_t id = send_dbus_notification(connection, 0, owner, message);
		if (!id) return;
		wnotify visual(id,owner,message);
		std::pair<wnotify_owner_it, bool> result = noticias.insert(visual);
		if (!result.second) {
			ERR_DU << "Failed to insert a dbus notification message:\n"
				<< "New Item:\n" << "\tid=" << id << "\n\towner=" << owner << "\n\tmessage=" << message << "\n"
				<< "Old Item:\n" << "\tid=" << result.first->id << "\n\towner=" << result.first->owner << "\n\tmessage=" << result.first->message << "\n";
		}
	}
}
Exemple #10
0
void vision_client::shedule_Update				(u32 dt)
{
	inherited::shedule_Update	(dt);

	if (!object().g_Alive())
		return;

	switch (m_state) {
		case 0 : {
			m_state				= 1;
			eye_pp_s01			();
			break;
		}
		case 1 : {
			m_state				= 0;
			eye_pp_s2			();
			break;
		}
		default					: NODEFAULT;
	}

	visual().update				(float(dt)/1000.f);
}
int main(int argc, char** argv)
{
#ifdef PARALLEL_CORES
  omp_set_num_threads(PARALLEL_CORES);
#endif

  std::string directory = "./";
  if(argc > 1)
    directory = std::string(argv[1]);

  IDXLoader loader(28, 28, 10000, 1, directory);
  OpenANN::DirectStorageDataSet trainSet(&loader.trainingInput,
                                         &loader.trainingInput);

  int H = 196;
  OpenANN::SparseAutoEncoder sae(loader.D, H, 3.0, 0.1, 3e-3, OpenANN::LOGISTIC);
  sae.trainingSet(trainSet);

  OpenANN::LBFGS optimizer(20);
  OpenANN::StoppingCriteria stop;
  stop.maximalIterations = 400;
  optimizer.setOptimizable(sae);
  optimizer.setStopCriteria(stop);
  optimizer.optimize();

  OpenANN::MulticlassEvaluator evaluator(1, OpenANN::Logger::FILE);
  OpenANN::DirectStorageDataSet testSet(&loader.testInput, &loader.testInput,
                                        &evaluator);
  sae.validationSet(testSet);

  QApplication app(argc, argv);
  SparseAutoEncoderVisualization visual(sae, trainSet, H, 5, 7, 800, 600);
  visual.show();
  visual.resize(800, 600);
  return app.exec();
}
Exemple #12
0
/**
 * View Menu
 * Interface Modification
 **/
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
                            MainInterface *mi,
                            bool with_intf )
{
    assert( mi );

    QMenu *menu = new QMenu( qtr( "V&iew" ), mi );

    QAction *act = menu->addAction( QIcon( ":/menu/playlist_menu" ),
            qtr( "Play&list" ), mi,
            SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );

    /*menu->addSeparator();
    menu->addAction( qtr( "Undock from Interface" ), mi,
                     SLOT( undockPlaylist() ), qtr( "Ctrl+U" ) );*/

    menu->addSeparator();

    if( with_intf )
    {
        QMenu *intfmenu = InterfacesMenu( p_intf, menu );
        MenuFunc *f = new MenuFunc( intfmenu, 4 );
        CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
        THEDP->menusUpdateMapper->setMapping( intfmenu, f );
        menu->addSeparator();
    }

    /* Minimal View */
    QAction *action = menu->addAction( qtr( "Mi&nimal View" ) );
    action->setShortcut( qtr( "Ctrl+H" ) );
    action->setCheckable( true );
    action->setChecked( !with_intf &&
            (mi->getControlsVisibilityStatus() & CONTROLS_HIDDEN ) );

    CONNECT( action, triggered( bool ), mi, toggleMinimalView( bool ) );
    CONNECT( mi, minimalViewToggled( bool ), action, setChecked( bool ) );

    /* FullScreen View */
    action = menu->addAction( qtr( "&Fullscreen Interface" ), mi,
            SLOT( toggleFullScreen() ), QString( "F11" ) );
    action->setCheckable( true );
    action->setChecked( mi->isFullScreen() );
    CONNECT( mi, fullscreenInterfaceToggled( bool ),
             action, setChecked( bool ) );

    /* Advanced Controls */
    action = menu->addAction( qtr( "&Advanced Controls" ), mi,
            SLOT( toggleAdvanced() ) );
    action->setCheckable( true );
    if( mi->getControlsVisibilityStatus() & CONTROLS_ADVANCED )
        action->setChecked( true );

    if( with_intf )
    // I don't want to manage consistency between menus, so no popup-menu
    {
        action = menu->addAction( qtr( "Quit after Playback" ) );
        action->setCheckable( true );
        CONNECT( action, triggered( bool ), THEMIM, activatePlayQuit( bool ) );
    }

#if 0 /* For Visualisations. Not yet working */
    adv = menu->addAction( qtr( "Visualizations selector" ),
            mi, SLOT( visual() ) );
    adv->setCheckable( true );
    if( visual_selector_enabled ) adv->setChecked( true );
#endif

    menu->addSeparator();
    addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
        ":/menu/preferences", SLOT( toolbarDialog() ) );
    menu->addSeparator();

    return menu;
}
Exemple #13
0
void vision_client::remove_links				(CObject *object)
{
	visual().remove_links		(object);
}
Exemple #14
0
void vision_client::reload						(LPCSTR section)
{
	visual().reload				(section);
}
Exemple #15
0
void vision_client::reinit						()
{
	visual().reinit				();
}
Exemple #16
0
float vision_client::feel_vision_mtl_transp		(CObject* O, u32 element)
{
	return						(visual().feel_vision_mtl_transp(O,element));
}
Exemple #17
0
int main(int argc, char** argv)
{
  
  ros::init(argc, argv, "coverage");
  int startcycle;
  bool gobackwards=false;
  int backwardsign=1;
  ros::NodeHandle nh;
  M = new moj(nh);
  
//  double map_width=0, map_height=0;
//  if (nh.getParam("/coverage/map_width", map_width))
//  {
//    printf("map width is %f m\n", map_width);
//  }
//  if (nh.getParam("/coverage/map_height", map_height))
//  {
//    printf("map height is %f m\n", map_height);
//  }
//    ROS_ERROR("map width is %f m", map_width);
//    ROS_ERROR("map height is %f m", map_height);

  M->initializePlanner(); 
//  ros::Duration(5).sleep();  //sad ovo ne trebam

  VisualizationPublisher visual(nh);
  VisualizationPublisherCCD visualCCD(nh);
  
  
  CCD = new CCDStar(GM->Map_Dim_X, GM->Map_Dim_Y);
	std::vector<R_point> goals;
	goals.reserve(100); 
  goals.clear();

// Lets just make sure the laser is on the upright position, otherwise we might see the arm as an obstacle!
    ros::Publisher ptu_d46_pub = nh.advertise<trajectory_msgs::JointTrajectory>("/ptu_d46_controller/command", 10);

    trajectory_msgs::JointTrajectory msg;
    msg.header.stamp = ros::Time::now();
    msg.points.resize(1);
    msg.joint_names.push_back("ptu_d46_pan_joint");
    msg.points[0].positions.push_back(0.0);
    msg.points[0].velocities.push_back(0.8);
    msg.points[0].accelerations.push_back(0.8);
    msg.joint_names.push_back("ptu_d46_tilt_joint");
    msg.points[0].positions.push_back(0.5);
    msg.points[0].velocities.push_back(0.8);
    msg.points[0].accelerations.push_back(0.8);
    msg.points[0].time_from_start = ros::Duration(1.0);


    ptu_d46_pub.publish(msg);
    
  MetalDetector md;


  ros::Rate rate(10.0);



  while (nh.ok()) {


    ros::spinOnce(); 
    M->executeMotion();

//drawing in rviz	
    if (gobackwards){
      visual.robot_shape.color.g = 1.0;
    }else{
      visual.robot_shape.color.g = 0.0;
    }  
			visual.visualizationduringmotion();	
			visualCCD.visualizationduringmotion();	
		if(M->voznja)
		{
		}else{
		  printf("waiting for new goal\n");
		}

	  if (M->zavrsio)
		  break;

//calculate coverage path
    if ((M->ciklus>11) ){
    
    int numnewcells=CCD->setCoverageOnRobotCurrentPosition(M->RB.x, M->RB.y, M->RB.th);
    if (M->slam_loop==0) { 
    if (gobackwards==false){
    if (M->voznja==false){ //ne vozi
#if DO_COVERAGE
      CCD->replanko=1;
      int pathflag=CCD->planCoveragePath();//racuna inic put samo jednom, ostalo replanira
      if (CCD->PathLength<=1){
        std::cerr<<"COVERAGE FINISHED!!! PathLength "<<CCD->PathLength<<std::endl;
        M->zavrsio=true;
        CCD->loger();
        continue;
      }
      if (pathflag==2) { 
        std::cerr<<"no path"<<std::endl;
        continue;
      }
      R_point goal=CCD->getGoal();//odredjuje cilj i putanje u realnim koordinatama za logiranje
      CCD->loger();
      bool skipgoal=false;
      for (uint i = 0; i < goals.size();i++){
        if ((fabs(goals[i].x-goal.x)+fabs(goals[i].y-goal.y)+200.*(1-cos(goals[i].th-goal.th))<100.)){ 
          skipgoal=true;
          std::cerr<<"skipping goal ("<<goal.x<<","<<goal.y<<") close to old goal ("<<goals[i].x<<","<<goals[i].y<<")"<<std::endl;
          break;
        }
      }
      if (skipgoal){ 
        CCD->disableCoverageOfArea(goal,350.); //okolina u milimetrima koju ce oznaciti da ne prekriva na mjestu toola i za getgoal da preskoci
      }else{
        goals.push_back(goal);
        M->gotogoal(goal);
      }
#endif
    }else{//vozi
    
      if ((CCD->checkIfStuck(numnewcells,M->setvel.v*M->metric,M->setvel.w))){
        gobackwards=true;
        startcycle=M->ciklus; 
        M->voznja=false;
        backwardsign=1;//da ide u rikverc
      }else{
        gobackwards=false;
      }

#if 0
      int pathflag=CCD->planCoveragePath();//ne replanira nego se samo mice po starom putu
      if (pathflag==2) continue; 
      R_point goal=CCD->getGoal();//odredjuje cilj i putanje u realnim koordinatama za logiranje
      bool skipgoal=false;
      for (uint i = 0; i < goals.size();i++){
        if ((fabs(goals[i].x-goal.x)+fabs(goals[i].y-goal.y)+200.*(1-cos(goals[i].th-goal.th))<100.)){ 
          skipgoal=true;
          std::cerr<<"skipping goal ("<<goal.x<<","<<goal.y<<") close to old goal ("<<goals[i].x<<","<<goals[i].y<<")"<<std::endl;
          break;
        }
      }
      if (skipgoal){ 
        CCD->disableCoverageOfArea(goal,350.); //okolina u milimetrima koju ce oznaciti da ne prekriva na mjestu toola i za getgoal da preskoci
      }else{
        goals.push_back(goal);
        M->gotogoal(goal);
      }
#endif
    }
    
    }else { //gobackwards==true 
      printf("RIKVERC                       RIKVERC                        RIKVERC\n\n\n");
      if (M->ciklus>startcycle+10){
        gobackwards=false;
        backwardsign*=-1; //alternira predznak, ici ce naprijed ako nije uspio nazad
        M->voznja=false; //true;
      }
      geometry_msgs::Twist vel;
		  vel.linear.x = -0.15*backwardsign;
		  vel.angular.z = 0;//0.75;
		  vel.linear.y = 0;
		  M->vel_pub.publish(vel);

    }    
    
    
    
    }
    
    
  }
    
	  rate.sleep();
  }
  return 0;
}
Exemple #18
0
void
news(void)
{
	int     n;
	int     hurt;

	if (ourtime > 30 && position < 32) {
		puts("An explosion of shuddering magnitude splinters bulkheads and");
		puts("ruptures the battlestar's hull.  You are sucked out into the");
		puts("frozen void of space and killed.");
		die(0);
	}
	if (ourtime > 20 && position < 32)
		puts("Explosions rock the battlestar.");
	if (ourtime > snooze) {
		puts("You drop from exhaustion...");
		zzz();
	}
	if (ourtime > snooze - 5)
		puts("You're getting tired.");
	if (ourtime > (rythmn + CYCLE)) {
		if (location == nightfile) {
			convert(TODAY);
			if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
				puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn.");
				puts("You awake from a misty dream-world into stark reality.");
				puts("It is day.");
			}
		} else {
			convert(TONIGHT);
			ClearBit(location[POOLS].objects, BATHGOD);
			if (OUTSIDE && ourtime - rythmn - CYCLE < 10) {
				puts("The dying sun sinks into the ocean, leaving a blood-stained sunset.");
				puts("The sky slowly fades from orange to violet to black.  A few stars");
				puts("flicker on, and it is night.");
				puts("The world seems completely different at night.");
			}
		}
		rythmn = ourtime - ourtime % CYCLE;
	}
	if (!wiz && !tempwiz)
		if ((TestBit(inven, TALISMAN) || TestBit(wear, TALISMAN)) && (TestBit(inven, MEDALION) || TestBit(wear, MEDALION)) && (TestBit(inven, AMULET) || TestBit(wear, AMULET))) {
			tempwiz = 1;
			puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard.");
		}
	if (TestBit(location[position].objects, ELF)) {
		printf("%s\n", objdes[ELF]);
		fight(ELF, rnd(30));
	}
	if (TestBit(location[position].objects, DARK)) {
		printf("%s\n", objdes[DARK]);
		fight(DARK, 100);
	}
	if (TestBit(location[position].objects, WOODSMAN)) {
		printf("%s\n", objdes[WOODSMAN]);
		fight(WOODSMAN, 50);
	}
	switch (position) {

	case 267:
	case 257:		/* entering a cave */
	case 274:
	case 246:
		notes[CANTSEE] = 1;
		break;
	case 160:
	case 216:		/* leaving a cave */
	case 230:
	case 231:
	case 232:
		notes[CANTSEE] = 0;
		break;
	}
	if (TestBit(location[position].objects, GIRL))
		meetgirl = 1;
	if (meetgirl && CYCLE * 1.5 - ourtime < 10) {
		SetBit(location[GARDEN].objects, GIRLTALK);
		SetBit(location[GARDEN].objects, LAMPON);
		SetBit(location[GARDEN].objects, ROPE);
	}
	if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) {
		ClearBit(location[DOCK].objects, GIRL);
		ClearBit(location[DOCK].objects, MAN);
	}
	if (meetgirl && ourtime - CYCLE * 1.5 > 10) {
		ClearBit(location[GARDEN].objects, GIRLTALK);
		ClearBit(location[GARDEN].objects, LAMPON);
		ClearBit(location[GARDEN].objects, ROPE);
		meetgirl = 0;
	}
	if (TestBit(location[position].objects, CYLON)) {
		puts("Oh my God, you're being shot at by an alien spacecraft!");
		printf("The targeting computer says we have %d seconds to attack!\n",
		    ourclock);
		fflush(stdout);
		sleep(1);
		if (!visual()) {
			hurt = rnd(NUMOFINJURIES);
			injuries[hurt] = 1;
			puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll.");
			puts("The viper shudders under a terrible explosion.");
			printf("I'm afraid you have suffered %s.\n", ouch[hurt]);
		} else
			ClearBit(location[position].objects, CYLON);
	}
	if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) {
		puts("I'm afraid you have suffered fatal injuries.");
		die(0);
	}
	for (n = 0; n < NUMOFINJURIES; n++)
		if (injuries[n] == 1) {
			injuries[n] = 2;
			if (WEIGHT > 5)
				WEIGHT -= 5;
			else
				WEIGHT = 0;
		}
	if (injuries[ARM] == 2) {
		if (CUMBER > 5)
			CUMBER -= 5;
		else
			CUMBER = 0;
		injuries[ARM]++;
	}
	if (injuries[RIBS] == 2) {
		if (CUMBER > 2)
			CUMBER -= 2;
		else
			CUMBER = 0;
		injuries[RIBS]++;
	}
	if (injuries[SPINE] == 2) {
		WEIGHT = 0;
		injuries[SPINE]++;
	}
	if (carrying > WEIGHT || encumber > CUMBER)
		notes[CANTMOVE] = 1;
	else
		notes[CANTMOVE] = 0;
}
	virtual i4_bool create_window(w32 xres, w32 yres)
	{
		return input.create_window(0,0,xres,yres,this,i4_F,visual());
	}
Exemple #20
0
/* crontab
 */
main(int argc, char **argv)
{
    int i;
    int opt;
    int edit=0,remove=0,list=0;
    char *user = 0;
    char whoami[20];
    char *what = "update";
    struct passwd *pwd;

    opterr = 1;

#if HAVE_BASENAME
    pgm = basename(argv[0]);
#else
    if (pgm = strrchr(argv[0], '/') )
	++pgm;
    else
	pgm = argv[0];
#endif

    if ( (pwd = getpwuid(getuid())) == 0 )
	fatal("you don't seem to have a password entry?\n");
    strncpy(whoami, pwd->pw_name, sizeof whoami);

    while ( (opt=getopt(argc,argv, "elru:")) != EOF ) {
	switch (opt) {
	case 'e': edit = 1; what = "edit"; break;
	case 'l': list = 1; what = "list"; break;
	case 'r': remove = 1; what = "remove"; break;
	case 'u': user = optarg; break;
	default:  usage();
	}
    }
    if ( edit + list + remove > 1 )
	usage();

    if (user) {
	if ( (pwd = getpwnam(user)) == 0 )
	    fatal("user %s does not have a password entry.\n", user);
    }
    else if ( (pwd = getpwuid(getuid())) == 0 )
	fatal("you don't seem to have a password entry?\n");

    if ( (getuid() != 0) && (pwd->pw_uid != getuid()) )
	fatal("you may not %s %s's crontab.\n", what, pwd->pw_name);

    argc -= optind;
    argv += optind;

    interactive=0;
    info((strcmp(whoami,pwd->pw_name) == 0) ? "(%s) %s" : "(%s) %s (%s)",
				whoami, what, pwd->pw_name);
    if (list) {
	if ( !cat(pwd->pw_name) )
	    fatal("no crontab for %s", pwd->pw_name);
    }
    else if (remove) {
	superpowers();
	xchdir(CRONDIR);
	if (unlink(pwd->pw_name) == -1)
	    fatal("%s: %s", pwd->pw_name, strerror(errno));
    }
    else if (edit)
	visual(pwd);
    else if ( !newcrontab( argc ? argv[0] : "-", pwd->pw_name) )
	exit(1);
    exit(0);
}
Exemple #21
0
BipedManager::BipedManager(std::string const& rootPath,
    std::string const& bname, ProgramFactory& programFactory,
    SkinController::Updater const& postUpdate)
{
    // Vertex format shared by the two skins.
    VertexFormat vformat;
    vformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0);
    vformat.Bind(VA_NORMAL, DF_R32G32B32_FLOAT, 0);
    vformat.Bind(VA_TEXCOORD, DF_R32G32_FLOAT, 0);

    // Create the texture effects for the two skins.
    std::shared_ptr<Texture2> texture[2];
    std::shared_ptr<Texture2Effect> effect[2];
    for (int i = 0; i < 2; ++i)
    {
        std::string name = rootPath + "Skins/Skins" + std::to_string(i) + ".texture.png";
        texture[i].reset(WICFileIO::Load(name, true));
        texture[i]->AutogenerateMipmaps();
        effect[i] = std::make_shared<Texture2Effect>(programFactory,
            texture[i], SamplerState::MIN_L_MAG_L_MIP_L, SamplerState::WRAP,
            SamplerState::WRAP);
    }

    PreSpatialArray preSpatialArray;
    PreSkinArray preSkinArray;
    SpatialMap spatialMap;

    std::string filename = rootPath + bname + ".txt";
    std::ifstream inFile(filename);
    while (!inFile.eof())
    {
        std::string line;
        getline(inFile, line);
        if (line == "")
        {
            // The file contains no blank lines, except for the very last one.
            break;
        }

        // Strip off initial white space.
        std::string::size_type begin = line.find_first_not_of(" ");
        if (begin > 0)
        {
            line = line.substr(begin);
        }

        std::string::size_type end;
        std::string name;
        if (line.find("Node") == 0)
        {
            // Load the node.
            begin = line.find("<");
            end = line.find(">");
            name = line.substr(begin + 1, end - 1 - begin);
            if (name.back() == 'X')
            {
                // TODO: These nodes are not necessary.  Remove them from the
                // data sets.
                continue;
            }

            PreSpatial* preSpatial = LoadNode(rootPath, name);
            preSpatialArray.push_back(preSpatial);
            Node* node = reinterpret_cast<Node*>(preSpatial->Associate);
            spatialMap[name] = node;

            // Load the transform controllers.
            NodeCtrl nc;
            nc.first = node;

            nc.second.reset(LoadTransformController(rootPath, name, "Idle"));
            mIdleArray.push_back(nc);

            nc.second.reset(LoadTransformController(rootPath, name, "Walk"));
            mWalkArray.push_back(nc);

            nc.second.reset(LoadTransformController(rootPath, name, "Run"));
            mRunArray.push_back(nc);
        }
        else if (line.find("TriMesh") == 0)
        {
            // Load the mesh.
            begin = line.find("<");
            end = line.find(">");
            name = line.substr(begin + 1, end - 1 - begin);
            int suffix = name[name.length() - 1] - '0';
            PreSpatial* preSpatial = LoadMesh(rootPath, name, vformat, effect[suffix]);
            preSpatialArray.push_back(preSpatial);
            spatialMap[name] = preSpatial->Associate;

            // Load the skin controller.
            PreSkin* preSkin = LoadSkinController(rootPath, name, postUpdate);
            preSkinArray.push_back(preSkin);

            // Attach the skin controller to the mesh.
            preSpatial->Associate->AttachController(preSkin->Associate);
        }
    }

    // Resolve the bone links.
    for (auto preSkin : preSkinArray)
    {
        SkinController* ctrl = preSkin->Associate;
        Node** bones = ctrl->GetBones();
        int i = 0;
        for (auto const& boneName : preSkin->BoneNames)
        {
            auto iter = spatialMap.find(boneName);
            bones[i] = reinterpret_cast<Node*>(iter->second);
            ++i;
        }
    }

    // Assemble the biped hierarchy.
    for (auto preSpatial : preSpatialArray)
    {
        Node* node = dynamic_cast<Node*>(preSpatial->Associate);
        if (node)
        {
            for (auto const& childName : preSpatial->ChildNames)
            {
                if (childName.back() == 'X')
                {
                    // TODO: These nodes are not necessary.  Remove them from
                    // the data sets.
                    continue;
                }

                auto iter = spatialMap.find(childName);
                Visual* mesh = dynamic_cast<Visual*>(iter->second);
                if (mesh)
                {
                    std::shared_ptr<Visual> visual(mesh);
                    node->AttachChild(visual);
                    if (visual->GetEffect().get() == effect[0].get())
                    {
                        mSubscribers[0].first = visual;
                        mSubscribers[0].second = effect[0]->GetPVWMatrixConstant();
                    }
                    else
                    {
                        mSubscribers[1].first = visual;
                        mSubscribers[1].second = effect[1]->GetPVWMatrixConstant();
                    }
                }
                else
                {
                    node->AttachChild(std::shared_ptr<Spatial>(iter->second));
                }
            }
        }
    }

    mRoot.reset(reinterpret_cast<Node*>(preSpatialArray[0]->Associate));

    for (auto preSpatial : preSpatialArray)
    {
        delete preSpatial;
    }

    for (auto preSkin : preSkinArray)
    {
        delete preSkin;
    }

    // Create the blend controllers.
    int const numControllers = static_cast<int>(mIdleArray.size());
    mIdleWalkArray.resize(numControllers);
    mWalkRunArray.resize(numControllers);
    for (int i = 0; i < numControllers; ++i)
    {
        NodeCtrl const& nc0 = mIdleArray[i];
        NodeCtrl const& nc1 = mWalkArray[i];
        NodeCtrl const& nc2 = mRunArray[i];

        mIdleWalkArray[i].first = nc0.first;
        mIdleWalkArray[i].second = std::make_shared<BlendTransformController>(
            nc0.second, nc1.second, true, false);

        mWalkRunArray[i].first = nc0.first;
        mWalkRunArray[i].second = std::make_shared<BlendTransformController>(
            nc1.second, nc2.second, true, false);
    }
}