Ejemplo n.º 1
0
void Bonus::process()
{
	y += velY;
	
	int ix = ftoi(x), iy = ftoi(y);
	
	if(game.level.inside(ix, iy + 1)
	&& game.materials[game.level.pixel(ix, iy + 1)].background())
	{
		velY += C[BonusGravity];
	}
		
	int inewY = ftoi(y + velY);
	if(inewY < 0 || inewY >= game.level.height - 1
	|| game.materials[game.level.pixel(ix, inewY)].dirtRock())
	{
		velY = -(velY * C[BonusBounceMul]) / C[BonusBounceDiv];
		
		if(std::abs(velY) < 100) // TODO: Read from EXE
			velY = 0;
	}
	
	if(--timer <= 0)
	{
		game.sobjectTypes[game.bonusSObjects[frame]].create(ix, iy, 0);
		if(used)
			game.bonuses.free(this);
	}
}
Ejemplo n.º 2
0
int fn_Find_Char(GAME_TRIGER * gt, TRIGER_STRUCTURE * ts, 
                 int *top, int *left, int *bottom, int *right, int *ycor, 
                 WCHAR cWChar, float xbmp, float ybmp)
{
  float *l, *t, *r, *b, *y;
  int i;

  if (cWChar < 0 || cWChar > b2_2d_font.iMaxCharValue)
    return 0;
  
  i = b2_2d_font.pTTable[cWChar];
  if (i < 0) {
    return 0;
  }
  else {
    l = (float *) &gt->command[i].Parametr[1].Value;
    t = (float *) &gt->command[i].Parametr[2].Value;
    r = (float *) &gt->command[i].Parametr[3].Value;
    b = (float *) &gt->command[i].Parametr[4].Value;
    y = (float *) &gt->command[i].Parametr[5].Value;

    *left = ftoi((*l) * xbmp);
    *top = ftoi((*t) * ybmp);
    *right = ftoi((*r) * xbmp);
    *bottom = ftoi((*b) * ybmp);
    *ycor = ftoi((*y) * ybmp);
  }

  return 1;
}
Ejemplo n.º 3
0
/* Converts from HSV to RGB */
void hsv_to_rgb(float hue, float saturation, float value,
                float &r, float &g, float &b)
{
  float f, p, q, t;

  if(saturation == 0) {
    r = value;
    g = value;
    b = value; /* heh */
  }
  else {
    hue *= 6;
    
    if(hue == 6)
      hue = 0;
  
    f = hue - ftoi(hue);
    p = value * (1 - saturation);
    q = value * (1 - saturation * f);
    t = value * (1 - saturation * (1.0 - f));

    switch (ftoi(hue))  {
    case 0:
      r = value;
      g = t;
      b = p;
      break;
    
    case 1:
      r = q;
      g = value;
      b = p;
      break;
    
    case 2:
      r = p;
      g = value;
      b = t;
      break;
    
    case 3:
      r = p;
      g = q;
      b = value;
      break;
    
    case 4:
      r = t;
      g = p;
      b = value;
      break;
    
    case 5:
      r = value;
      g = p;
      b = q;
      break;
    }
  }
}
Ejemplo n.º 4
0
int fn2_Find_Char(GAME_TRIGER * gt, TRIGER_STRUCTURE * ts, int *top,
  int *left, int *bottom, int *right, int *ycor, WCHAR cWChar, float xbmp,
  float ybmp)
{
  float *l, *t, *r, *b, *y;
  int i;

/*	for(i=0;i<gt->lastcommand;i++)
		switch(gt->command[i].iCommand)
		{
			case 1:
				{
					if(gt->command[i].LastParam > 5 &&
					   gt->command[i].Parametr[0].Type == 3)
					{
						if((WCHAR)gt->command[i].Parametr[0].Value == cWChar)
						{
							l = (float *)&gt->command[i].Parametr[1].Value;
							t = (float *)&gt->command[i].Parametr[2].Value;
							r = (float *)&gt->command[i].Parametr[3].Value;
							b = (float *)&gt->command[i].Parametr[4].Value;
							y = (float *)&gt->command[i].Parametr[5].Value;

							*left = ftoi((*l) * xbmp);
							*top = ftoi((*t) * ybmp);
							*right = ftoi((*r) * xbmp);
							*bottom = ftoi((*b) * ybmp);
							*ycor = ftoi((*y) * ybmp);

							return 1;
						}
					}
				}
				break;
		}*/

  if (cWChar > b2_3d_font.iMaxCharValue)
    return 0;

  i = b2_3d_font.pTTable[cWChar];

  if (i < 0)
    return 0;
  else {
    l = (float *) &gt->command[i].Parametr[1].Value;
    t = (float *) &gt->command[i].Parametr[2].Value;
    r = (float *) &gt->command[i].Parametr[3].Value;
    b = (float *) &gt->command[i].Parametr[4].Value;
    y = (float *) &gt->command[i].Parametr[5].Value;

    *left = ftoi((*l) * xbmp);
    *top = ftoi((*t) * ybmp);
    *right = ftoi((*r) * xbmp);
    *bottom = ftoi((*b) * ybmp);
    *ycor = ftoi((*y) * ybmp);
  }

  return 1;
}
Ejemplo n.º 5
0
//==============================
// ColorToABGR
int32_t ColorToABGR( Vector4f const & color )
{
    // format is ABGR 
    return  ( ftoi( color.w * 255.0f ) << 24 ) |
            ( ftoi( color.z * 255.0f ) << 16 ) |
            ( ftoi( color.y * 255.0f ) << 8 ) |
            ftoi( color.x * 255.0f );
}
Ejemplo n.º 6
0
static void
spectrogram_wavedata_listener (void *ctx, ddb_audio_data_t *data) {
    w_spectrogram_t *w = ctx;
    if (!w->samples) {
        return;
    }
    deadbeef->mutex_lock (w->mutex);
    w->samplerate = (float)data->fmt->samplerate;
    int nsamples = data->nframes;
    int sz = MIN (FFT_SIZE, nsamples);
    int n = FFT_SIZE - sz;
    memmove (w->samples, w->samples + sz, (FFT_SIZE - sz)*sizeof (double));

    float pos = 0;
    for (int i = 0; i < sz && pos < nsamples; i++, pos ++) {
        w->samples[n+i] = -1000.0;
        for (int j = 0; j < data->fmt->channels; j++) {
            w->samples[n + i] = MAX (w->samples[n + i], data->data[ftoi (pos * data->fmt->channels) + j]);
        }
    }
    deadbeef->mutex_unlock (w->mutex);
    if (w->buffered < FFT_SIZE) {
        w->buffered += sz;
    }
}
Ejemplo n.º 7
0
//-------------------------------------------------------------------------
int notmain ( void )
{
    uart_init();
    hexstring(0x12345678);
    hexstring(ifdummy(1.0F));
    hexstring(ifdummy(2.0F));
    hexstring(ifdummy(3.0F));
    hexstring(ifdummy(1234.0F));
    hexstring(ifdummy(1.2F));
    hexstring(ifdummy(vdiv(1234.0F,1.20F)));
    hexstring(ftoi(vdiv(1234.0F,1.20F)));
    hexstring(ftoi(1234.0F/1.20F));
    hexstring(ftoi(1234.0F/fdummy(1.20F)));
    hexstring(1234.0F/fdummy(1.20F));
    return(0);
}
Ejemplo n.º 8
0
void cr_Set_Surface(CREDIT_SURFACE * p_cs, int y)
{
  if (p_cs->iSurface == -1)
    return;

  p_cs->y = y;
  p_cs->x = ftoi((1024 - ddxGetWidth(p_cs->iSurface)) / 2.0f);
}
Ejemplo n.º 9
0
/* based on Delphi function by Witold J.Janik */
void
create_gradient_table (gpointer user_data, GdkColor *colors, int num_colors)
{
    w_spectrogram_t *w = user_data;

    num_colors -= 1;

    for (int i = 0; i < GRADIENT_TABLE_SIZE; i++) {
        double position = (double)i/GRADIENT_TABLE_SIZE;
        /* if position > 1 then we have repetition of colors it maybe useful    */
        if (position > 1.0) {
            if (position - ftoi (position) == 0.0) {
                position = 1.0;
            }
            else {
                position = position - ftoi (position);
            }
        }

        double m= num_colors * position;
        int n=(int)m; // integer of m
        double f=m-n;  // fraction of m

        w->colors[i] = 0xFF000000;
        float scale = 255/65535.f;
        if (num_colors == 0) {
            w->colors[i] = ((uint32_t)(colors[0].red*scale) & 0xFF) << 16 |
                ((uint32_t)(colors[0].green*scale) & 0xFF) << 8 |
                ((uint32_t)(colors[0].blue*scale) & 0xFF) << 0;
        }
        else if (n < num_colors) {
            w->colors[i] = ((uint32_t)((colors[n].red*scale) + f * ((colors[n+1].red*scale)-(colors[n].red*scale))) & 0xFF) << 16 |
                ((uint32_t)((colors[n].green*scale) + f * ((colors[n+1].green*scale)-(colors[n].green*scale))) & 0xFF) << 8 |
                ((uint32_t)((colors[n].blue*scale) + f * ((colors[n+1].blue*scale)-(colors[n].blue*scale))) & 0xFF) << 0;
        }
        else if (n == num_colors) {
            w->colors[i] = ((uint32_t)(colors[n].red*scale) & 0xFF) << 16 |
                ((uint32_t)(colors[n].green*scale) & 0xFF) << 8 |
                ((uint32_t)(colors[n].blue*scale) & 0xFF) << 0;
        }
        else {
            w->colors[i] = 0xFFFFFFFF;
        }
    }
}
Ejemplo n.º 10
0
void cr_DrawSurface(int iDest, int iSour, int *y)
{
  int xp = ftoi((1024 - ddxGetWidth(iSour)) / 2.0f);

  ddxBitBlt(iDest, xp, *y, ddxGetWidth(iSour), ddxGetHight(iSour), iSour, 0,
    0);


  (*y) += ddxGetHight(iSour);
}
Ejemplo n.º 11
0
Archivo: callout.c Proyecto: xxx/cdlib
/*
 * Function name: find_call_out
 * Description:   Locate an existing call_out to a named function
 * Arguments:     func - name of function the call_out should call
 * Returns:       -1 if not found, else time left before triggered
 */
int
find_call_out(string func)
{
    mixed *calls = get_all_alarms();
    int i;
    
    for (i = 0; i < sizeof(calls); i++)
	if (calls[i][1] == func)
	    return ftoi(calls[i][2]);
    return -1;
}
Ejemplo n.º 12
0
void oe_prikaz_set_barva_body_fast(K_EDITOR * p_cnf)
{
  if (!p_cnf->groupnum)
    return;

  if (!doe_prikaz_vyber_barvu_float(p_cnf, hwnd_aplikace, &p_cnf->bar.gr))
    return;

  // nastav i barvy v te liste
  if (p_cnf->bar.hDlg) {
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT15, "%d",
      ftoi(p_cnf->bar.gr * MAX_BYTE_F));
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT16, "%d",
      ftoi(p_cnf->bar.gg * MAX_BYTE_F));
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT17, "%d",
      ftoi(p_cnf->bar.gb * MAX_BYTE_F));
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT5, "%d",
      ftoi(p_cnf->bar.ga * MAX_BYTE_F));
  }

  oe_prikaz_set_barva_body(p_cnf);
}
Ejemplo n.º 13
0
Archivo: callout.c Proyecto: xxx/cdlib
/*
 * Function name: remove_call_out
 * Description:   Locate and remove a call_out to a named function
 * Arguments:     func - name of function the call_out is for
 * Returns:       -1 if not found, time that remained before trigger
 *                would be done if found
 */
int
remove_call_out(string func)
{
    mixed *calls = get_all_alarms();
    int i;
    
    for (i = 0; i < sizeof(calls); i++)
	if (calls[i][1] == func)
	{
	    remove_alarm(calls[i][0]);
	    return ftoi(calls[i][2]);
	}
    return -1;
}
Ejemplo n.º 14
0
int kam_pol_cti_klic(AnimHandle handle, float time, BOD * p_t, float *p_r,
                     float *p_fi, float *p_vzdal)
{
    KAMERA_TRACK_INFO *p_track;
    int loop, dtime;
    QUAT q(1, 0, 0, 0);

    if (handle >= p_ber->kamnum)
        return (K_CHYBA);

    p_track = p_ber->kamery + handle;

    if (!p_track || p_track->flag & GAME_KAMERA_3DS)
        return (K_CHYBA);

    loop = p_track->flag & GK_LOOP;

    if (time > 1.0f)
        time = 1.0f;
    else if (time < 0.0f)
        time = 0.0f;

    dtime = ftoi(time * p_track->endtime);

    if (p_track->pos_keys) {
        key_track_interpolace_bod(p_t, p_track->p_pos, p_track->p_pkeys, dtime,
                                  p_track->endtime, p_track->pos_keys, loop);
    }
    else {
        p_t->set(0.0f);
    }

    if (p_track->quat_keys) {
        key_track_interpolace_quat(&q, p_track->p_quat, p_track->p_qkeys, dtime,
                                   p_track->endtime, p_track->quat_keys, loop);
    }

    if (p_track->roll_keys) {
        key_track_interpolace_float(p_vzdal, p_track->p_roll, p_track->p_rlkeys,
                                    dtime, p_track->endtime, p_track->roll_keys, loop);
    }
    else {
        *p_vzdal = 0;
    }

    quat_to_euler(&q, p_r, p_fi);

    return (TRUE);
}
Ejemplo n.º 15
0
void kam_set_kino_screen(G_KONFIG * p_ber)
{
    int kxres = SCREEN_XRES;
    int kyres = ftoi(SCREEN_XRES * KINO_POMER);
    int kx = SCREEN_XSTART, ky = SCREEN_YSTART + (SCREEN_YRES - kyres) / 2;

    set_matrix_view(kx, ky, kxres, kyres);

    projection_matrix(&p_ber->kamera.project, p_ber->kam.fov,
                      (float) kxres / (float) kyres,
                      p_ber->kam.near_plane,
                      p_ber->kam.far_plane);
    set_matrix_project(&p_ber->kamera.project);

    camera_screen_mode = CAMERA_KINO;
}
void computeFPS()
{
    frameCount++;
    fpsCount++;

    if (fpsCount == fpsLimit)
    {
        char fps[256];
        float ifps = 1.f / (sdkGetAverageTimerValue(&timer) / 1000.f);
        sprintf(fps, "%s (sigma=%4.2f): %3.1f fps", sSDKsample, sigma, ifps);

        glutSetWindowTitle(fps);
        fpsCount = 0;

        fpsLimit = ftoi(MAX(ifps, 1.f));
        sdkResetTimer(&timer);
    }
}
void computeFPS()
{
    frameCount++;
    fpsCount++;

    if (fpsCount == fpsLimit)
    {
        char fps[256];
        float ifps = 1.f / (sdkGetAverageTimerValue(&timer) / 1000.f);
        sprintf(fps, "CUDA 3D Volume Filtering: %3.1f fps", ifps);

        glutSetWindowTitle(fps);
        fpsCount = 0;

        fpsLimit = ftoi(MAX(1.f, ifps));
        sdkResetTimer(&timer);
    }
}
Ejemplo n.º 18
0
void oe_prikaz_set_barva(K_EDITOR * p_cnf)
{
  if (!doe_prikaz_vyber_barvu_float(p_cnf, hwnd_aplikace, &p_cnf->bar.gr))
    return;

  // nastav i barvy v te liste
  if (p_cnf->bar.hDlg) {
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT15, "%d",
      ftoi(p_cnf->bar.gr * MAX_BYTE_F));
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT16, "%d",
      ftoi(p_cnf->bar.gg * MAX_BYTE_F));
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT17, "%d",
      ftoi(p_cnf->bar.gb * MAX_BYTE_F));
    doe_printf(p_cnf->bar.hDlg, IDC_EDIT5, "%d",
      ftoi(p_cnf->bar.ga * MAX_BYTE_F));
  }
  kprintf(1, "Barva R %d G %d B %d A %d", ftoi(p_cnf->bar.gr * MAX_BYTE_F),
    ftoi(p_cnf->bar.gg * MAX_BYTE_F),
    ftoi(p_cnf->bar.gb * MAX_BYTE_F), ftoi(p_cnf->bar.ga * MAX_BYTE_F));
}
Ejemplo n.º 19
0
bool BObject::process(Game& game)
{
	Common& common = *game.common;
	
	pos += vel;
	
	auto ipos = ftoi(pos);
	
	if(!game.level.inside(ipos))
	{
		return false;
	}
	else
	{
		PalIdx c = game.level.pixel(ipos);
		Material m = game.level.mat(ipos);
		
		if(m.background())
			vel.y += LC(BObjGravity);

		LTRACE(blod, c, xpos, ipos.x);
		LTRACE(blod, c, ypos, ipos.y);
			
		if((c >= 1 && c <= 2)
		|| (c >= 77 && c <= 79)) // TODO: Read from EXE
		{
			game.level.setPixel(ipos, 77 + game.rand(3), common);
			return false;
		}
		else if(m.anyDirt())
		{
			game.level.setPixel(ipos, 82 + game.rand(3), common);
			return false;
		}
		else if(m.rock())
		{
			game.level.setPixel(ipos, 85 + game.rand(3), common);
			return false;
		}
	}
	
	return true;
}
Ejemplo n.º 20
0
void fn2_Draw_Format_Line(GAME_TRIGER * gt, TRIGER_STRUCTURE * ts,
  TEXT_WORLD * tWord, int iWordl, int x, int y, int xmax, int iSection,
  int iSurface, char bFormat)
{
  int top, bottom, left, right, ycor;
  int i, j;
  int sx;

  float fp = 0;
  float f = 0;

  if (bFormat)
    fp = (xmax - tWord[iWordl - 1].xEnd) / (float) (iWordl - 1);

  if (!iWordl)
    return;

  for (i = 0; i < iWordl; i++) {
    sx = tWord[i].xStart + ftoi(f);

    for (j = 0; j < 128; j++) {
      if (!tWord[i].wcWord)
        return;

      if (!end_char(tWord[i].wcWord[j])) {
        if (fn2_Find_Char(gt, ts, &top, &left, &bottom, &right, &ycor,
            tWord[i].wcWord[j],
            (float) ddx2GetWidth(b2_3d_font.iBitmap[iSection]),
            (float) ddx2GetHeight(b2_3d_font.iBitmap[iSection]))) {
          ddx2TransparentBlt(iSurface, sx, y + ycor, right - left + 1,
            bottom - top + 1, b2_3d_font.iBitmap[iSection], left, top,
            b2_3d_font.tcolor);

          sx += right - left + 2;
        }
      }
      else
        break;
    }

    f += fp;
  }
}
Ejemplo n.º 21
0
int kam_3ds_cti_klic(AnimHandle handle, float time, BOD * p_p, BOD * p_t,
                     float *p_roll)
{
    KAMERA_TRACK_INFO *p_track;
    int loop;
    int dtime;

    if (handle >= p_ber->kamnum)
        return (K_CHYBA);

    p_track = p_ber->kamery + handle;

    if (!p_track || p_track->flag & GAME_KAMERA_POLAR)
        return (K_CHYBA);

    loop = p_track->flag & GK_LOOP;
    if (time > 1.0f)
        time = 1.0f;
    else if (time < 0.0f)
        time = 0.0f;

    dtime = ftoi(time * p_track->endtime);

    if (p_track->pos_keys) {
        key_track_interpolace_bod(p_p, p_track->p_pos, p_track->p_pkeys, dtime,
                                  p_track->endtime, p_track->pos_keys, loop);
    }
    if (p_track->trg_keys) {
        key_track_interpolace_bod(p_t, p_track->p_trg, p_track->p_tkeys, dtime,
                                  p_track->endtime, p_track->trg_keys, loop);
    }
    if (p_track->roll_keys) {
        key_track_interpolace_float(p_roll, p_track->p_roll, p_track->p_rlkeys,
                                    dtime, p_track->endtime, p_track->roll_keys, loop);
    }
    else {
        *p_roll = 0.0f;
    }

    return (TRUE);
}
Ejemplo n.º 22
0
int main(int argc, char* argv[]){
  float f;
  unsigned int i;
  
  if (argc < 2) {
    printf("Too few arguments");
    return EXIT_FAILURE;
  }

  f = atof(argv[1]);
  i = ftoi(f);
  printbits(i, SBITS, EBITS-1);
  printf(" ");
  printbits(i, EBITS, MBITS-1);
  printf(" ");
  printbits(i, MBITS, sizeof(f)*8-1);
  printf("\n");


  return EXIT_SUCCESS;
}
Ejemplo n.º 23
0
int cr_Set_Text_Center(int hdc, char *text, int isection, RECT r)
{
  int xp, yp;
  int tx, ty;
  WCHAR wc[256];
  int h;

  h = ddxCreateSurface(1024, 110, ddxFindFreeSurface());

  MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, wc, sizeof(wc) / sizeof(wc[0]));
  fn_Draw_MessageA(h, 0, 0, &b2_2d_font.gt, &b2_2d_font.ts, wc, isection, &tx, &ty);

  xp = ftoi(((r.right - r.left) - tx) / 2.0f);  
  yp = 0;

  ddxTransparentBlt(hdc, r.left + xp, r.top + yp, tx, ty, h, 0, 0, tx, 90, TRANSCOLOR);

  ddxReleaseBitmap(h);

  return 1;
}
Ejemplo n.º 24
0
void Ninjarope::process(Worm& owner, Game& game)
{
	Common& common = *game.common;
	
	if(out)
	{
		pos += vel;
		
		auto ipos = ftoi(pos);
		
		anchor = 0;
		for(std::size_t i = 0; i < game.worms.size(); ++i)
		{
			Worm& w = *game.worms[i];
			
			if(&w != &owner
			&& checkForSpecWormHit(game, ipos.x, ipos.y, 1, w))
			{
				anchor = &w;
				break;
			}
		}
		
		fixedvec diff = pos - owner.pos;
		
		fixedvec force(
			(diff.x << LC(NRForceShlX)) / LC(NRForceDivX),
			(diff.y << LC(NRForceShlY)) / LC(NRForceDivY));
		
		curLen = (vectorLength(ftoi(diff.x), ftoi(diff.y)) + 1) << LC(NRForceLenShl);
		
		if(ipos.x <= 0
		|| ipos.x >= game.level.width - 1
		|| ipos.y <= 0
		|| ipos.y >= game.level.height - 1
		|| game.level.mat(ipos).dirtRock())
		{
			if(!attached)
			{
				length = LC(NRAttachLength);
				attached = true;
				
				if(game.level.inside(ipos))
				{
					if(game.level.mat(ipos).anyDirt())
					{
						PalIdx pix = game.level.pixel(ipos);
						for(int i = 0; i < 11; ++i) // TODO: Check 11 and read from exe
						{
							common.nobjectTypes[2].create2(
								game,
								game.rand(128),
								fixedvec(),
								pos,
								pix,
								owner.index,
								0);
						}
					}
				}
			}
			
			vel.zero();
		}
		else if(anchor)
		{
			if(!attached)
			{
				length = LC(NRAttachLength); // TODO: Should this value be separate from the non-worm attaching?
				attached = true;
			}
			
			if(curLen > length)
			{
				anchor->vel -= force / curLen;
			}
			
			vel = anchor->vel;
			pos = anchor->pos;
		}
		else
		{
			attached = false;
		}
		
		if(attached)
		{
			// curLen can't be 0

			if(curLen > length)
			{
				owner.vel += force / curLen;
			}
		}
		else
		{
			vel.y += LC(NinjaropeGravity);

			if(curLen > length)
			{
				vel -= force / curLen;
			}
		}
	}
}
Ejemplo n.º 25
0
polar2di::polar2di(VECT2DI src)
{
  float flenght;
  scalar2polar(src.x, src.y, &rotation, &flenght);
  length = ftoi(flenght);
}
Ejemplo n.º 26
0
void SObjectType::create(Game& game, int x, int y, int ownerIdx, WormWeapon* firedBy, WObject* from)
{
	Common& common = *game.common;
	SObject& obj = *game.sobjects.newObjectReuse();

	LTRACE(rand, 0, sobj, game.rand.x);
	LTRACE(sobj, &obj - game.sobjects.arr, cxpo, x);
	LTRACE(sobj, &obj - game.sobjects.arr, cypo, y);
	
	assert(numSounds < 10);
	
	if(startSound >= 0)
		game.soundPlayer->play(game.rand(numSounds) + startSound);
		
	for(std::size_t i = 0; i < game.viewports.size(); ++i)
	{
		Viewport& v = *game.viewports[i];
		
		if(x > v.x
		&& x < v.x + v.rect.width()
		&& y > v.y
		&& y < v.y + v.rect.height())
		{
			if(itof(shake) > v.shake)
				v.shake = itof(shake);
		}
	}
	
	obj.id = id;
	obj.x = x - 8;
	obj.y = y - 8;
	obj.curFrame = 0;
	obj.animDelay = animDelay;
	
	if(flash > game.screenFlash)
	{
		game.screenFlash = flash;
	}

	Worm* owner = game.wormByIdx(ownerIdx);

	game.statsRecorder->damagePotential(owner, firedBy, damage);
		
	if(damage > 0)
	{
		for(std::size_t i = 0; i < game.worms.size(); ++i)
		{
			Worm& w = *game.worms[i];
			
			int wix = ftoi(w.pos.x);
			int wiy = ftoi(w.pos.y);
			
			if(wix < x + detectRange
			&& wix > x - detectRange
			&& wiy < y + detectRange
			&& wiy > y - detectRange)
			{
				int delta = wix - x;
				int power = detectRange - std::abs(delta);
				int powerSum = power;
				
				if(std::abs(w.vel.x) < itof(2)) // TODO: Read from EXE
				{
					if(delta > 0)
						w.vel.x += blowAway * power;
					else
						w.vel.x -= blowAway * power;
				}
				
				delta = wiy - y;
				power = detectRange - std::abs(delta);
				powerSum = (powerSum + power) / 2;
				
				if(std::abs(w.vel.y) < itof(2)) // TODO: Read from EXE
				{
					if(delta > 0)
						w.vel.y += blowAway * power;
					else
						w.vel.y -= blowAway * power;
				}
				
				int z = damage * powerSum;
				if(detectRange)
					z /= detectRange;

				if (from && !from->hasHit)
				{
					game.statsRecorder->hit(owner, firedBy, &w);
					from->hasHit = true;
				}
					
				if(w.health > 0)
				{
					game.doDamage(w, z, ownerIdx);
					game.statsRecorder->damageDealt(owner, firedBy, &w, z, false);
						
					int bloodAmount = game.settings->blood * powerSum / 100;
					
					if(bloodAmount > 0)
					{
						for(int i = 0; i < bloodAmount; ++i)
						{
							int angle = game.rand(128);
							common.nobjectTypes[6].create2(
								game,
								angle,
								w.vel / 3,
								w.pos,
								0,
								w.index,
								firedBy);
						}
					}
					
					if(game.rand(3) == 0)
					{
						int snd = 18 + game.rand(3); // NOTE: MUST be outside the unpredictable branch below
						if(!game.soundPlayer->isPlaying(&w))
						{
							game.soundPlayer->play(snd, &w);
						}
					}
				}
			}
		} // for( ... worms ...
		
		int objBlowAway = blowAway / 3; // TODO: Read from EXE
		
		auto wr = game.wobjects.all();
		for (WObject* i; i = wr.next(); )
		{
			Weapon const& weapon = *i->type;
			
			if(weapon.affectByExplosions)
			{
				auto ipos = ftoi(i->pos);
				if(ipos.x < x + detectRange
				&& ipos.x > x - detectRange
				&& ipos.y < y + detectRange
				&& ipos.y > y - detectRange)
				{
					int delta = ipos.x - x;
					int power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.x += objBlowAway * power;
						else if(delta < 0)
							i->vel.x -= objBlowAway * power;
					}
					
					delta = ipos.y - y;
					power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.y += objBlowAway * power;
						else if(delta < 0)
							i->vel.y -= objBlowAway * power;
					}
					
					if(weapon.chainExplosion)
						i->blowUpObject(game, ownerIdx);
				}
			} // if( ... affectByExplosions ...
		} // for( ... wobjects ...
		
		auto nr = game.nobjects.all();
		for (NObject* i; i = nr.next(); )
		{
			NObjectType const& t = *i->type;
		
			if(t.affectByExplosions)
			{
				auto ipos = ftoi(i->pos);
				if(ipos.x < x + detectRange
				&& ipos.x > x - detectRange
				&& ipos.y < y + detectRange
				&& ipos.y > y - detectRange)
				{
					int delta = ipos.x - x;
					int power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.x += objBlowAway * power;
						else if(delta < 0)
							i->vel.x -= objBlowAway * power;
					}
					
					delta = ipos.y - y;
					power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.y += objBlowAway * power;
						else if(delta < 0)
							i->vel.y -= objBlowAway * power;
					}

					Common& common = *game.common;

					LTRACE(nobj, &*i - game.nobjects.arr, puxp, i->vel.x);
					LTRACE(nobj, &*i - game.nobjects.arr, puyp, i->vel.y);
				}
			}
		}
				
		{
			int width = detectRange / 2;
			
			gvl::rect rect(x - width, y - width, x + width + 1, y + width + 1);
			
			rect.intersect(game.level.rect());

			for(int y = rect.y1; y < rect.y2; ++y)
			for(int x = rect.x1; x < rect.x2; ++x)
			{
				if(game.level.mat(x, y).anyDirt()
				&& game.rand(8) == 0)
				{
					PalIdx pix = game.level.pixel(x, y);
					int angle = game.rand(128);
					common.nobjectTypes[2].create2(
						game,
						angle,
						fixedvec(),
						itof(gvl::ivec2(x, y)),
						pix, ownerIdx, firedBy);
				}
			}
		}
		
	} // if(damage ...
	
	if(dirtEffect >= 0)
	{
		drawDirtEffect(common, game.rand, game.level, dirtEffect, x - 7, y - 7);
		
		if(game.settings->shadow)
			correctShadow(common, game.level, gvl::rect(x - 10, y - 10, x + 11, y + 11));
	}
	
	auto br = game.bonuses.all();
	for (Bonus* i; i = br.next(); )
	{
		int ix = ftoi(i->x), iy = ftoi(i->y);
		
		if(ix > x - detectRange
		&& ix < x + detectRange
		&& iy > y - detectRange
		&& iy < y + detectRange)
		{
			game.bonuses.free(br);
			common.sobjectTypes[0].create(game, ix, iy, ownerIdx, firedBy);
		}
	} // for( ... bonuses ...
}
Ejemplo n.º 27
0
//==============================
// VertexBlockSortFn
// sort function for vertex blocks
int VertexBlockSortFn( void const * a, void const * b )
{
	return ftoi( ((vbSort_t const*)a)->DistanceSquared - ((vbSort_t const*)b)->DistanceSquared );
}
Ejemplo n.º 28
0
int cr_CreditsUNI(HWND hWnd, AUDIO_DATA * p_ad)
{
	DWORD	dwStart, dwStop, dwEplased = 0;
	int		y = 868;
	int		dy = 868*2 + 2000;
	char	text[256];
	char	cbmp[256];
	FILE	*file;
	int		c = 0;
	int		bmp = 0;
	RECT	r;
	float	f = p_ad->Music_Gain;
	int		i;
	CREDIT_SURFACE	cs[CREDIT_SURFACES];
	int		iActual = 0;
	int		iClock[12];
	APAK_HANDLE	*hArchive = NULL;
	int		error;

	for(i=0;i<12;i++)
		iClock[i] = -1;

	LoadClock(iClock);

	if(iClock[0] != -1)
	{
		ddxResizeCursorBack(iClock[0]);
		DrawClock(iClock, 0);
	}
	
	if(ogg_playing())
	{
		while(f >= 0.05f)
		{
			f -= 0.05f;
			ogg_gain(f);
			Sleep(25);
			DrawClock(iClock, 0);
		}

		ap_Stop_Song(p_ad);
	}

	for(i=0;i<CREDIT_SURFACES;i++)
	{
		cs[i].iSurface = -1;
		cs[i].x = 0;
		cs[i].y = 0;
	}

  strcpy(text,BITMAP_DIR);
	chdir(text);

	hArchive = apakopen(cFontFile[2], text, &error);
	
	if(!hArchive)
		return 0;
	else
		hArchive->pActualNode = hArchive->pRootNode->pNextNode;

	file = aopen(hArchive, "credits.txt", "r");

	if(!file)
		return 0;

	aunicode(file);

	while(!aeof(file))
	{
		agets(text, 256, file);
		c++;
	}

	DrawClock(iClock, 1);
	aseek(file, 2, SEEK_SET);

	dy += c * 75;
	
	if(c > CREDIT_SURFACES-1)
	{
		kprintf(1, "Kredity: radku je vic jak surfacu!");
		apakclose(&hArchive);
		return 0;
	}

	ddxSetFlip(0);
	fn_Set_Font(cFontFile[0]);
	DrawClock(iClock, 2);
	fn_Load_Bitmaps();
	DrawClock(iClock, 3);
	
	cs[iActual].iSurface = ddxLoadBitmap("anakreon_small.bmp", pBmpArchive);
	
	if(cs[iActual].iSurface == -1)
	{
		cr_Release_Bitmaps(cs, iClock);
		apakclose(&hArchive);
		return 0;
	}
	else
		cr_Set_Surface(&cs[iActual], y);

	DrawClock(iClock, 4);
	y+= 250;
	iActual++;
	
	cs[iActual].iSurface = ddxLoadBitmap("cinemax_small.bmp", pBmpArchive);

	if(cs[iActual].iSurface == -1)
	{
		cr_Release_Bitmaps(cs, iClock);
		apakclose(&hArchive);
		return 0;
	}
	else
		cr_Set_Surface(&cs[iActual], y);

	iActual++;
	y+= 768;

	DrawClock(iClock, 5);

	r.left = 0;
	r.right = 1024;
	r.top = 0;
	r.bottom = 90;

	while(!aeof(file))
	{
		ZeroMemory(text, 256);
		agets(text, 256, file);

		if(text[0] == '$')
		{
			if(bmp < 5)
			{
				if(bmp)
				{
					sprintf(cbmp, "brouk%d.bmp", bmp);
					cs[iActual].iSurface = ddxLoadBitmap(cbmp, pBmpArchive);

					if(cs[iActual].iSurface == -1)
					{
						cr_Release_Bitmaps(cs, iClock);
						apakclose(&hArchive);
						return 0;
					}
					else
					{
						cr_Set_Surface(&cs[iActual], y);
						y += ddxGetHight(cs[iActual].iSurface);
						iActual++;
					}
				}

				bmp++;
			}

			cs[iActual].iSurface = ddxCreateSurface(1024, 90, ddxFindFreeSurface());

			if(cs[iActual].iSurface == -1)
			{
				cr_Release_Bitmaps(cs, iClock);
				apakclose(&hArchive);
				return 0;
			}
			else
			{
				ddxCleareSurfaceColor(cs[iActual].iSurface, 0);
				cr_Set_Text_CenterW(cs[iActual].iSurface, (WCHAR *)text, 1, r);
				cs[iActual].y = y;
				iActual++;
			}
		}
		else
			if(strcmp(text,"\n") && strlen(text))
			{
				cs[iActual].iSurface = ddxCreateSurface(1024, 90, ddxFindFreeSurface());

				if(cs[iActual].iSurface == -1)
				{
					cr_Release_Bitmaps(cs, iClock);
					apakclose(&hArchive);
					return 0;
				}
				else
				{
					ddxCleareSurfaceColor(cs[iActual].iSurface, 0);
					cr_Set_Text_CenterW(cs[iActual].iSurface, (WCHAR *)text, 0, r);
					cs[iActual].y = y;
					iActual++;
				}
			}

		y += 80;

		if(iActual >= CREDIT_SURFACES)
		{
			kprintf(1, "iActual >= CREDIT_SURFACES !!!!!!!!!!!");
			break;
		}

		DrawClock(iClock, 6);
	}

	aclose(file);

	y = 0;

	ap_Play_Song(11,0, p_ad);

	ddxResizeCursorBack(0);
	ddxSetCursorSurface(0);

	for(i=0;i<12;i++)
		if(iClock[i] != -1)
		{
			ddxReleaseBitmap(iClock[i]);
			iClock[i] = -1;
		}

	ddxSetCursor(0);
	dwStart = timeGetTime();

	while(!key[K_ESC])
	{
		y = (int)ftoi((dwEplased * dy) / (float) 195000);
	
		if(y >=  dy)
			key[K_ESC] = 1;

		cr_Draw_Creadits(cs, y);

		dwStop = timeGetTime();
		dwEplased = dwStop - dwStart;

		ddxRestore(p_ad);
	}

	cr_Release_Bitmaps(cs, iClock);
	fn_Release_Font(1);

	if(ogg_playing())
		ap_Stop_Song(p_ad);

	//Sleep(1000);
	ap_Play_Song(0, 0, p_ad);

	ddxSetCursor(1);
	ddxSetFlip(1);
	key[K_ESC] = 0;
	apakclose(&hArchive);

  return 0;
}
Ejemplo n.º 29
0
uint distance(plansys a,plansys b)
/* Seperation between two planets (4*sqrt(X*X+Y*Y/4)) */
{	return (uint)ftoi(4*sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)/4));
}
Ejemplo n.º 30
0
void DepthBuffer::binTriangles4Simd(vec4f vertices[12],uint32 count) {
	enum { kNumLanes = 4 };

	VecF32Soa transformedPos[3];
	gather4Simd(transformedPos,(VecF32*)vertices);

	VecS32 vertexX[3],vertexY[3];
	VecF32 vertexZ[3];

	for(int i = 0;i<3;i++){
		//Convert the floating point coordinates to integer screen space coordinates.
		//NB: truncate
		vertexX[i] = ftoi(transformedPos[i].x);
		vertexY[i] = ftoi(transformedPos[i].y);

		vertexZ[i] = transformedPos[i].z;
	}

	//Compute triangle area.
	VecS32 area = (vertexX[1] - vertexX[0]) * (vertexY[2] - vertexY[0]) - (vertexX[0] - vertexX[2]) * (vertexY[0] - vertexY[1]);
	VecF32 oneOverArea = VecF32(1.0f)/itof(area);

	//Setup Z for interpolation
	vertexZ[1] = (vertexZ[1] - vertexZ[0]) * oneOverArea;
	vertexZ[2] = (vertexZ[2] - vertexZ[0]) * oneOverArea;

	//Find bounding box for the screen space triangle
	VecS32 zero = VecS32(0);
	VecS32 minX = vmax( vmin(vmin(vertexX[0],vertexX[1]),vertexX[2]), zero);
	VecS32 maxX = vmin( vmax(vmax(vertexX[0],vertexX[1]),vertexX[2]), VecS32(size_.x-1) );
	VecS32 minY = vmax( vmin(vmin(vertexY[0],vertexY[1]),vertexY[2]), zero);
	VecS32 maxY = vmin( vmax(vmax(vertexY[0],vertexY[1]),vertexY[2]), VecS32(size_.y-1) );

	uint32 numLanes = std::min(count,uint32(kNumLanes));
	for(uint32 i =0;i<numLanes;++i){
		//Skip triangle if the area is zero
		if(area.lane[i] <= 0) continue;

		float oneOverW[3];
		for(int j = 0;j<3;++j){
			oneOverW[j] = transformedPos[j].w.lane[i];
		}

		// Reject the triangle if any of its verts is behind the nearclip plane
		if(oneOverW[0] == 0.0f || oneOverW[1] == 0.0f || oneOverW[2] == 0.0f) continue;

		//Convert bounding box in terms of pixels to bounding box in terms of tiles.
		int32 tileMinX = minX.lane[i]/tileSize_.x;//std::max(minX.lane[i]/tileSize_.x,0);
		int32 tileMaxX = maxX.lane[i]/tileSize_.x;//std::min(maxX.lane[i]/tileSize_.x,tileCount_.x);
		int32 tileMinY = minY.lane[i]/tileSize_.y;//std::max(minY.lane[i]/tileSize_.y,0);
		int32 tileMaxY = maxY.lane[i]/tileSize_.y;//std::min(maxY.lane[i]/tileSize_.y,tileCount_.y);

		for(;tileMinY <= tileMaxY;tileMinY++){
			auto tileIndex = tileMinX + tileMinY*tileCount_.x;
		for(auto x = tileMinX; x<= tileMaxX; x++,tileIndex++){
			auto count = tileTriangleCount_[tileIndex];
			if(count >= kMaxTrianglesPerTile) continue;
			tileTriangleCount_[tileIndex]++;

			BinnedTriangle& triangle =*( triangleBins_ + count + x*kMaxTrianglesPerTile + tileMinY*tileCount_.x*kMaxTrianglesPerTile);
			triangle.v[0].x = vertexX[0].lane[i];
			triangle.v[0].y = vertexY[0].lane[i];
			triangle.v[1].x = vertexX[1].lane[i];
			triangle.v[1].y = vertexY[1].lane[i];
			triangle.v[2].x = vertexX[2].lane[i];
			triangle.v[2].y = vertexY[2].lane[i];
			triangle.z[0] = vertexZ[0].lane[i];
			triangle.z[1] = vertexZ[1].lane[i];
			triangle.z[2] = vertexZ[2].lane[i];
		} }
	}
}