TEST_F(PluginCompatibilityTest, PreBourbaki) {
  // Read the entire hex data.
  std::fstream file = std::fstream(
      SOLUTION_DIR / "ksp_plugin_test" / "pre_bourbaki.proto.hex");
  CHECK(file.good());
  std::string hex;
  while (!file.eof()) {
    std::string line;
    std::getline(file, line);
    for (auto const c : line) {
      if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
        hex.append(1, c);
      }
    }
  }
  file.close();

  // Parse it and convert to binary data.
  UniqueBytes bin(hex.size() / 2);
  HexadecimalDecode(Array<std::uint8_t const>(
                        reinterpret_cast<const std::uint8_t*>(hex.c_str()),
                        hex.size()),
                    bin.get());

  // Construct a protocol buffer from the binary data.
  google::protobuf::io::CodedInputStream coded_input_stream(
      bin.data.get(), static_cast<int>(bin.size));
  serialization::Plugin pre_bourbaki_serialized_plugin;
  CHECK(pre_bourbaki_serialized_plugin.MergeFromCodedStream(
            &coded_input_stream));

  // Construct a plugin from the protocol buffer.
  auto plugin = TestablePlugin::ReadFromMessage(pre_bourbaki_serialized_plugin);

  // Do some operations on the plugin.
  plugin->KeepAllVessels();
  plugin->AdvanceTime(plugin->current_time() + 1 * Second, 2 * Radian);
  plugin->AdvanceTime(plugin->current_time() + 1 * Hour, 3 * Radian);

  // Serialize and deserialize it in the new format.
  serialization::Plugin post_bourbaki_serialized_plugin;
  plugin->WriteToMessage(&post_bourbaki_serialized_plugin);
  plugin = TestablePlugin::ReadFromMessage(post_bourbaki_serialized_plugin);
}
示例#2
0
static void OPL_Mix_Callback(void *udata,
                             Uint8 *byte_buffer,
                             int buffer_bytes)
{
    int16_t *buffer;
    unsigned int buffer_len;
    unsigned int filled = 0;

    // Buffer length in samples (quadrupled, because of 16-bit and stereo)

    buffer = (int16_t *) byte_buffer;
    buffer_len = buffer_bytes / 4;

    // Repeatedly call the OPL emulator update function until the buffer is
    // full.

    while (filled < buffer_len)
    {
        uint64_t next_callback_time;
        uint64_t nsamples;

        SDL_LockMutex(callback_queue_mutex);

        // Work out the time until the next callback waiting in
        // the callback queue must be invoked.  We can then fill the
        // buffer with this many samples.

        if (opl_sdl_paused || OPL_Queue_IsEmpty(callback_queue))
        {
            nsamples = buffer_len - filled;
        }
        else
        {
            next_callback_time = OPL_Queue_Peek(callback_queue) + pause_offset;

            nsamples = (next_callback_time - current_time) * mixing_freq;
            nsamples = (nsamples + OPL_SECOND - 1) / OPL_SECOND;

            if (nsamples > buffer_len - filled)
            {
                nsamples = buffer_len - filled;
            }
        }

        SDL_UnlockMutex(callback_queue_mutex);

        // Add emulator output to buffer.

        FillBuffer(buffer + filled * 2, nsamples);
        filled += nsamples;

        // Invoke callbacks for this point in time.

        AdvanceTime(nsamples);
    }
}
示例#3
0
void Idle(void)
{
	if (!mPause && !mDesign)
	{
		double t;

		if (mUseFixedTimeStep)
			t = mManualTimeStep;
		else
			t = GetTime();
		
		AdvanceTime(t);
	}

	glutPostRedisplay();
}
示例#4
0
// Handle menu commands
void HandleMenuCommand(int option)
{
	switch(option)
	{
		case 'de':
			mDesign = !mDesign;
			
			if (mDesign)
			{
				mPS.StartConstructingSystem();
			}
			else
			{
				mPS.FinishConstructingSystem();
			}
			break;
		
		case 'cs':
			if (!mDesign)
			{
				mDesign = true;
				mPS.StartConstructingSystem();
			}
			mPS.ClearSystem();
			break;
		
		case 'mp':
			mMode = designMode_Particle;
			break;

		case 'mn':
			mMode = designMode_Nail;
			break;

		case 'ms':
			mMode = designMode_Spring;
			break;
		
		case 'd':
			mSurfaceConditionsName = "Default";
			mSurface.SetAmbientColor( 0.0, 0.0, 1.0, 1.0 );
			mSurface.SetDiffuseColor( 0.0, 0.0, 1.0, 1.0 );
			mSurface.SetSpecularColor( 0.5, 0.5, 0.5, 0.5 );
			mSurface.SetShininess( 10.0 );
			mPS.gravity = 9.8;
			mPS.drag = 0.01;
			mPS.SetSpringConstant(5);
			mPS.SetSpringDampingConstant(1);
			mSurface.SetMassProportion(1); // proportional to numer of particles in x
			break;

		case 't':
			mSurfaceConditionsName = "Trampoline";
			mSurface.SetAmbientColor( 0.1, 0.1, 0.3, 1.0 );
			mSurface.SetDiffuseColor( 0.0, 0.0, 0.6, 1.0 );
			mSurface.SetSpecularColor( 0.5, 1.0, 1.0, 1.0 );
			mSurface.SetShininess( 70.0 );
			mPS.gravity = 9.8;
			mPS.drag = 0.001;
			mPS.SetSpringConstant(10);
			mPS.SetSpringDampingConstant(1);
			mSurface.SetMassProportion(0.5); // proportional to numer of particles in x
			break;

		case 'f':
			mSurfaceConditionsName = "Foam";
			mSurface.SetAmbientColor( 1.0, 1.0, 1.0, 1.0 );
			mSurface.SetDiffuseColor( 0.8, 0.8, 1.0, 1.0 );
			mSurface.SetShininess( 10.0 );
			mPS.gravity = 0.5;
			mPS.drag = 1.0;
			mPS.SetSpringConstant(1);
			mPS.SetSpringDampingConstant(1);
			mSurface.SetMassProportion(1); // proportional to numer of particles in x
			break;

		case 'c':
			mSurfaceConditionsName = "Clay";
			mSurface.SetAmbientColor( 0.6, 0.6, 0.4, 1.0 );
			mSurface.SetDiffuseColor( 0.3, 0.3, 0.2, 1.0 );
			mSurface.SetSpecularColor( 0.2, 0.2, 0.2, 1.0 );
			mSurface.SetShininess( 10.0 );
			mPS.gravity = 1.0;
			mPS.drag = 2.0;
			mPS.SetSpringConstant(0.5);
			mPS.SetSpringDampingConstant(1);
			mSurface.SetMassProportion(1); // proportional to numer of particles in x
			break;

		case 'j':
			mSurfaceConditionsName = "Jello";
			mSurface.SetAmbientColor( 1.0, 0.0, 0.0, 1.0 );
			mSurface.SetDiffuseColor( 1.0, 0.0, 0.0, 1.0 );
			mSurface.SetSpecularColor( 1.0, 1.0, 1.0, 1.0 );
			mSurface.SetShininess( 100.0 );
			mPS.gravity = 0;
			mPS.drag = 0.1;
			mPS.SetSpringConstant(10);
			mPS.SetSpringDampingConstant(2);
			mSurface.SetMassProportion(1); // proportional to numer of particles in x
			break;

		case 'w':
			mSurfaceConditionsName = "Waterbed";
			mSurface.SetAmbientColor( 0.4, 1.0, 0.2, 1.0 );
			mSurface.SetDiffuseColor( 0.1, 0.8, 0.5, 1.0 );
			mSurface.SetSpecularColor( 0.6, 0.6, 1.0, 1.0 );
			mSurface.SetShininess( 200.0 );
			mPS.gravity = 2;
			mPS.drag = 0.001;
			mPS.SetSpringConstant(1);
			mPS.SetSpringDampingConstant(1);
			mSurface.SetMassProportion(1); // proportional to numer of particles in x
			break;

		case '1':
			mSurfaceParticles = 3;
			ConstructSurface(mSurfaceParticles);
			break;

		case '2':
			mSurfaceParticles = 5;
			ConstructSurface(mSurfaceParticles);
			break;

		case '3':
			mSurfaceParticles = 10;
			ConstructSurface(mSurfaceParticles);
			break;

		case '4':
			mSurfaceParticles = 15;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case '5':
			mSurfaceParticles = 20;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case '6':
			mSurfaceParticles = 25;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case '7':
			mSurfaceParticles = 30;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case '8':
			mSurfaceParticles = 35;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case '9':
			mSurfaceParticles = 40;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case '0':
			mSurfaceParticles = 50;
			ConstructSurface(mSurfaceParticles);
			break;
		
		case 'n':
			mDrawNormals = !mDrawNormals;
			break;

		case 'i':
			mDrawInfo = (EDrawInfo)(mDrawInfo + 1);
			if (mDrawInfo >= drawInfo_PastEndOfList)
				mDrawInfo = drawInfo_StartOfList;
			break;

		case 's':
			mDrawSurface = !mDrawSurface;
			mPS.useDepthForMouseZ = mDrawSurface;
			break;

		case 'p':
			mDrawSystem = !mDrawSystem;
			break;

		case 'm':
			if (mPause)
				AdvanceTime(mManualTimeStep);
			break;

		case 'x':
			mUseFixedTimeStep = !mUseFixedTimeStep;
			break;
			
		case ' ':
			mPause = !mPause;
			break;

		case 'q':		// quit
			exit(0);
			break;

		default:
			//printf("Invalid menu choice: %c", option);
			break;
	}
}
示例#5
0
int EjectedPilotClass::Exec()
{
   	ACMIGenPositionRecord genPos;
	ACMISwitchRecord acmiSwitch;

	SoundPos.UpdatePos(this);

	if (IsDead())
		return TRUE;
	
		// Call superclass Exec.
		SimMoverClass::Exec();

      if (!SimDriver.MotionOn())
         return IsLocal();

      if (_delayTime > SimLibElapsedTime) { // not time yet
		RunJettisonCanopy(); // stay with it
		return IsLocal();
      }

		// Advance time
		AdvanceTime();

		// Simulate the ejected pilot here.
		switch(_stage)
		{
			case PD_JETTISON_CANOPY :
			{
				RunJettisonCanopy();
				
				break;
			}
			case PD_EJECT_SEAT :
			{
				RunEjectSeat();

				break;
			}
			case PD_FREE_FALL_WITH_SEAT :
			{
				RunFreeFall();

				break;
			}
			case PD_CHUTE_OPENING :
			{
				RunFreeFall();

				// Here we run our little switch based animation...
				static const int NUM_FRAMES = 31;

				float percent = (_runTime             - StageEndTime(_stage-1)) /
					            (StageEndTime(_stage) - StageEndTime(_stage-1));
				int	frame = FloatToInt32(percent * (NUM_FRAMES-0.5f));

				if ( frame < 0 )
					frame = 0;
				else if ( frame > NUM_FRAMES )
					frame = NUM_FRAMES;

				percent = ((_runTime  - _deltaTime )           - StageEndTime(_stage-1)) /
					       (StageEndTime(_stage) - StageEndTime(_stage-1));

				int	prevframe = FloatToInt32(percent * ((float)NUM_FRAMES-0.5f));
				if ( prevframe < 0 )
					prevframe = 0;
				else if ( prevframe > NUM_FRAMES )
					prevframe = NUM_FRAMES;

				if ( gACMIRec.IsRecording() && prevframe != frame)
				{
						acmiSwitch.hdr.time = SimLibElapsedTime * MSEC_TO_SEC + OTWDriver.todOffset;
						acmiSwitch.data.type = Type();
						acmiSwitch.data.uniqueID = ACMIIDTable->Add(Id(),NULL,0);//.num_;
						acmiSwitch.data.switchNum = 0;
						acmiSwitch.data.prevSwitchVal = 1<<prevframe;
						acmiSwitch.data.switchVal = 1<<frame;
						gACMIRec.SwitchRecord( &acmiSwitch );
				}
					
				if ( drawPointer )
					((DrawableBSP*)drawPointer)->SetSwitchMask( 0, 1<<frame );

				break;
			}
			case PD_FREE_FALL_WITH_OPEN_CHUTE :
			{
				RunFreeFallWithOpenChute();
	
				break;
			}
			case PD_FREE_FALL_WITH_COLLAPSED_CHUTE :
			{
				RunFreeFall();
	
				break;
			}
			case PD_SAFE_LANDING :
			{
				RunSafeLanding();

				_stageTimer += _deltaTime;

				static const int NUM_FRAMES = 13;
				float percent = _stageTimer/2.0f;
				int	frame = FloatToInt32(percent * ((float)NUM_FRAMES-0.5f));

				if ( frame < 0 )
					frame = 0;
				else if ( frame > NUM_FRAMES )
					frame = NUM_FRAMES;

				if ( drawPointer )
					((DrawableBSP*)drawPointer)->SetSwitchMask( 0, 1<<frame );
	
				break;
			}
			case PD_CRASH_LANDING :
			{
				RunCrashLanding();

				_stageTimer += _deltaTime;

				static const int NUM_FRAMES = 12;
				float percent = _stageTimer/2.0f;
				int	frame = FloatToInt32(percent * ((float)NUM_FRAMES-0.5f));

				if ( frame < 0 )
					frame = 0;
				else if ( frame > NUM_FRAMES )
					frame = NUM_FRAMES;

				if ( drawPointer )
					((DrawableBSP*)drawPointer)->SetSwitchMask( 0, 1<<frame );
	
				break;
			}
			default :
			{
				ShiWarning ("Bad Eject Mode");
			}
		}

		// Make sure all components of orientation are in range ( 0 <= n <= TWO_PI).
		FixOrientationRange();

		// Update shared data.
		SetPosition(_pos[I_X], _pos[I_Y], _pos[I_Z]);
		SetDelta(_vel[I_X], _vel[I_Y], _vel[I_Z]);
		SetYPR(_rot[I_YAW], _rot[I_PITCH], _rot[I_ROLL]);
		SetYPRDelta(_aVel[I_YAW], _aVel[I_PITCH], _aVel[I_ROLL]);
		if (gACMIRec.IsRecording() && (SimLibFrameCount & 3 ) == 0)
		{
			genPos.hdr.time = SimLibElapsedTime * MSEC_TO_SEC + OTWDriver.todOffset;
			genPos.data.type = Type();
			genPos.data.uniqueID = ACMIIDTable->Add(Id(),NULL,TeamInfo[GetTeam()]->GetColor());//.num_;
			genPos.data.x = XPos();
			genPos.data.y = YPos();
			genPos.data.z = ZPos();
			genPos.data.roll = Roll();
			genPos.data.pitch = Pitch();
			genPos.data.yaw = Yaw();
// remove			genPos.data.teamColor = TeamInfo[GetTeam()]->GetColor();
			gACMIRec.GenPositionRecord( &genPos );
		}

		// Update matrices for geometry.
		CalcTransformMatrix((SimMoverClass *)this);

		// See if it hit the ground.
		if ( _hitGround == FALSE )
			_hitGround = HasHitGround();

		/*
		** We now do completion in the safe or crash landing stages
		** (by calling HitGround() )
		if (HasHitGround())
		{
			HitGround();
		}
		*/

		// Display some debug data.
#if DEBUG_EJECTION_SEQUENCE
		SpewDebugData();
#endif // DEBUG_EJECTION_SEQUENCE

	return IsLocal();
}