Ejemplo n.º 1
0
bool Ship::FireMissile(int idx, Ship *target)
{
	assert(target);

	const Equip::Type t = m_equipment.Get(Equip::SLOT_MISSILE, idx);
	if (t == Equip::NONE) {
		return false;
	}

	m_equipment.Set(Equip::SLOT_MISSILE, idx, Equip::NONE);
	CalcStats();

	matrix4x4d m;
	GetRotMatrix(m);
	vector3d dir = m*vector3d(0,0,-1);
	
	ShipType::Type mtype;
	switch (t) {
		case Equip::MISSILE_SMART: mtype = ShipType::MISSILE_SMART; break;
		case Equip::MISSILE_NAVAL: mtype = ShipType::MISSILE_NAVAL; break;
		case Equip::MISSILE_UNGUIDED: mtype = ShipType::MISSILE_UNGUIDED; break;
		default:
		case Equip::MISSILE_GUIDED: mtype = ShipType::MISSILE_GUIDED; break;
	}
	Missile *missile = new Missile(mtype, this, target);
	missile->SetRotMatrix(m);
	missile->SetFrame(GetFrame());
	// XXX DODGY! need to put it in a sensible location
	missile->SetPosition(GetPosition()+50.0*dir);
	missile->SetVelocity(GetVelocity());
	Space::AddBody(missile);
	return true;
}
Ejemplo n.º 2
0
bool usImage::Rotate(double theta, bool mirror)
{
    wxImage *pImg = 0;

    CalcStats();

    CopyToImage(&pImg, Min, Max, 1.0);

    wxImage mirrored = *pImg;

    if (mirror)
    {
        mirrored = pImg->Mirror(false);
    }

    wxImage rotated = mirrored.Rotate(theta, wxPoint(0,0));

    CopyFromImage(rotated);

    delete pImg;

    return false;
}
Ejemplo n.º 3
0
void BudgetWindow::HandleCategorySelection(void)
{
	BRow *row = fCategoryList->CurrentSelection();
	if(!row)
	{
		fAmountBox->SetText("");
		fMonthly->SetValue(B_CONTROL_ON);
		fStatAverageRow->SetField(new BStringField(""),1);
		fStatHighestRow->SetField(new BStringField(""),1);
		fStatLowestRow->SetField(new BStringField(""),1);
	}

	BudgetEntry entry;
	BStringField *strfield = (BStringField*)row->GetField(0);
	if(!gDatabase.GetBudgetEntry(strfield->String(),entry))
		return;

	switch(entry.period)
	{
		case BUDGET_WEEKLY:
		{
			fWeekly->SetValue(B_CONTROL_ON);
			break;
		}
		case BUDGET_QUARTERLY:
		{
			fQuarterly->SetValue(B_CONTROL_ON);
			break;
		}
		case BUDGET_ANNUALLY:
		{
			fAnnually->SetValue(B_CONTROL_ON);
			break;
		}
		default:
		{
			fMonthly->SetValue(B_CONTROL_ON);
			break;
		}
	}

	BString str;
	gDefaultLocale.CurrencyToString(entry.amount.AbsoluteValue(),str);
	str.Truncate(str.FindFirst(gDefaultLocale.CurrencyDecimal()));
	str.RemoveFirst(gDefaultLocale.CurrencySymbol());
	fAmountBox->SetText(str.String());

	Fixed high,low,avg;
	CalcStats(entry.name.String(),high,low,avg);

	gDefaultLocale.CurrencyToString(high.AbsoluteValue(),str);
	str.RemoveFirst(gDefaultLocale.CurrencySymbol());
	fStatHighestRow->SetField(new BStringField(str.String()),1);

	gDefaultLocale.CurrencyToString(low.AbsoluteValue(),str);
	str.RemoveFirst(gDefaultLocale.CurrencySymbol());
	fStatLowestRow->SetField(new BStringField(str.String()),1);

	gDefaultLocale.CurrencyToString(avg.AbsoluteValue(),str);
	str.RemoveFirst(gDefaultLocale.CurrencySymbol());
	fStatAverageRow->SetField(new BStringField(str.String()),1);

	fCatStat->Invalidate();
}
Ejemplo n.º 4
0
/***************************************************************************
 ** ReadSites --
 **    This function asks the user for the name of the data
 ** file to be used, opens it, reads the website Addresses and
 ** sorts them. The totals are then computed and the tables printed using
 ** other functions within this one.
 **      Inputs: None
 **      Outputs: 4 arrays fll of websites and printed results.
 ***************************************************************************/
void ReadSites()
{
   FILE *ifp;
   char filename[SIZE] = "cat";
   char temp[SIZE] = "dog";
   int j = 0;

   /*The  four arrays are declared*/
   WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE];

   int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0;
   int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0;
   int  TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites;
   int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; 
   int *pTotalSearchSites, *pTotalEducationSites;

   /*The pointers are set to point to the their corresponding values*/
   pTotalNonUniqueSites = &TotalNonUniqueSites;
   pTotalUniqueSites = &TotalUniqueSites;
   pTotalTimeLogged = &TotalTimeLogged;
   pTotalFunSites = &TotalFunSites;
   pTotalSearchSites = &TotalSearchSites;
   pTotalEducationSites = &TotalEducationSites;
   pTotalNewsSites = &TotalNewsSites;

   /*The are filled with dummy values*/
   FillArray(comSites);
   FillArray(netSites);
   FillArray(eduSites);
   FillArray(govSites);

   /*Asks the user for the file name*/
   fprintf(stdout, "\nPlease enter the file name: ");
   fscanf(stdin, "%s", filename);
   ifp = fopen(filename, "r");

   /*If the file cannot exit and give error message*/
   if(ifp == NULL)
   {
      fprintf(stderr, "The file could not be opened.");
      exit(-1);
   }

   /*Scans every thing in the file until it reaches the end*/
   while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF)
     {
	/*Breaks the string temp  into access code, domain name*/
	/* and domain ending and stores the in the temporary structure*/
	t.webAddress = CreateAddress(temp);
	
	/*Depending on the first letter of the domain ending, stores*/
	/*them into the appropriate array*/
	if(t.webAddress.domainEnding[0] == 'c')
	{
	   /*Finds the index of wherever the website is supposed to go*/
	   j = IsPresent(comSites, t);
	   
	   /*Stores the website in the proper location*/
	   comSites[j].webAddress = t.webAddress;
	   
	   /*Stores the siteType in the corresponding location*/
	   strcpy(comSites[j].siteType, t.siteType);
	   
	   /*Adds the number of hits and the seconds*/
	   comSites[j].hits += 1;
	   comSites[j].seconds += t.seconds;
	} 
	else if(t.webAddress.domainEnding[0] == 'g')
	{
	   j = IsPresent(govSites, t);
	   
	   govSites[j].webAddress = t.webAddress;
	   strcpy(govSites[j].siteType, t.siteType);
	   govSites[j].hits += 1;
	   govSites[j].seconds += t.seconds;
	}
	else if(t.webAddress.domainEnding[0] == 'n')
	{
	   j = IsPresent(netSites, t);
	   
	   netSites[j].webAddress = t.webAddress;
	   strcpy(netSites[j].siteType, t.siteType);
	   netSites[j].hits += 1;
	   netSites[j].seconds += t.seconds;
	 }
       else
	 {
	   j = IsPresent(eduSites, t);
	   
	   eduSites[j].webAddress = t.webAddress;
	   strcpy(eduSites[j].siteType, t.siteType);
	   eduSites[j].hits += 1;
	   eduSites[j].seconds += t.seconds;
	 } 
     }  
   
   /*Sorts the arrays*/
   SortArray(eduSites, ArrayLength(eduSites));
   SortArray(govSites, ArrayLength(govSites));
   SortArray(comSites, ArrayLength(comSites));
   SortArray(netSites, ArrayLength(netSites));
   
   /*Computes the totals using data from all the arrays*/
   ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, 
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   /*Prints the results of the read*/
   PrintTable(comSites, netSites, eduSites, govSites);
   
   /*Caclulates the percentages and prints them*/
   CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites,
	     TotalNewsSites, TotalEducationSites, TotalTimeLogged,
	     TotalNonUniqueSites);
   
   return;
}
Ejemplo n.º 5
0
void Ship::UpdateMass()
{
	CalcStats();
	SetMass(m_stats.total_mass*1000);
}
Ejemplo n.º 6
0
static void* rt_system_thread(void * arg)
{
	unsigned char slaves_OP=0;
	struct timeval tv;	
	int64_t ts1, ts2;
	SEM * shm_sem;
	SEM * sync_sem;
	RT_TASK *task;
	int i, j;
	M3EcSystemShm * sys = (M3EcSystemShm *)arg;
	printf("Starting real-time thread\n",0);
	RTIME t_last;
	int64_t cntr=0;	
	task = rt_task_init_schmod(nam2num("M3SYSP"), 0, 0, 0, SCHED_FIFO, 0xF);
	rt_allow_nonroot_hrt();
	if (task==NULL)
	{
		printf("Failed to create RT-TASK M3SYSP\n",0);
		return 0;
	}
	shm_sem=(SEM*)rt_get_adr(nam2num(SEMNAM_M3LSHM));
	if (!shm_sem)
	{
		printf("Unable to find the SEMNAM_M3LSHM semaphore.\n",0);
		rt_task_delete(task);
		return 0;
	}
	else
		printf("Allocated shm_sem semaphore  %08x \n",shm_sem);
	
	sync_sem=(SEM*)rt_get_adr(nam2num(SEMNAM_M3SYNC));
	if (!sync_sem)
	{
		printf("Unable to find the SEMNAM_M3SYNC semaphore.\n",0);
		rt_task_delete(task);
		rt_sem_delete(shm_sem);
		return 0;
	}
	else
		printf("Allocated sync_sem semaphore  %08x \n",sync_sem);
	
	RTIME tick_period = nano2count(RT_TIMER_TICKS_NS); 
	RTIME now = rt_get_time();
	rt_task_make_periodic(task, now + tick_period, tick_period); 
	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();
	t_last=now;
	sys_thread_active=1;
	printf("Waiting for Slaves to be in OP state\n");
	
	while((!slaves_OP)&&(!sys_thread_end))
	{
		rt_sem_wait(sync_sem);
		rt_sem_wait(shm_sem);
		slaves_OP=1;
		for(i=0;i<sys->slaves_responding;i++)
		{				
			if((sys->slave[i].al_state!=8)&&(sys->slave[i].active))
			{
				//printf("al_state %d : %d\n",i,sys->slave[i].al_state);
				slaves_OP=0;
			}
		}
		rt_sem_signal(shm_sem);
		rt_task_wait_period();
	}
	
	
	
	uint64_t tl;
	while(!sys_thread_end)
	{
		
		rt_sem_wait(sync_sem);
		rt_sem_wait(shm_sem);	
							
		if(cntr%200==0)		
			PrintStats(sys);
		
		CalcStats(sys);
	
		cntr++;
		rt_sem_signal(shm_sem);
		rt_task_wait_period();
	}	
	printf("Exiting RealTime Thread...\n",0);
	rt_make_soft_real_time();
	rt_task_delete(task);
	sys_thread_active=0;
	return 0;
}
Ejemplo n.º 7
0
static int
ThreadedCalcStats (OList * tests, THREAD_T ** workers,
    test_t ** data, int nConnCount, int *nThreads)
{
  OList *iter;
  int nConn;
  int rc = 1;
  int rc1 = 1;

  for (iter = tests, nConn = 0; iter && nConn < nConnCount;
      nConn++, iter = o_list_next (iter))
    {
      int nOkA = 0, nOkC = 0;
      int nA = 0, nC = 0;
#if defined(PTHREADS)
      unsigned long result;
#elif defined(WIN32)
      unsigned int result;
#endif
      BOOL runStatus = TRUE;
      int i;
      test_t *test = (test_t *) iter->data;
      if (IS_A (*test))
	{
	  test->tpc.a.nTrnCnt = 0;
	  test->tpc.a.nTrnCnt1Sec = 0;
	  test->tpc.a.nTrnCnt2Sec = 0;
	  test->tpc.a.dDiffSum = -1;
	}
      else
	{
	  test->tpc.c.tpcc_sum = 0;
	  test->tpc.c.run_time = 0;
	  test->tpc.c.nRounds = 0;
	  reset_times (test);
	}

      for (i = 0; i < nThreads[nConn]; i++)
	{
	  GET_EXIT_STATUS (workers[nConn][i], &result);

	  if (!result)
	    runStatus = result;

	  switch (data[nConn][i].TestType)
	    {
	    case TPC_A:
	      nA++;
	      if (!test->is_unsupported && result)
		{
		  nOkA++;
		  test->tpc.a.nTrnCnt += data[nConn][i].tpc.a.nTrnCnt;
		  test->tpc.a.nTrnCnt1Sec += data[nConn][i].tpc.a.nTrnCnt1Sec;
		  test->tpc.a.nTrnCnt2Sec += data[nConn][i].tpc.a.nTrnCnt2Sec;
		  if (data[nConn][i].tpc.a.dDiffSum > test->tpc.a.dDiffSum)
		    test->tpc.a.dDiffSum = data[nConn][i].tpc.a.dDiffSum;
		}
	      break;

	    case TPC_C:
	      nC++;
	      if (result)
		{
		  nOkC++;
		  test->tpc.c.tpcc_sum += data[nConn][i].tpc.c.tpcc_sum;
		  test->tpc.c.run_time += data[nConn][i].tpc.c.run_time;
		  test->tpc.c.nRounds += data[nConn][i].tpc.c.nRounds;

		  /* individual transaction timings */
		  ta_merge (&(test->tpc.c.ten_pack_ta),
		      &(data[nConn][i].tpc.c.ten_pack_ta));
		  ta_merge (&(test->tpc.c.new_order_ta),
		      &(data[nConn][i].tpc.c.new_order_ta));
		  ta_merge (&(test->tpc.c.payment_ta),
		      &(data[nConn][i].tpc.c.payment_ta));
		  ta_merge (&(test->tpc.c.delivery_ta),
		      &(data[nConn][i].tpc.c.delivery_ta));
		  ta_merge (&(test->tpc.c.slevel_ta),
		      &(data[nConn][i].tpc.c.slevel_ta));
		  ta_merge (&(test->tpc.c.ostat_ta),
		      &(data[nConn][i].tpc.c.ostat_ta));
		}
	      break;
	    }
	}

      if (nA || nOkC)
	rc1 = do_login (test);

      if (nA)
	{
	  if (nOkA < nA)
	    pane_log
		("\r\n\r\n%s - %s(%s) - %d out of %d TPC-A Threads ended with errors.\r\n",
		test->szName, test->szDBMS, test->szDriverName, nA - nOkA,
		nA);
	  else
	    pane_log
		("\r\n\r\n%s - %s(%s) - all %d TPC-A Threads completed successfully.\r\n",
		test->szName, test->szDBMS, test->szDriverName, nOkA);

	  if (nOkA == 0 && !test->szSQLState[0] && !test->szSQLError[0])
	    {
	      strcpy ((char *) test->szSQLState, "ERROR");
	      strcpy ((char *) test->szSQLError,
		  "All Threads ended prematurely.");
	    }

	  if (test->hdbc)
	    CalcStats (runStatus, nOkA, test, test->tpc.a.nTrnCnt,
		test->tpc.a.nTrnCnt1Sec,
		test->tpc.a.nTrnCnt2Sec, test->tpc.a.dDiffSum);
	}

      if (nOkC)
	{
	  pane_log
	      ("\r\n\r\n%s - %s(%s) - %d/%d TPC-C Threads ended with no errors.\r\n",
	      test->szName, test->szDBMS, test->szDriverName, nOkC, nC);
	  test->tpc.c.run_time /= nOkC;
	  if (test->hdbc)
	    add_tpcc_result (test);
	}

      if ((nA || nOkC) && rc1)
	do_logout (test);

      if (!(nOkA || nOkC))
	{
	  pane_log
	      ("\r\n\r\n%s - %s(%s) - All Threads ended prematurely.\r\n",
	      test->szName, test->szDBMS, test->szDriverName);
	  rc = 0;
	}
    }
  return rc;
}