示例#1
0
errval_t thc_wait_receive_any_x(struct thc_per_binding_state_t *thc,
                                struct thc_receiver_info *rxi) {
  struct thc_receive_cancel_info cinf;
  cancel_item_t ci;
  int canceled = 0;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_wait_receive_any_x\n"));
  // We release the binding lock before blocking.  It is passed back to us
  // by the bottom-half receive function, or by the cancel action.
  cinf.thc = thc;
  cinf.rxi = rxi;
  cinf.was_canceled = 0;
  THCAddCancelItem(&ci, &thc_receive_x_cancel_fn, (void*)&cinf);
  THCSuspendThen(&rxi->waiter, 
                 thc_wait_receive_any0, 
                 (void*)&thc->thc_binding_lock);
  canceled = cinf.was_canceled;
  if (!canceled) {
    // Remove cancel item if it did not run
    if (!THCCancelItemRan(&ci)) {
      THCRemoveCancelItem(&ci);
    }
  }
  if (!canceled) THCIncRecvCount();
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_wait_receive_any\n"));
  return canceled ? THC_CANCELED : SYS_ERR_OK;
}
示例#2
0
void thc_await_send(struct thc_per_binding_state_t *thc,
                    void *f) {
  struct common_binding *c = (struct common_binding *)f;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_await_send\n"));
  // Synchronize with thc_send_possible_event callback
  thc_lock_acquire(&thc->thc_binding_lock);

  // Request an event when sending is possible
  if (!thc->send_possible_event_requested) {
    errval_t err = c->register_send(c, 
                                    get_default_waitset(), 
                                    MKCONT(thc_send_possible_event, c));
    if (err == FLOUNDER_ERR_TX_BUSY) {
      goto done;
    }

    assert(err_is_ok(err));
    thc->send_possible_event_requested = 1;
  }
  
  // Wait
  //
  // We release the binding lock before blocking.  It is passed back to us
  // by the notification

  THCSuspendThen(&thc->waiting_sender, 
                 thc_await_send0, 
                 (void*) &thc->thc_binding_lock);

 done:
  thc_lock_release(&thc->thc_binding_lock);
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_await_send\n"));
}
示例#3
0
void Renderer::SetRenderTarget(int handle, int stage)
{
	if(handle == -1)
	{
		m_bRenderToBackBuffer = true;
		m_nTargetHeight = m_nHeight;
		m_nTargetWidth = m_nWidth;
		m_arrayCurrentRenderTargets[stage] = handle;
		//A call with -1 as handle resets the target stage to the backbuffer's render target.
		m_pD3DDevice->SetRenderTarget((DWORD)stage, m_pOriginalBackBuffer);      
		m_pD3DDevice->SetDepthStencilSurface(m_pOriginalDepthStencil);
		return;
	}
	m_bRenderToBackBuffer = false;
	//Otherwise, assert handle is a valid number.
	size_t numTextures = gTextureManager->getSize();
	if(handle < 0 || handle >= (int)numTextures)
	{
		//Preposterous! Why would you do this!?
		assert(handle < 0 || handle >= (int)numTextures);
		DEBUGPRINTF("Not a valid handle: %d \n", handle);
		return;

	}
	//Now we want a texture element from the texturemanager.
	TextureEntry* renderTarget = gTextureManager->m_listTextureCache[handle];
	//Got it.
	if(renderTarget == NULL)
		return;
	//if there's not a surface, get one.
	if(renderTarget->m_surfaceLocked == NULL)
	{
		//I'm helping!
		renderTarget->m_texture->GetSurfaceLevel(0,&renderTarget->m_surfaceLocked);
	}
	//if we have a depth stencil, set it.
	if(renderTarget->m_bHasDepthStencil)
		m_pD3DDevice->SetDepthStencilSurface(renderTarget->m_surfaceDepthBuffer);
	else
		m_pD3DDevice->SetDepthStencilSurface(m_pOriginalDepthStencil);

	//Now, since we've got error checking out of the way, set the render target to the texture.

	HRESULT hr = m_pD3DDevice->SetRenderTarget(stage, renderTarget->m_surfaceLocked);
	if(SUCCEEDED(hr))
	{
		//we're fine.
		m_nTargetHeight = renderTarget->m_ySize;
		m_nTargetWidth = renderTarget->m_xSize;
		m_arrayCurrentRenderTargets[stage] = handle;
		return;
	}
	else
	{
		assert(SUCCEEDED(hr));
		
		DEBUGPRINTF("Failed to set texture: %s as a render target.\n", renderTarget->m_strName.c_str());
		return;
	}
}
示例#4
0
errval_t thc_receive_x(struct thc_per_binding_state_t *thc,
                       struct thc_per_recv_t *recv,
                       struct thc_receiver_info *rxi) 
{
  struct thc_receive_cancel_info cinf;
  cancel_item_t ci;
  int canceled = 0;

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_receive_x\n"));

  thc_lock_acquire(&thc->thc_binding_lock);

  // Return THC_CANCELED if already requested
  if (THCIsCancelRequested()) {
    canceled = 1;
    goto done;
  }

  assert(recv->r == NULL && "thc_receiver found existing receiver");

  // Install us as the receiver for this message
  rxi->next = NULL;
  rxi->demux = NO_DEMUX;
  recv->r = rxi;

  // Wake any bottom-half functions that are present
  if (recv->num_bh > 0) {
    thc_condvar_broadcast(&recv->cv_bh);
  }

  // Wait until a bottom-half provides a message
  //
  // We release the binding lock before blocking.  It is passed back to us
  // by the bottom-half receive function or the cancelation function.
  cinf.thc = thc;
  cinf.rxi = rxi;
  cinf.was_canceled = 0;
  THCAddCancelItem(&ci, &thc_receive_x_cancel_fn, (void*)&cinf);
  THCSuspendThen(&rxi->waiter, thc_receive0, (void*) &thc->thc_binding_lock);
  canceled = cinf.was_canceled;
  if (!canceled) {
    // Remove cancel item if it did not run
    if (!THCCancelItemRan(&ci)) {
      THCRemoveCancelItem(&ci);
    }
  }

  // Remove us as the receiver
  assert(recv->r == rxi);  
  recv->r = NULL;
  
 done:
  thc_lock_release(&thc->thc_binding_lock);

  if (!canceled) THCIncRecvCount();

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_receive_x\n"));
  return canceled ? THC_CANCELED : SYS_ERR_OK;
}
示例#5
0
errval_t thc_receive_demux_x(struct thc_per_binding_state_t *thc,
                             struct thc_per_recv_t *recv,
                             struct thc_receiver_info *rxi) {
  struct thc_receiver_info **rxip;
  struct thc_receive_cancel_info cinf;
  cancel_item_t ci;
  int canceled = 0;

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_receive_demux_x\n"));
  thc_lock_acquire(&thc->thc_binding_lock);

  // Return THC_CANCELED if already requested
  if (THCIsCancelRequested()) {
    canceled = 1;
    goto done;
  }

  // Wake any bottom-half functions that are present
  if (recv->num_bh > 0) {
    thc_condvar_broadcast(&recv->cv_bh);
  }

  // Wait until a bottom-half provides a message
  //
  // We release the binding lock before blocking.  It is passed back to us
  // by the bottom-half receive function.
  cinf.thc = thc;
  cinf.rxi = rxi;
  cinf.was_canceled = 0;
  THCAddCancelItem(&ci, &thc_receive_x_cancel_fn, (void*)&cinf);
  THCSuspendThen(&rxi->waiter, thc_receive0, (void*) &thc->thc_binding_lock);
  canceled = cinf.was_canceled;
  if (!canceled) {
    // Remove cancel item if it did not run
    if (!THCCancelItemRan(&ci)) {
      THCRemoveCancelItem(&ci);
    }
  }

 done:
  // Remove us from the list of receivers
  rxip = (struct thc_receiver_info **) &(recv->r);
  bool found = false;
  while (*rxip != NULL) {
    if (*rxip == rxi) {
      *rxip = rxi -> next;
      found = true;
      break;
    }
    rxip = &((*rxip)->next);
  }
  assert(found);

  thc_lock_release(&thc->thc_binding_lock);

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_receive_demux_x\n"));
  return canceled ? THC_CANCELED : SYS_ERR_OK;
}
示例#6
0
void thc_stop_receiving(struct thc_per_binding_state_t *thc,

                        struct thc_per_recv_t *recv,
                        struct thc_receiver_info *rxi) {
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_stop_receiving\n"));
  assert(recv->r == rxi);
  assert(rxi->next == NULL);
  recv->r = NULL;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_stop_receiving\n"));
}
示例#7
0
errval_t thc_await_send_x(struct thc_per_binding_state_t *thc,
                          void *f) {
  struct thc_await_send_cancel_info cinf;
  cancel_item_t ci;
  int canceled = 0;
  struct common_binding *c = (struct common_binding *)f;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_await_send_x\n"));

  // Synchronize with thc_send_possible_event callback
  thc_lock_acquire(&thc->thc_binding_lock);

  // Return THC_CANCELED if already requested
  if (THCIsCancelRequested()) {
    canceled = 1;
    goto done;
  }

  // Request an event when sending is possible
  if (!thc->send_possible_event_requested) {
    errval_t err = c->register_send(c, 
                                    get_default_waitset(), 
                                    MKCONT(thc_send_possible_event, c));
    if (err == FLOUNDER_ERR_TX_BUSY) {
      goto done;
    }

    assert(err_is_ok(err));
    thc->send_possible_event_requested = 1;
  }
  
  // Wait
  //
  // We release the binding lock before blocking.  It is passed back to us
  // by the notification
  
  cinf.thc = thc;
  cinf.was_canceled = 0;
  THCAddCancelItem(&ci, &thc_await_send_x_cancel_fn, (void*)&cinf);
  THCSuspendThen(&thc->waiting_sender, 
                 thc_await_send0, 
                 (void*) &thc->thc_binding_lock);
  canceled = cinf.was_canceled;
  if (!canceled) {
    // Remove cancel item if it did not run
    if (!THCCancelItemRan(&ci)) {
      THCRemoveCancelItem(&ci);
    }
  }

 done:
  thc_lock_release(&thc->thc_binding_lock);

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_await_send\n"));
  return canceled ? THC_CANCELED : SYS_ERR_OK;
}
示例#8
0
void thc_wait_receive_any(struct thc_per_binding_state_t *thc,
                          struct thc_receiver_info *rxi) {
  // We release the binding lock before blocking.  It is passed back to us
  // by the bottom-half receive function.
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_wait_receive_any\n"));
  THCSuspendThen(&rxi->waiter, 
                 thc_wait_receive_any0, 
                 (void*)&thc->thc_binding_lock);
  THCIncRecvCount();
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_wait_receive_any\n"));
}
示例#9
0
// Cause the next "n" messages to be discarded on receipt
void thc_discard(struct thc_per_binding_state_t *thc,
                 struct thc_per_recv_t *recv,
                 uint64_t n) 
{
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_discard\n"));
  thc_lock_acquire(&thc->thc_binding_lock);
  recv->num_discard += n;
  if (recv->num_bh > 0) {
    thc_condvar_broadcast(&recv->cv_bh);
  }
  thc_lock_release(&thc->thc_binding_lock);
    DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_discard\n"));
}
示例#10
0
void thc_start_receive_demux(struct thc_per_binding_state_t *thc,
                             struct thc_per_recv_t *recv,
                             struct thc_receiver_info *rxi) {
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_start_receive_demux\n"));
  thc_lock_acquire(&thc->thc_binding_lock);

  // Install us on the list of receivers
  assert(rxi->demux != NO_DEMUX);
  assert(rxi->waiter == NULL);
  rxi->next = recv->r;
  recv->r = rxi;

  thc_lock_release(&thc->thc_binding_lock);
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_start_recieve_demux\n"));
}
示例#11
0
void bloodExpiration()
{

    /*
	1) Exhaust the batches of various items scheduled to be expired
	on the day.
	2) Update wastages if any.
	*/
    int bloodGroup = transfer[BLOODGROUP];
    int item = transfer[ITEM];
    int n;


    float expiredStockBatch = Stock[oldestBadge[item][bloodGroup]][item][bloodGroup];
	if (expiredStockBatch > 0.0f)
        DEBUGPRINTF("Threw away expired %.4f units of %s of blood group %s\n", expiredStockBatch, bloodItemTypes[item], bloodGroupTypes[bloodGroup]);
    waste[item][bloodGroup] += expiredStockBatch;
    oldestBadge[item][bloodGroup] ++; //new oldest badge
    N[item][bloodGroup] --; // Decrement total number of badges for item i and bloodgroup g
    if (oldestBadge[item][bloodGroup] + N[item][bloodGroup] >= MAXNBATCH)
    {
        relocateBadges(item, bloodGroup);
    }

}
示例#12
0
void Clock::Initialize()
{
	DEBUGPRINTF( "Initializing Clock\n" );

	ShutDown();

#if BUILD_WINDOWS_NO_SDL
	LARGE_INTEGER Frequency;
	LARGE_INTEGER Counter;

	QueryPerformanceFrequency( &Frequency );
	QueryPerformanceCounter( &Counter );

	m_Resolution			= 1.0 / (double)Frequency.QuadPart;
	m_PhysicalBaseTime		= Counter.QuadPart;
#endif

#if BUILD_SDL
	Uint64 Frequency	= SDL_GetPerformanceFrequency();
	Uint64 Counter		= SDL_GetPerformanceCounter();

	m_Resolution			= 1.0 / static_cast<double>( Frequency );
	m_PhysicalBaseTime		= Counter;
#endif

	m_PhysicalDeltaTime		= 0;
	m_MachineDeltaTime		= 0.0f;
	m_GameDeltaTime			= 0.0f;

	m_PhysicalCurrentTime	= 0;
	m_MachineCurrentTime	= 0.0f;
	m_GameCurrentTime		= 0.0f;

	m_TickCount				= 0;
}
示例#13
0
void thc_start_receiving(struct thc_per_binding_state_t *thc,
                         struct thc_per_recv_t *recv,
                         struct thc_receiver_info *rxi) {
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_start_receiving\n"));
  // Install ourselves to receive the message
  assert(recv->r == NULL && 
         "receive_any attempted for message with pending receive");
  recv->r = rxi;
  rxi->next = NULL;
  rxi->demux = NO_DEMUX;

  // Wake any bottom-half functions present for this message
  if (recv->num_bh > 0) {
    thc_condvar_signal(&recv->cv_bh);
  }
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_start_receiving\n"));
}
示例#14
0
void thc_complete_send_cb(void *f) {
  struct common_binding *c = (struct common_binding *)f;
  struct thc_per_binding_state_t *thc;
  thc = (struct thc_per_binding_state_t *)(c->st);
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_complete_send_cb\n"));

  thc_lock_acquire(&thc->thc_binding_lock);

  if (thc->waiting_complete_sender) {
    awe_t *awe = thc->waiting_complete_sender;
    thc->waiting_complete_sender = NULL;
    THCSchedule(awe); // thc->thc_binding_lock passed to thc_complete_send
  } else {
    thc->thc_send_complete = 1;
    thc_lock_release(&thc->thc_binding_lock);
  }
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_complete_send_cb\n"));
}
示例#15
0
static void thc_send_possible_event(void *arg) {
  struct common_binding *b = (struct common_binding*) arg;
  struct thc_per_binding_state_t *thc;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_send_possible_event\n"));
  thc = (struct thc_per_binding_state_t *)(b->st);
  thc_lock_acquire(&thc->thc_binding_lock);
  thc->send_possible_event_requested = 0;
  awe_t *awe = thc->waiting_sender;
  if (awe != NULL) {
    // Sender waiting
    thc->waiting_sender = NULL;
    THCSchedule(awe); // thc_binding_lock passed to sender
  } else {
    // No sender waiting (because they were canceled)
    thc_lock_release(&thc->thc_binding_lock);
  }
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_send_possible_event\n"));
}
示例#16
0
static void thc_receive_x_cancel_fn(void *c) {
  struct thc_receive_cancel_info *cinf = (struct thc_receive_cancel_info *)c;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_receive_x_cancel_fn\n"));
  thc_lock_acquire(&cinf->thc->thc_binding_lock);
  assert(!cinf->was_canceled);
  if (cinf->rxi->waiter == NULL) {
    // We lost a race with an incoming message
    thc_lock_release(&cinf->thc->thc_binding_lock);
  } else {
    // Cancellation got the thc_binding_lock before an
    // incoming message arrived.
    cinf->was_canceled = 1;
    awe_t *awe = cinf->rxi->waiter;
    cinf->rxi->waiter = NULL;
    THCYieldTo(awe); // thc->thc_binding_lock passed to top-half function
  }
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_receive_x_cancel_fn\n"));
}
示例#17
0
static void thc_await_send_x_cancel_fn(void *c) {
  struct thc_await_send_cancel_info *cinf = (struct thc_await_send_cancel_info*)c;
  struct thc_per_binding_state_t *thc = cinf->thc;
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_await_send_x_cancel_fn\n"));
  thc_lock_acquire(&thc->thc_binding_lock);
  if (thc->waiting_sender == NULL) {
    // We lost a race with an incoming send_possible event
    thc_lock_release(&thc->thc_binding_lock);
  } else {
    // Cancellation got the thc_binding_lock before an
    // incoming send_possible event
    assert(!cinf->was_canceled);
    cinf->was_canceled = 1;
    awe_t *awe = cinf->thc->waiting_sender;
    cinf->thc->waiting_sender = NULL;
    THCYieldTo(awe); // thc->thc_binding_lock passed to await_send_x;
  }
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_await_send_x_cancel_fn\n"));
}
示例#18
0
void thc_complete_send(struct thc_per_binding_state_t *thc,
                       void *f) {
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_complete_send\n"));
  // There is at most one sender, so if we are waiting to complete then
  // nobody else should be waiting for a can-send callback
  assert(thc->waiting_sender == NULL);

  thc_lock_acquire(&thc->thc_binding_lock);

  if (!thc->thc_send_complete) {
    // Send completion callback has not yet executed: wait
    THCSuspendThen(&thc->waiting_complete_sender,
                   thc_complete_send0,
                   (void*) &thc->thc_binding_lock);
  }

  thc_lock_release(&thc->thc_binding_lock);
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_complete_send\n"));
}
示例#19
0
struct thc_receiver_info *thc_start_demuxable_bh(struct thc_per_binding_state_t *thc,
                                                 void *common_binding,
                                                 struct thc_per_recv_t *recv,
                                                 uint64_t demux) {
  assert(demux != NO_DEMUX);
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > start_demux_bh\n"));
  thc_lock_acquire(&thc->thc_binding_lock);

  bool found;
  struct thc_receiver_info *rxi;
  do {
    found = false;
    rxi = recv->r;
    while (rxi != NULL) {
      assert(rxi->demux != NO_DEMUX);
      if (rxi->demux == demux) {
        // Wait until the receiver is ready (the response to an OOO RPC
        // may come back after they've done the send but before they
        // block in receive).
        while (rxi->waiter == NULL) {
          recv->num_bh++;
          thc_condvar_wait(&recv->cv_bh, &thc->thc_binding_lock);
          recv->num_bh--;
        }
        assert(rxi->waiter != NULL);
        found = true;
        break;
      }
      rxi = rxi->next;
    }
    // No receiver entry present: they were canceled
    if (!found) {
      thc_lock_release(&thc->thc_binding_lock);
      DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < start_demux_bh\n"));
      return NULL;
    }
  } while (!found);

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < start_demux_bh\n"));
  return rxi;
}
Node * pullProc(RunningProcesses *rp, int procID)
{
 
  Node *temp = NULL;
  Node *tempToPull = NULL;
  if(rp->size != 0)
    {
      temp = rp->head;
    }
  else
    {
      DEBUGPRINTF("ERROR: Tried to pull Proc on an empty list\n");
      return NULL;
    }
  //if the proc to be removed is the head
  if (rp->size == 1)
    {
      rp->head = NULL;
      rp->tail = NULL;
      temp->next = NULL;
      rp->size--;
      return temp;
    }
  if(rp->head->procID ==procID)
    {
      rp->head = temp->next;
      temp->next = NULL;
      rp->size--;
      return temp;
    }
  //else check the LinkedList for the Node
  else
    {
      while(temp->next != NULL)
	{
	  if(temp->next->procID == procID)
	    {
	      tempToPull = temp->next;
	      if(tempToPull->next == NULL)//test if it is the tail
		{
		  rp->tail = temp;
		}
	      temp->next = tempToPull->next;
	      tempToPull->next = NULL;
	      rp->size--;
	      return tempToPull;
	    }
	  temp = temp->next;
	}

      return NULL;
    }
}
示例#21
0
void bloodCamp()
{
	float Fcamp[17] = { 0.09363296, 0.48689139, 0.65543071, 0.77528090, 0.86516854, 0.91011236, 0.95505618, 0.97003745, 0.98127341,
		0.98127341, 0.98876404, 0.99250936, 0.99625468, 0.99625468, 0.99625468, 0.99625468, 1.0 };
	/* the description in the book chapter uses an Empirical distribution for units of blood donated, then you would do the same as for Fcamp,
	However, see bloodbank.R script for analysis of this data, we find that we could us the negative binomial distribution */
	float size = 2.7425933;
	float mu = 83.5663430;  /* these are the parameters found in the R script for the negative binomial distribution */
	float collected = (float) negativebinomrnd(size, mu, camp_seed);
	DEBUGPRINTF("Blood from camp: %.4f units. Now storing in inventory based on policies. \n", collected);
	bloodArrival(collected);
	/* Schedule next camp 3) */
	event_schedule(sim_time + (float)discrete_empirical(Fcamp, 17, camp_seed), EVENT_BLOOD_ARRIVAL);
}
示例#22
0
void Clock::Report() const
{
	DEBUGPRINTF( "=== Clock report ===\n" );
	DEBUGPRINTF( "Machine time: %.2f\n", m_MachineCurrentTime );
	DEBUGPRINTF( "Game time: %.2f\n", m_GameCurrentTime );
	DEBUGPRINTF( "Machine delta time: %.4f\n", m_MachineDeltaTime );
	DEBUGPRINTF( "Game delta time: %.4f\n", m_GameDeltaTime );
	DEBUGPRINTF( "Game time drift: %.4f\n", m_GameCurrentTime - m_MachineCurrentTime );	// Only meaningful before time effects are applied
}
示例#23
0
errval_t thc_receive_demux(struct thc_per_binding_state_t *thc,
                           struct thc_per_recv_t *recv,
                           struct thc_receiver_info *rxi) {
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_receive_demux\n"));
  thc_lock_acquire(&thc->thc_binding_lock);

  // Wake any bottom-half functions that are present
  if (recv->num_bh > 0) {
    thc_condvar_broadcast(&recv->cv_bh);
  }

  // Wait until a bottom-half provides a message
  //
  // We release the binding lock before blocking.  It is passed back to us
  // by the bottom-half receive function.

  THCSuspendThen(&rxi->waiter, thc_receive0, (void*) &thc->thc_binding_lock);

  // Remove us from the list of receivers
  struct thc_receiver_info **rxip = (struct thc_receiver_info **) &(recv->r);
  bool found = false;
  while (*rxip != NULL) {
    if (*rxip == rxi) {
      *rxip = rxi -> next;
      found = true;
      break;
    }
    rxip = &((*rxip)->next);
  }
  assert(found);

  thc_lock_release(&thc->thc_binding_lock);

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_receive_demux\n"));
  return SYS_ERR_OK;
}
示例#24
0
errval_t thc_receive(struct thc_per_binding_state_t *thc,
                     struct thc_per_recv_t *recv,
                     struct thc_receiver_info *rxi) 
{
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_receive\n"));
  thc_lock_acquire(&thc->thc_binding_lock);

  assert(recv->r == NULL && "thc_receiver found existing receiver");

  // Install us as the receiver for this message
  rxi->next = NULL;
  rxi->demux = NO_DEMUX;
  recv->r = rxi;

  // Wake any bottom-half functions that are present
  if (recv->num_bh > 0) {
    thc_condvar_broadcast(&recv->cv_bh);
  }

  // Wait until a bottom-half provides a message
  //
  // We release the binding lock before blocking.  It is passed back to us
  // by the bottom-half receive function.
  THCSuspendThen(&rxi->waiter, thc_receive0, (void*) &thc->thc_binding_lock);

  // Remove us as the receiver
  assert(recv->r == rxi);  
  recv->r = NULL;

  thc_lock_release(&thc->thc_binding_lock);

  THCIncRecvCount();

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_receive\n"));
  return 0;
}
示例#25
0
errval_t thc_cancel_receive_demux(struct thc_per_binding_state_t *thc,
                                  struct thc_per_recv_t *recv,
                                  struct thc_receiver_info *rxi) {
  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " > thc_cancel_receive_demux\n"));
  thc_lock_acquire(&thc->thc_binding_lock);

  // Remove us from the list of receivers
  struct thc_receiver_info **rxip = (struct thc_receiver_info **) &(recv->r);
  bool found = false;
  while (*rxip != NULL) {
    if (*rxip == rxi) {
      *rxip = rxi -> next;
      found = true;
      break;
    }
    rxip = &((*rxip)->next);
  }
  assert(found);

  thc_lock_release(&thc->thc_binding_lock);

  DEBUG_STUBS(DEBUGPRINTF(DEBUG_STUBS_PREFIX " < thc_cancel_receive_demux\n"));
  return THC_CANCELED;
}
示例#26
0
void bloodDonation()
{
    float donationF[11] = {0.459770115, 0.67816092, 0.770114943, 0.862068966, 0.873563218, 0.908045977, 0.965517241, 0.965517241, 0.965517241, 0.977011494, 1.0};
	//placeholders
	float collected = (float)discrete_empirical(donationF, 11, donation_seed); // TODO: need generator function for blood collected here
	/*
	1) Update the stock levels of the items of various blood groups based
	on daily donation quantity,% failed tests ,% componentized and % of
	various blood groups.
	2) Compute the day of Expiry of the new batch of the various items
	*/
	DEBUGPRINTF("Blood from donation: %.4f units. Now storing in inventory based on policies. \n", collected);
	bloodArrival(collected);
	/* Schedule next donation event */
	event_schedule(sim_time + 1.0f, EVENT_BLOOD_DONATION);

}
示例#27
0
Console::Console()
{
	AllocConsole();

	// Store off original stdin, stdout, and stderr
	m_StdIn = *stdin;
	m_StdOut = *stdout;
	m_StdErr = *stderr;

	intptr_t	StdHandle;
	int			ConHandle;
	FILE*		Stream;

	// Redirect stdout
	StdHandle = (intptr_t)GetStdHandle( STD_OUTPUT_HANDLE );
	ConHandle = _open_osfhandle( StdHandle, _O_TEXT );
	if( ConHandle != -1 )
	{
		Stream = _fdopen( ConHandle, "w" );
		*stdout = *Stream;
		setvbuf( stdout, NULL, _IONBF, 0 );
	}

	// Redirect stdin
	StdHandle = (intptr_t)GetStdHandle( STD_INPUT_HANDLE );
	ConHandle = _open_osfhandle( StdHandle, _O_TEXT );
	if( ConHandle != -1 )
	{
		Stream = _fdopen( ConHandle, "r" );
		*stdin = *Stream;
		setvbuf( stdin, NULL, _IONBF, 0 );
	}

	// Redirect stderr
	StdHandle = (intptr_t)GetStdHandle( STD_ERROR_HANDLE );
	ConHandle = _open_osfhandle( StdHandle, _O_TEXT );
	if( ConHandle != -1 )
	{
		Stream = _fdopen( ConHandle, "w" );
		*stderr = *Stream;
		setvbuf( stderr, NULL, _IONBF, 0 );
	}

	DEBUGPRINTF( "Console initialized\n" );
}
//returns 0 if it found the proc to delete and deleted it else it returns 1
int removeProc(RunningProcesses * rp, int removeProcID)
{
  Node *temp = NULL;
  Node *tempToDelete = NULL;
  if(rp->size != 0)
    {
      temp = rp->head;
    }
  else
    {
      DEBUGPRINTF("ERROR: Tried to removeProc on an empty list\n");
      return -1;
    }
  //if the proc to be removed is the head
  if(rp->head->procID == removeProcID)
    {
      removeFirstProc(rp);
      return 0;
    }
  //else check the LinkedList for the Node
  else
    {
      while(temp->next != NULL)
	{
	  if(temp->next->procID == removeProcID)
	    {
	      tempToDelete = temp->next;
	      if(tempToDelete->next == NULL)//test if its the tail
		{
		  rp->tail = temp;
		}
	      temp->next = tempToDelete->next;
	      tempToDelete->next = NULL;
	      free(tempToDelete);
	      tempToDelete = NULL;
	      rp->size--;
	      return 0;
	    }
	  temp = temp->next;
	}

      return 1;
    }
}
示例#29
0
void Renderer::RenderSpriteSheetIndex(float x, float y, float width, float height, int index)
{
	/*if(x < 0.0f || x > 1.0f)
		return;
	if(y < 0.0f || y > 1.0f)
		return;
	*/
	HRESULT result;


	//we will want to assume that we have a 16x16 sprite sheet for now.
	assert(index >= -1 && index < 256);
	
	//make new temp U,V coords.
	float newUMin, newVMin, newUMax, newVMax;
	newUMin = newVMin = 0.0f; 
	newUMax = newVMax = 1.0f;
	if(index != -1)
	{
		//since individual sprites are on 16x16
		unsigned int xCoord = 0;
		unsigned int yCoord = 0;

		xCoord = index % 16;
		yCoord = index / 16;

		float offset = 1.0f / 16.0f;
		newUMin = (float)xCoord * offset;
		newUMax = newUMin + offset;
		newVMin = (float)yCoord * offset;
		newVMax = newVMin + offset;
	}

	BillboardSprite sprite = BillboardSprite();
	// Make sure device exists
	if(m_pD3DDevice == NULL)
	{
		assert(false);
		return;
	}
	//Yeah, now we set stream source to be the vertex buffer we just dumped into.


	//set FVF.
	result = m_pD3DDevice->SetFVF(RenderVertexTL::FVF);
	assert(SUCCEEDED(result));

	sprite.SetAspectRatio((float)m_nTargetWidth,(float)m_nTargetHeight);
	sprite.SetWidth(width);
	sprite.SetHeight(height);
	if(m_bRenderToBackBuffer)
	{
		sprite.SetX(x,false);
		sprite.SetY(y,false);
	}
	else
	{
		sprite.SetX(x,true);
		sprite.SetY(y,true);
	}
	sprite.SetZ(1.0f);
	sprite.SetU(newUMin);
	sprite.SetV(newVMin);
	sprite.SetUWidth(newUMax-newUMin);
	sprite.SetVWidth(newVMax-newVMin);
	sprite.ApplyTextureCoords();

#if 0
	result = m_pD3DDevice->DrawIndexedPrimitiveUP(
		D3DPT_TRIANGLELIST,
		sprite.GetFirstVertex(),
		sprite.GetNumVertices(),
		sprite.GetNumPrimitives(),
		triList,
		D3DFMT_INDEX16,
		sprite.GetVertexList(),
		sizeof(RenderVertexTL)
	);
#endif
	//Let's fill the vertex buffer. (yay?)
	
	void *vb_vertices;

	//assert(localSpriteCount == m_nCurrentSprite);
	int localSpriteCount = m_nCurrentSprite++;
	//	if(spriteCount != -1)
	//		localSpriteCount = spriteCount;


	//Make sure there's still room in vertex buffer
	bool EnoughRoomInVertexBuffer = (localSpriteCount * BillboardSprite::GetNumVerticesStatic()) < (int)m_nLengthVertexBuffer;
	if(!EnoughRoomInVertexBuffer)
	{
		DEBUGPRINTF("Attempted to write %d to a %d length vertex buffer.\nForgetting to flush our buffer, are we?\n", localSpriteCount * BillboardSprite::GetNumVerticesStatic(), m_nLengthVertexBuffer);
		assert(EnoughRoomInVertexBuffer);
		return;
	}

	result = m_listVertexBuffer->Lock(localSpriteCount * sprite.GetNumIndices()/*sprite.GetNumVertices()*/ * sizeof(RenderVertexTL),	//Offset
								/*sprite.GetNumVertices()*/sprite.GetNumIndices() * sizeof(RenderVertexTL),            //SizeToLock
								&vb_vertices,					//Vertices
								D3DLOCK_DISCARD);				//Flags
	
	assert(SUCCEEDED(result));

	//vb_vertices now points to an array of vertices. To fill the Vertex Buffer with our data, we'll use memcpy from the standard C library.

	RenderVertexTL *tmp = (RenderVertexTL *)sprite.GetVertexList();
	int *a = (int *)sprite.GetIndexList();
	RenderVertexTL tempSprite[6] = {tmp[a[0]],tmp[a[1]],tmp[a[2]],tmp[a[3]],tmp[a[4]],tmp[a[5]]};

	memcpy	(
				vb_vertices, //Destination
				(const void *)tempSprite,
				//sprite.GetVertexList(),       //Source
				sprite.GetNumIndices() * sizeof(RenderVertexTL)
				//sprite.GetNumVertices() * sizeof(RenderVertexTL)
			); //Amount of data to copy

	//After we've copied our data into the buffer, we can unlock the buffer so it can be used for rendering. The Unlock call takes no parameters.

	m_listVertexBuffer->Unlock();

#if 0 //This section is disabled due to lack of proper index buffer support.
	void *ib_indices;

	//Make sure there's still room in index buffer
	bool EnoughRoomInIndexBuffer = (localSpriteCount * BillboardSprite::GetNumIndicesStatic()) < (int)m_nLengthIndexBuffer;
	if(!EnoughRoomInIndexBuffer)
	{
		DEBUGPRINTF("Attempted to write %d to a %d length vertex buffer.\nForgetting to flush our buffer, are we?\n", localSpriteCount * BillboardSprite::GetNumIndicesStatic(), m_nLengthIndexBuffer);
		assert(EnoughRoomInIndexBuffer);
		return;
	}

	result = m_listIndexBuffer->Lock(localSpriteCount * sprite.GetNumIndices() * sizeof(int),	//Offset
								sprite.GetNumIndices() * sizeof(int),            //SizeToLock
								&ib_indices,					//Vertices
								D3DLOCK_DISCARD);				//Flags
	
	assert(SUCCEEDED(result));

	//vb_vertices now points to an array of vertices. To fill the Vertex Buffer with our data, we'll use memcpy from the standard C library.

	memcpy	(
				ib_indices, //Destination
				sprite.GetIndexList(),       //Source
				sprite.GetNumIndices() * sizeof(int)
			); //Amount of data to copy

	//After we've copied our data into the buffer, we can unlock the buffer so it can be used for rendering. The Unlock call takes no parameters.

	m_listIndexBuffer->Unlock();
#endif
}
示例#30
0
HRESULT Renderer::Initiate(HWND hwnd, int width, int height, bool fullscreen, bool vsync, unsigned int refRate)
{
	m_hWnd = hwnd;
	// create the IDirect3D9 object
	m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
	if (m_pD3D == NULL)
		return E_FAIL;
	
	// get the display mode
	D3DDISPLAYMODE d3ddm;
	m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);

	// set the presentation parameters
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.BackBufferWidth = width;
	d3dpp.BackBufferHeight = height;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferFormat = d3ddm.Format;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.Windowed = !fullscreen;
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.FullScreen_RefreshRateInHz = refRate;
	if(vsync)
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	else
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	
	// create the device
	if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 
		D3DDEVTYPE_HAL, hwnd,
		D3DCREATE_FPU_PRESERVE | D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&d3dpp, &m_pD3DDevice)))
	{
		//Fallback to software rendering.
		if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 
			D3DDEVTYPE_REF, hwnd,
			D3DCREATE_FPU_PRESERVE | D3DCREATE_SOFTWARE_VERTEXPROCESSING,
			&d3dpp, &m_pD3DDevice)))
		{
			return E_FAIL;
		}
	}

	m_pD3DDevice->GetRenderTarget(0, &m_pOriginalBackBuffer);
	m_pD3DDevice->GetDepthStencilSurface(&m_pOriginalDepthStencil);

	//Set default render attributes.
	m_bDepthBufferRead = true;
	m_bDepthBufferWrite = true;
	m_bBlendEnable = true;
	m_fConstantOpacity = 1.0f;
	m_bZEnable = true;
	m_bFogEnable = false;
	m_nWidth = width;
	m_nHeight = height;
	m_nTargetHeight = height;
	m_nTargetWidth = width;
	m_bRenderToBackBuffer = true;

	restoreRenderStates();

	gTextureManager = new TextureManager();

	m_listVertexBuffer = NULL;
	m_listIndexBuffer = NULL;

	int vert_count;
	int byte_count;
	int ind_count;
	HRESULT hres;
	int sprite_count = 3 * (int)GetCoordOffsetInv() * (int)GetCoordOffsetInv();
	vert_count=6;//BillboardSprite::GetNumVerticesStatic();
	byte_count = vert_count*sizeof(RenderVertexTL) * sprite_count;
	m_nLengthVertexBuffer = vert_count * sprite_count;
	hres = m_pD3DDevice->CreateVertexBuffer(	
												byte_count, //length
												D3DUSAGE_WRITEONLY, //usage flags
												RenderVertexTL::FVF, //FVF
												D3DPOOL_MANAGED, //Pool
												&m_listVertexBuffer, //vertex buffer to be used.
												NULL //should be null?
											);

	if(FAILED(hres))
	{
		switch(hres)
		{
		case D3DERR_INVALIDCALL:
			DEBUGPRINTF("Invalid call in CreateVertexBuffer\n");
			break;
		case D3DERR_OUTOFVIDEOMEMORY:
			DEBUGPRINTF("Out of video memory for CreateVertexBuffer\n");
			break;
		case E_OUTOFMEMORY:
			DEBUGPRINTF("Out of memory for CreateVertexBuffer\n");
			break;
		}
		DEBUGPRINTF("%d bytes into vertex buffer fails\n", hres);
		return E_FAIL;
	}
	ind_count=BillboardSprite::GetNumIndicesStatic();
	byte_count = ind_count*sizeof(int) * sprite_count;
	m_nLengthIndexBuffer = ind_count * sprite_count;
	hres = m_pD3DDevice->CreateIndexBuffer(	
												byte_count, //length
												D3DUSAGE_WRITEONLY, //usage flags
												D3DFMT_INDEX16, //format of indices
												D3DPOOL_MANAGED, //Pool
												&m_listIndexBuffer, //vertex buffer to be used.
												NULL //should be null?
											);

	if(FAILED(hres))
	{
		switch(hres)
		{
		case D3DERR_INVALIDCALL:
			DEBUGPRINTF("Invalid call in CreateVertexBuffer\n");
			break;
		case D3DERR_OUTOFVIDEOMEMORY:
			DEBUGPRINTF("Out of video memory for CreateVertexBuffer\n");
			break;
		case E_OUTOFMEMORY:
			DEBUGPRINTF("Out of memory for CreateVertexBuffer\n");
			break;
		}
		DEBUGPRINTF("%d bytes into vertex buffer fails\n", hres);
		return E_FAIL;
	}

	DEBUGPRINTF("Size of input: %d\n", sizeof(RenderVertexTL[4]));
	m_nCurrentSprite = 0;
	m_uNumTriangles = 0;
	return S_OK;
}