Example #1
0
File: tecplot.c Project: rolk/ug
static INT get_offset (INT n)
{
  INT i,subtreesize[50],sum,offset;

  /* get number of objects downtree */
  sum = n;
  for (i=0; i<degree; i++) {
    GetConcentrate(i,subtreesize+i,sizeof(INT));
    sum += subtreesize[i];
  }

  /* get offset */
  if (me==master)
  {
    offset = 0;
  }
  else
  {
    Concentrate(&sum,sizeof(INT));
    GetSpread(&offset,sizeof(INT));
  }

  /* send offsets for downtree nodes */
  sum = offset+n;
  for (i=0; i<degree; i++) {
    Spread(i,&sum,sizeof(INT));
    sum += subtreesize[i];
  }

  return(offset);
}
Example #2
0
void mpc_psy_model_init_tables(PsyModel *m)
{
	m->Max_Band = (int) ( m->BandWidth * 64. / m->SampleFreq );
	if ( m->Max_Band <  1 ) m->Max_Band =  1;
	if ( m->Max_Band > 31 ) m->Max_Band = 31;

    Tonalitaetskoeffizienten (m);
	Ruhehoerschwelle ( m, m->EarModelFlag, m->Ltq_offset, m->Ltq_max );
    Loudness_Tabelle (m);
    Spread (m);
}
Example #3
0
void GoInfluence::ComputeInfluence(const GoBoard& bd,
                      const SgBWSet& stopPts,
                      SgBWArray<SgPointArray<int> >* influence)
{
    const int MAX_INFLUENCE = 64;
    for (SgBWIterator it; it; ++it)
    {
        SgBlackWhite color = *it;
        ((*influence)[color]).Fill(0);
        for (GoBoard::Iterator it(bd); it; ++it)
        {
            SgPoint p(*it);
            if (bd.IsColor(p, color))
                Spread(bd, p, stopPts[color], MAX_INFLUENCE, 
                       (*influence)[color]);
        }
    }
}
Example #4
0
File: notify.c Project: rolk/ug
int NotifyTwoWave (NOTIFY_INFO *allInfos, int lastInfo, int exception)
{
  NOTIFY_INFO  *newInfos;
  int l, i, j, n, unknownInfos, myInfos;
  int local_exception = exception;

#if     DebugNotify<=4
  printf("%4d:    NotifyTwoWave, lastInfo=%d\n", me, lastInfo);
  fflush(stdout);
#endif

  /* BOTTOM->TOP WAVE */
  /* get local Info lists from downtree */
  for(l=degree-1; l>=0; l--)
  {
    GetConcentrate(l, &n, sizeof(int));

    if (n<0)
    {
      /* exception from downtree, propagate */
      if (-n > local_exception)
        local_exception = -n;
    }

    if (lastInfo+n >= maxInfos) {
      DDD_PrintError('E', 6321, "msg-info array overflow in NotifyTwoWave");
      local_exception = EXCEPTION_NOTIFY;

      /* receive data, but put it onto dummy position */
      GetConcentrate(l, allInfos, n*sizeof(NOTIFY_INFO));
    }
    else
    {
      if (n>0)
        GetConcentrate(l, &(allInfos[lastInfo]), n*sizeof(NOTIFY_INFO));
    }

    /* construct routing table */
    for(i=0; i<n; i++)
      theRouting[allInfos[lastInfo+i].from] = l;

    if (n>0)
      lastInfo += n;
  }


  if (! local_exception)
  {
    /* determine target direction in tree */
    /* TODO: eventually extra solution for root node!
                     (it knows all flags are MYSELF or KNOWN!)  */
    qsort(allInfos, lastInfo, sizeof(NOTIFY_INFO), sort_XferInfos);
    i = j = 0;
    unknownInfos = lastInfo;
    myInfos = 0;
    while (i<lastInfo && allInfos[j].to==PROC_INVALID_TEMP)
    {
      if (allInfos[j].from==allInfos[i].to)
      {
        allInfos[i].flag = (allInfos[i].to==me) ? MYSELF : KNOWN;
        unknownInfos--;
        if (allInfos[i].to==me)
          myInfos++;
        i++;
      } else {
        if (allInfos[j].from<allInfos[i].to)
          j++;
        else
          i++;
      }
    }
    qsort(allInfos, lastInfo, sizeof(NOTIFY_INFO), sort_XferFlags);


    /* send local Info list uptree, but only unknown Infos */
    newInfos = &allInfos[lastInfo-unknownInfos];
    Concentrate(&unknownInfos, sizeof(int));
    Concentrate(newInfos, unknownInfos*sizeof(NOTIFY_INFO));
    lastInfo -= unknownInfos;

                #if     DebugNotify<=1
    for(i=0; i<unknownInfos; i++)
    {
      printf("%4d:    NotifyTwoWave, "
             "send uptree unknown %d/%d (%d|%d;%d)\n",
             me, i, unknownInfos,
             newInfos[i].to, newInfos[i].from, newInfos[i].size);
    }
                #endif

  }
  else
  {
    /* we have an exception somewhere in the processor tree */
    /* propagate it */
    int neg_exception = -local_exception;
    Concentrate(&neg_exception, sizeof(int));
    /* don't need to send data now */
  }

#if     DebugNotify<=3
  printf("%4d:    NotifyTwoWave, wave 1 ready\n", me);
  fflush(stdout);
#endif



  /* TOP->BOTTOM WAVE */

  /* get Infos local to my subtree from uptree */
  unknownInfos = 0;
  GetSpread(&unknownInfos, sizeof(int));
  if (unknownInfos<0)
  {
    /* exception from downtree, propagate */
    if (-unknownInfos > local_exception)
      local_exception = -unknownInfos;
  }

  if (unknownInfos>0)
  {
    GetSpread(newInfos, unknownInfos*sizeof(NOTIFY_INFO));
    lastInfo += unknownInfos;
  }

  if (! local_exception)
  {
    /* sort Infos according to routing */
    qsort(allInfos, lastInfo, sizeof(NOTIFY_INFO), sort_XferRouting);

                #if     DebugNotify<=1
    for(i=0; i<lastInfo; i++)
    {
      printf("%4d:    NotifyTwoWave, "
             "sorted for routing  %d/%d (%d|%d;%d)\n",
             me, i, lastInfo,
             allInfos[i].to, allInfos[i].from, allInfos[i].size);
    }
                #endif

    /* send relevant Infos downtree */
    i = 0;
    unknownInfos = lastInfo;
    while ((i<unknownInfos)&&(allInfos[i].to==me)) i++;
    lastInfo = i;
    for(l=0; l<degree; l++)
    {
      j = i;
      while ((i<unknownInfos)&&(theRouting[allInfos[i].to]==l)) i++;
      j = i-j;

      Spread(l, &j, sizeof(int));
      if (j>0)
        Spread(l, &allInfos[i-j], j*sizeof(NOTIFY_INFO));
    }


    /* reuse theDescs-array for registering messages to be received */
    for(i=0; i<lastInfo; i++)
    {
      theDescs[i].proc = allInfos[i].from;
      theDescs[i].size = allInfos[i].size;
    }

                #if     DebugNotify<=3
    printf("%4d:    NotifyTwoWave, "
           "wave 2 ready, nRecv=%d\n", me, lastInfo);
    fflush(stdout);
                #endif
  }
  else
  {
    /* we received an exception from uptree, propagate it */
    for(l=0; l<degree; l++)
    {
      int neg_exception = -local_exception;
      Spread(l, &neg_exception, sizeof(int));
      /* dont send any data */
    }

                #if     DebugNotify<=3
    printf("%4d:    NotifyTwoWave, "
           "wave 2 ready, Exception=%d\n", me, local_exception);
    fflush(stdout);
                #endif

    return(-local_exception);
  }

  return(lastInfo);
}
Example #5
0
BOOL TableClass::Layout (struct LayoutMessage &lmsg)
{
  if(Flags & FLG_AllElementsPresent)
  {
    FindImage(lmsg);
    if(!(Flags & FLG_AllocatedColours))
      AllocateColours(lmsg.Share->Scr->ViewPort.ColorMap);

    if(lmsg.Y != lmsg.MinY || !lmsg.IsAtNewline())
      lmsg.AddYSpace(4);

    lmsg.EnsureNewline();

    Top = lmsg.Y;
    Left = lmsg.X;
    lmsg.TopChange = min(Top, lmsg.TopChange);

    if(!(Flags & FLG_KnowsMinMax))
    {
      struct MinMaxMessage mmsg(lmsg.Share->Fonts, &lmsg);
      mmsg.Reset();
      MinMax(mmsg);
    }

    ULONG scr_width = lmsg.ScrWidth() - (Columns+1)*Spacing - 2*BorderSize;
    if(GivenWidth)
    {
      if(GivenWidth->Type == Size_Percent)
         Width = max(Min, ((lmsg.ScrWidth() * GivenWidth->Size) / 100) - (Columns+1)*Spacing - 2*BorderSize);
      else
            Width = max(GivenWidth->Size-(Columns+1)*Spacing-2*BorderSize, Min);
    }
    else
         Width = (Min <= scr_width) ? min(scr_width, Max) : Min;

    /* Set all cells to their min or max width */
    LONG scale = Width, table_delta = 0, relative = 0;
    for(ULONG i = 0; i < Columns; i++)
    {
      if(!Widths[i].Percent)
      {
        LONG cellwidth = Width >= Max ? Widths[i].Max : Widths[i].Min;
        table_delta += Widths[i].Max - Widths[i].Min;
        scale -= cellwidth;
        relative += Widths[i].Relative;
        Widths[i].Width = cellwidth;
      }
    }

    /* Set all cells with a width given in percent */
    for(ULONG i = 0; i < Columns; i++)
    {
      if(Widths[i].Percent)
      {
        ULONG cellwidth = max(Widths[i].Min, min((ULONG)scale, (Width * Widths[i].Percent) / 100));
        Widths[i].Width = cellwidth;
        scale -= cellwidth;
      }
    }

    if(scale > 0)
    {
      if(relative)
      {
        Spread(scale, relative, RelativeScale);
      }
      else if(table_delta)
      {
        Spread(scale, table_delta, NormalScale);
      }
      else
      {
        LONG width = Max;
        for(UWORD i = 0; i < Columns; i++)
        {
          if(Widths[i].Fixed)
            width -= Widths[i].Max;
        }

        if(width)
            Spread(scale, width, LeftOverScale);
        else  Width -= scale;
      }
    }
    else
    {
      Width -= scale;
    }

    struct CellWidth *oldwidths = lmsg.Widths;
    ULONG oldspace = lmsg.Spacing, oldpad = lmsg.Padding;
    struct TextFont *oldfont = lmsg.Font;

    ULONG oldcols = lmsg.Columns, oldimageleftindent = lmsg.ImageLeftIndent, oldimagerightindent = lmsg.ImageRightIndent;
    lmsg.ImageLeftIndent = lmsg.ImageRightIndent = 0;
    struct FloadingImage *fleft = lmsg.FLeft, *fright = lmsg.FRight;
    lmsg.FLeft = lmsg.FRight = NULL;

    lmsg.Widths = Widths;
    lmsg.Spacing = Spacing;
    lmsg.Padding = Padding + (BorderSize ? 1 : 0);
    lmsg.Columns = Columns;

    ULONG oldminx = lmsg.MinX;
    lmsg.MinX = lmsg.X += BorderSize;

    lmsg.AddYSpace(Spacing+BorderSize);
    Flags &= ~FLG_Virgin;

    ULONG *oldopencounts = lmsg.RowOpenCounts;
    lmsg.RowOpenCounts = (ULONG *)memset(RowOpenCounts, 0, Columns * sizeof(ULONG));

    ULONG *oldheights = lmsg.Heights;
    ULONG pass = lmsg.Pass;
    lmsg.Pass = 0;
    lmsg.Heights = (ULONG *)memset(Heights, 0, Rows*sizeof(ULONG));

    ULONG realrows = 0;
    struct ChildsList *first = FirstChild;
    while(first)
    {
      ((class TRClass *)first->Obj)->TRLayout(lmsg);
      first = first->Next;
      realrows++;
    }

    /* Should some cell set a rowspan that ends outside the table, then we enlarge all height entries */
    while(realrows < Rows)
    {
      Heights[realrows] = max(Heights[realrows], Heights[realrows-1]);
      realrows++;
    }

    Bottom = Rows ? Heights[Rows-1] : lmsg.Y;
    lmsg.Y = Bottom + Spacing;

    lmsg.Pass = 1;
    lmsg.Heights = Heights;

    first = FirstChild;
    while(first)
    {
      ((class TRClass *)first->Obj)->TRLayout(lmsg);
      first = first->Next;
    }

    lmsg.Pass = pass;
    lmsg.Heights = oldheights;

    lmsg.RowOpenCounts = oldopencounts;

    lmsg.MinX = oldminx;
    lmsg.AddYSpace(BorderSize);

    lmsg.Widths = oldwidths;
    lmsg.Columns = oldcols;
    lmsg.Spacing = oldspace;
    lmsg.Padding = oldpad;

    lmsg.FLeft = fleft;
    lmsg.FRight = fright;
    lmsg.ImageLeftIndent = oldimageleftindent;
    lmsg.ImageRightIndent = oldimagerightindent;
    lmsg.X += oldimageleftindent;

    lmsg.Font = oldfont;

    lmsg.Width = max((ULONG)lmsg.Width, lmsg.MinX+Width+((Columns+1)*Spacing)+2*BorderSize+lmsg.MarginWidth+lmsg.ImageRightIndent);

    Bottom = lmsg.Y-1;
    lmsg.AddYSpace(4);

    LONG width = Width+((Columns+1)*Spacing)+2*BorderSize;
    LONG delta = lmsg.ScrWidth() - width;
    UBYTE oldalign = lmsg.Align;
    if(delta > 0)
    {
      LONG offset = 0;

      if(Alignment == Align_Left || Alignment == Align_Right)
      {
        LONG width = Width + (Columns+1)*Spacing + 2*BorderSize;
        struct FloadingImage *img = new (std::nothrow) struct FloadingImage(Top, Left, width, (Bottom-Top)+1, this, lmsg.Parent);
        if (img)
        {
        	LONG left = lmsg.AddImage(img, Alignment == Align_Right);
	        offset = left - Left;
    	}

        lmsg.Y = Top;
        lmsg.Baseline = lmsg.Bottom = 0;
      }
      else if(lmsg.Align == Align_Center || Alignment == Align_Center)
      {
        offset = delta/2;
      }
      else if(lmsg.Align == Align_Right)
      {
        offset = delta;
      }

      if(offset)
        AdjustPosition(offset, 0);
    }

    lmsg.Align = oldalign;

    if(Alignment != Align_Left && Alignment != Align_Right)
      lmsg.CheckFloatingObjects();

    Flags |= FLG_Layouted;
  }
  else
  {
    lmsg.TopChange = min(lmsg.TopChange, MAX_HEIGHT);
  }

   return TRUE;
}
Example #6
0
void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
{
	FLOG("Simulating block {%d, %d, %d}: block %d, meta %d", 
		a_Chunk->GetPosX() * cChunkDef::Width + a_RelX, a_RelY, a_Chunk->GetPosZ() * cChunkDef::Width + a_RelZ,
		a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ),
		a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ)
	);
	
	BLOCKTYPE MyBlock; NIBBLETYPE MyMeta;
	a_Chunk->GetBlockTypeMeta(a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta);

	if (!IsAnyFluidBlock(MyBlock))
	{
		// Can happen - if a block is scheduled for simulating and gets replaced in the meantime.
		FLOG("  BadBlockType exit");
		return;
	}

	// When in contact with water, lava should harden
	if (HardenBlock(a_Chunk, a_RelX, a_RelY, a_RelZ, MyBlock, MyMeta))
	{
		// Block was changed, bail out
		return;
	}

	if (MyMeta != 0)
	{
		// Source blocks aren't checked for tributaries, others are.
		if (CheckTributaries(a_Chunk, a_RelX, a_RelY, a_RelZ, MyMeta))
		{
			// Has no tributary, has been decreased (in CheckTributaries()),
			// no more processing needed (neighbors have been scheduled by the decrease)
			FLOG("  CheckTributaries exit");
			return;
		}
	}
	
	// New meta for the spreading to neighbors:
	// If this is a source block or was falling, the new meta is just the falloff
	// Otherwise it is the current meta plus falloff (may be larger than max height, will be checked later)
	NIBBLETYPE NewMeta = ((MyMeta == 0) || ((MyMeta & 0x08) != 0)) ? m_Falloff : (MyMeta + m_Falloff);
	bool SpreadFurther = true;
	if (a_RelY > 0)
	{
		BLOCKTYPE Below = a_Chunk->GetBlock(a_RelX, a_RelY - 1, a_RelZ);
		if (IsPassableForFluid(Below) || IsBlockLava(Below) || IsBlockWater(Below))
		{
			// Spread only down, possibly washing away what's there or turning lava to stone / cobble / obsidian:
			SpreadToNeighbor(a_Chunk, a_RelX, a_RelY - 1, a_RelZ, 8);

			// Source blocks spread both downwards and sideways
			if (MyMeta != 0)
			{
				SpreadFurther = false;
			}
		}
		// If source creation is on, check for it here:
		else if (
			(m_NumNeighborsForSource > 0) &&  // Source creation is on
			(MyMeta == m_Falloff) &&          // Only exactly one block away from a source (fast bail-out)
			!IsPassableForFluid(Below) &&     // Only exactly 1 block deep
			CheckNeighborsForSource(a_Chunk, a_RelX, a_RelY, a_RelZ)  // Did we create a source?
		)
		{
			// We created a source, no more spreading is to be done now
			// Also has been re-scheduled for ticking in the next wave, so no marking is needed
			return;
		}
	}
	
	if (SpreadFurther && (NewMeta < 8))
	{
		// Spread to the neighbors:
		Spread(a_Chunk, a_RelX, a_RelY, a_RelZ, NewMeta);
	}
	
	// Mark as processed:
	a_Chunk->FastSetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, MyMeta);
}