Esempio n. 1
0
void
scrollable_widget_rep::handle_get_coord4 (get_coord4_event ev) {
  if      (ev->which == "visible") {
    ev->c1= scx - get_dx (grav, w);
    ev->c2= scy - get_dy (grav, h) - h;
    ev->c3= scx - get_dx (grav, w) + w;
    ev->c4= scy - get_dy (grav, h);
  }
  else if (ev->which == "extents") {
    ev->c1= ex1; ev->c2= ey1;
    ev->c3= ex2; ev->c4= ey2;
  }
  else attribute_widget_rep::handle_get_coord4 (ev);
}
Esempio n. 2
0
int setup(void)
{
#ifdef PS2
    evfd = open("/dev/ps2event", O_RDONLY);
    if (evfd < 0) { perror("/dev/ps2event: open"); return 1; }
    ioctl(evfd, PS2IOC_ENABLEEVENT, PS2EV_VSYNC);
    dx = get_dx();
    dy = get_dy();
#endif /* PS2 */

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
    cleaned_up = 0;
    atexit(cleanup);

    /*
     * Set the video mode up.
     */
    screen = SDL_SetVideoMode(SCR_WIDTH*XMULT, SCR_HEIGHT*YMULT,
			      8, SDL_SWSURFACE);
    if (!screen) {
	printf("SDL screen initialisation error: %s\n", SDL_GetError());
	return 1;
    }
    SDL_ShowCursor(SDL_DISABLE);
}
Esempio n. 3
0
/* Generic "growing-wall" special (callback) */
static void growing_wall_callback(game_t *p_game, int id, void *p_priv_in)
{
  growing_wall_priv_t *p_priv = (growing_wall_priv_t*)p_priv_in;
  point_t new_pt = pt_add_dir(p_priv->pt, get_dx(p_priv->dir));
  mask_tile_t *p_mask_tile;
  tile_t *p_tile;

  /* Reduce the speed */
  if ( !(p_priv->toggle = !p_priv->toggle) )
    return;

  assert(pt_in_rect(new_pt, pt(0,0), pt(p_game->p_cur_level->w, p_game->p_cur_level->h)));

  p_tile = &p_game->p_cur_level->p_level_data[new_pt.y * p_game->p_cur_level->w + new_pt.x];
  p_mask_tile = &MTILE_AT(p_game, new_pt.x, new_pt.y);

  if (!MASK_TILE_IS_WALKABLE(*p_mask_tile))
    {
      status_enqueue_message(p_game, "THE ROARING STOPS");
      callback_unregister(p_game, p_priv->id);
      return;
    }

  p_priv->pt = new_pt;
  *p_tile = p_priv->tile;
  p_mask_tile->id = MASK_ID(p_priv->tile);
}
Esempio n. 4
0
	std::array<double, Ndim> get_position() const {
		std::array<double, Ndim> pos;
		const double dx = get_dx();
		for (int i = 0; i < Ndim; i++) {
			pos[i] = loc[i] * dx;
		}
		return pos;
	}
float AbstractFormConfigurationTuple::get_absolute_area_improvement()
{
	float sum_of_areas_of_boxes_of_contained_forns = 0;
	for (int i=0; i<abstract_form_configs.size(); ++i)
	{
		sum_of_areas_of_boxes_of_contained_forns += abstract_form_configs[i].get_dx() * abstract_form_configs[i].get_dy();
	}

	return sum_of_areas_of_boxes_of_contained_forns - get_dx() * get_dy();
}
Esempio n. 6
0
void view::rtransform(int& x, int& y) {
    int dx = - get_dx();
    int dy = - get_dy();
    double scale = 1.0 / get_scale();

    x += dx;
    y += dy;

    x *= scale;
    y *= scale;
}
Esempio n. 7
0
void view::transform(int& x, int& y) {
    int dx = get_dx();
    int dy = get_dy();
    double scale = get_scale();

    x *= scale;
    y *= scale;

    x += dx;
    y += dy;
}
Esempio n. 8
0
void view::transform(int& x, int& y, int& w, int& h, int& r) {
    int dx = get_dx();
    int dy = get_dy();
    double scale = get_scale();

    x *= scale;
    y *= scale;
    w *= scale;
    h *= scale;
    r *= scale;

    x += dx;
    y += dy;
}
/**
 * @brief Recursive function to generate a maze.
 *
 * @param[in] cx Starting x-coordinate.
 * @param[in] cy Starting y-coordinate.
 */
void RecursiveBacktracker::carve_passages_from(int cx, int cy)
{
    int i, nx, ny, directions[] = {N, S, E, W};
    shuffle_array(directions, NUM_DIRECTIONS);

    for (i = 0; i < NUM_DIRECTIONS; i++)
    {
        nx = cx + get_dx(directions[i]);
        ny = cy + get_dy(directions[i]);

        if ((nx >= 0 && nx < WIDTH) && (ny >= 0 && ny < HEIGHT)
            && maze->grid[nx][ny] == 0)
        {
            maze->grid[cx][cy] |= directions[i];
            maze->grid[nx][ny] |= get_opposite(directions[i]);

            carve_passages_from(nx, ny);
        }
    }
}
Esempio n. 10
0
int main(int argc, char **argv)
{
    SDL_Surface *screen;
    SDL_AudioSpec audio_wanted;
    int frame;
    int evfd;
    int x, y;

    evfd = open("/dev/ps2event", O_RDONLY);
    if (evfd < 0) { perror("/dev/ps2event: open"); return 1; }
    ioctl(evfd, PS2IOC_ENABLEEVENT, PS2EV_VSYNC);

    dx = get_dx();
    dy = get_dy();
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
    atexit(cleanup);

    if (argc > 1 && !strcmp(argv[1], "-j")) {
	int i;
	SDL_Event event;
	SDL_Joystick *joystick;

	printf("%d joysticks were found.\n\n", SDL_NumJoysticks() );
	printf("The names of the joysticks are:\n");
	for (i=0; i < SDL_NumJoysticks(); i++) {
	    printf("    %s\n", SDL_JoystickName(i));
	}

	joystick = SDL_JoystickOpen(0);
	printf("Joystick 0 has %d axes\n", SDL_JoystickNumAxes(joystick));
	printf("Joystick 0 has %d buttons\n", SDL_JoystickNumButtons(joystick));
	printf("Joystick 0 has %d balls\n", SDL_JoystickNumBalls(joystick));
	printf("Joystick 0 has %d hats\n", SDL_JoystickNumHats(joystick));

	while(SDL_WaitEvent(&event)) {
	    switch(event.type) {
	      case SDL_JOYAXISMOTION:
		printf("Axis %d %d\n", event.jaxis.axis, event.jaxis.value);
		break;
	      case SDL_JOYBUTTONDOWN:
		printf("Button %d down\n", event.jbutton.button);
		break;
	      case SDL_JOYBUTTONUP:
		printf("Button %d up\n", event.jbutton.button);
		break;
	      case SDL_KEYDOWN:
		goto done;
		break;
	    }
	}
	done:

	return 0;
    }

    /*
     * Set the audio device up.
     */
    audio_wanted.freq = 22050;
    audio_wanted.format = AUDIO_S8;
    audio_wanted.channels = 1;    /* 1 = mono, 2 = stereo */
    audio_wanted.samples = 1024;  /* Good low-latency value for callback */
    audio_wanted.callback = fill_audio;
    audio_wanted.userdata = NULL;
    if ( SDL_OpenAudio(&audio_wanted, NULL) < 0 ) {
        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
        return 1;
    }

    /*
     * Set the video mode up.
     */
    screen = SDL_SetVideoMode(SCR_WIDTH*XMULT, SCR_HEIGHT*YMULT,
			      8, SDL_SWSURFACE);
    if (!screen) {
	printf("SDL screen initialisation error: %s\n", SDL_GetError());
	return 1;
    }
    SDL_ShowCursor(SDL_DISABLE);

    if (SDL_MUSTLOCK(screen))
	SDL_LockSurface(screen);
    for (x = 0; x < SCR_WIDTH*XMULT; x++) {
	for (y = 0; y < SCR_HEIGHT*YMULT; y++) {
	    putpixel(screen, x, y,
		     SDL_MapRGB(screen->format, (x*10)&255,
				(y*10)&255, ((x+y+frame)*10)&255));
	}
    }
    if (SDL_MUSTLOCK(screen))
	SDL_UnlockSurface(screen);

    SDL_PauseAudio(0);

    for (frame = 1; frame < 256; frame++) {
	SDL_Rect r1 = { 0, 0, SCR_WIDTH*XMULT-1, SCR_HEIGHT*YMULT };
	SDL_Rect r2 = { 1, 0, SCR_WIDTH*XMULT-1, SCR_HEIGHT*YMULT };
	
	if (SDL_MUSTLOCK(screen))
	    SDL_LockSurface(screen);
//	for (x = 0; x < SCR_WIDTH*XMULT; x++) {
	    for (y = 0; y < SCR_HEIGHT*YMULT; y++) {
		memmove(screen->pixels + y * screen->pitch,
			screen->pixels + y * screen->pitch + screen->format->BytesPerPixel,
			(SCR_WIDTH*XMULT-1) * screen->format->BytesPerPixel);
		putpixel(screen, SCR_WIDTH*XMULT-1, y, 0);
		//putpixel(screen, x, y, (x==SCR_WIDTH*XMULT-1 ? 0 :
		//			getpixel(screen, x+1, y)));
	    }
//	}
	if (SDL_MUSTLOCK(screen))
	    SDL_UnlockSurface(screen);
	//SDL_UpdateRect(screen, frame*2, 0, 2, SCR_HEIGHT*YMULT);
	SDL_Flip(screen);
	{
	    long long t = bigclock();
	    ioctl(evfd, PS2IOC_WAITEVENT, PS2EV_VSYNC);
	    sparetime += bigclock() - t;
	}
    }

    return 0;
}
Esempio n. 11
0
void BinaryStar::set_refine_flags() {
    double refine_adjustment = 1;
    ChildIndex c;
    if (get_level() < 1) {
        for (int i = 0; i < OCT_NCHILD; i++) {
            set_refine_flag(i, true);
        }
    } else if (get_level() < get_max_level_allowed()) {
        Real mass_min, dxmin, vmin, this_mass;
        dxmin = dynamic_cast<BinaryStar*>(get_root())->get_dx() / Real(1 << OctNode::get_max_level_allowed());
        vmin = dxmin * dxmin * dxmin;
        mass_min = refine_floor * vmin * refine_adjustment;
        for (int k = BW; k < GNX - BW; k++) {
            c.set_z(2 * k / GNX);
            for (int j = BW; j < GNX - BW; j++) {
                c.set_y(2 * j / GNX);
                for (int i = BW; i < GNX - BW; i++) {
                    c.set_x(2 * i / GNX);
#ifdef REFINE_ACC_MORE
                    if ((get_level() == get_max_level_allowed() - 1 && (*this)(i, j, k).frac(0) > refine_floor * refine_adjustment)
                            || get_level() < get_max_level_allowed() - 1) {
#else
                        if (get_level() < get_max_level_allowed()) {
#endif
                        if (!get_refine_flag(c)) {
                            //              set_refine_flag(c, true);
                            Real ra = (X(i, j, k) - bparam.x1).mag();
                            Real rd = (X(i, j, k) - bparam.x2).mag();
                            if ((*this)(i, j, k).rho() > refine_floor * refine_adjustment) {
                                set_refine_flag(c, true);
                            } else if (get_time() == 0.0 && (ra < get_dx() || rd < get_dx())) {
                                set_refine_flag(c, true);
                            } else/* if (get_time() != 0.0)*/{
                                this_mass = pow(get_dx(), 3) * (*this)(i, j, k).rho();
                                if (this_mass > mass_min) {
                                    set_refine_flag(c, true);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
/*
 void BinaryStar::set_refine_flags() {
 ChildIndex c;
 if (get_level() < 1) {
 for (int i = 0; i < OCT_NCHILD; i++) {
 set_refine_flag(i, true);
 }
 } else if (get_level() < get_max_level_allowed()) {
 Real mass_min, dxmin, vmin, this_mass;
 dxmin = dynamic_cast<BinaryStar*>(get_root())->get_dx() / Real(1 << OctNode::get_max_level_allowed());
 vmin = dxmin * dxmin * dxmin;
 mass_min = refine_floor * vmin;
 for (int k = BW; k < GNX - BW; k++) {
 c.set_z(2 * k / GNX);
 for (int j = BW; j < GNX - BW; j++) {
 c.set_y(2 * j / GNX);
 for (int i = BW; i < GNX - BW; i++) {
 c.set_x(2 * i / GNX);
 if ((get_level() == get_max_level_allowed() - 1 && (*this)(i, j, k).frac(0) > refine_floor) || get_level() < get_max_level_allowed() - 1) {
 if (!get_refine_flag(c)) {
 //		set_refine_flag(c, true);
 Real ra = (X(i, j, k) - a0).mag();
 Real rd = (X(i, j, k) - d0).mag();
 if ((*this)(i, j, k).rho() > refine_floor) {
 set_refine_flag(c, true);
 } else if (get_time() == 0.0 && (ra < get_dx() || rd < get_dx())) {
 set_refine_flag(c, true);
 } else{
 this_mass = pow(get_dx(), 3) * (*this)(i, j, k).rho();
 if (this_mass > mass_min) {
 set_refine_flag(c, true);
 }
 }
 }
 }
 }
 }
 }
 }
 }
 */

void BinaryStar::initialize() {
    if (!bparam_init) {
        bparam_init = true;
        bparam.fill_factor = 0.97;
        binary_parameters_compute(&bparam);
        State::rho_floor = 1.0e-12 * bparam.rho1;
        refine_floor = 1.0e-4 * bparam.rho1;
        dynamic_cast<HydroGrid*>(get_root())->HydroGrid::mult_dx(bparam.a * 5.0);
#ifndef USE_FMM
        dynamic_cast<MultiGrid*>(get_root())->MultiGrid::mult_dx(bparam.a * 5.0);
#endif
        State::set_omega(bparam.omega);
    }
    for (int k = BW - 1; k < GNX - BW + 1; k++) {
        for (int j = BW - 1; j < GNX - BW + 1; j++) {
            for (int i = BW - 1; i < GNX - BW + 1; i++) {
                int id;
                State U = Vector<Real, STATE_NF>(0.0);
                Real R2 = (xc(i) * xc(i) + yc(j) * yc(j));
                Real rho = density_at(&bparam, xc(i), yc(j), zc(k), &id);
                rho = max(rho, State::rho_floor);
                Real tau = pow(State::ei_floor, 1.0 / State::gamma);
                U.set_rho(rho);
                U.set_et(U.ed());
                U.set_tau(tau);
                U.set_sx(0.0);
                U.set_sy(bparam.omega * R2 * U.rho());
                U.set_sz(0.0);
                if (id == 1) {
                    U.set_frac(0, U.rho());
                    U.set_frac(1, 0.0);
                } else if (id == -1) {
                    U.set_frac(1, U.rho());
                    U.set_frac(0, 0.0);
                } else {
                    U.set_frac(1, 0.0);
                    U.set_frac(0, 0.0);
                }
                (*this)(i, j, k) = U;
            }
        }
    } /*Real K, E1, E2, period, rho_c1, rho_c2;
     a0 = d0 = 0.0;
     if (scf_code) {
     const Real a = 0.075;
     const Real R2 = 0.0075;
     const Real n = 1.5;
     rho_c2 = q_ratio * M1 * (pow(3.65375 / R2, 3.0) / (2.71406 * 4.0 * M_PI));
     rho_c1 = rho_c2 / pow(q_ratio, 2.0 * n / (3.0 - n));

     a0[0] = a * q_ratio / (q_ratio + 1.0);
     d0[0] = -a / (q_ratio + 1.0);
     K = pow(R2 / 3.65375, 2) * 4.0 * M_PI / (2.5) * pow(rho_c2, 1.0 / 3.0);
     Ka = Kd = (5.0 / 8.0) * K;
     polyK = K;
     E1 = 1.0 / (sqrt((4.0 * M_PI * pow(rho_c1, 1.0 - 1.0 / n)) / ((n + 1.0) * K)));
     E2 = 1.0 / (sqrt((4.0 * M_PI * pow(rho_c2, 1.0 - 1.0 / n)) / ((n + 1.0) * K)));
     //	printf("%e %e %e %e\n", rho_c1, rho_c2, E1, E2);
     period = sqrt(pow(a, 3) / (q_ratio + 1.0) / M1) * 2.0 * M_PI;
     } else {
     rho_c1 = rho_c2 = 1.0;
     a0[0] = 0.025;
     d0[0] = -0.025;
     E1 = E2 = 0.0015;
     K = pow(E1, 2) * 4.0 * M_PI / (2.5);
     period = sqrt(pow((a0 - d0).mag(), 3) / 2.303394e-07) * 2.0 * M_PI;
     }
     State U;
     Real d, e, gamma, tau;
     gamma = 5.0 / 3.0;
     Real ra, rd, r0, ek;
     _3Vec v;
     const Real Omega = 2.0 * M_PI / period;
     State::set_omega(Omega);
     Real f1, f2;
     if (get_level() == 0) {
     printf("Period = %e Omega = %e\n", period, Omega);
     }
     Real d_floor = 10.0 * State::rho_floor;
     for (int k = BW - 1; k < GNX - BW + 1; k++) {
     for (int j = BW - 1; j < GNX - BW + 1; j++) {
     for (int i = BW - 1; i < GNX - BW + 1; i++) {
     U = Vector<Real, STATE_NF>(0.0);
     ra = (X(i, j, k) - a0).mag();
     rd = (X(i, j, k) - d0).mag();
     d = +rho_c1 * pow(lane_emden(ra / E1), 1.5);
     d += rho_c2 * pow(lane_emden(rd / E2), 1.5);
     d = max(d, d_floor);
     if (ra < rd) {
     f1 = d - d_floor / 2.0;
     f2 = d_floor / 2.0;
     } else {
     f2 = d - d_floor / 2.0;
     f1 = d_floor / 2.0;
     }
     if (State::cylindrical) {
     Real R2 = (HydroGrid::xc(i) * HydroGrid::xc(i) + HydroGrid::yc(j) * HydroGrid::yc(j));
     v[0] = 0.0;
     v[1] = R2 * State::get_omega();
     } else {
     v[0] = -HydroGrid::yc(j) * State::get_omega();
     v[1] = +HydroGrid::xc(i) * State::get_omega();

     }
     v[2] = 0.0;
     e = K * pow(d, gamma) / (gamma - 1.0);
     tau = pow(e, 1.0 / gamma);
     U.set_rho(d);
     U.set_frac(0, f1);
     U.set_frac(1, f2);
     U.set_et(e);
     U.set_tau(tau);
     U.set_sx(d * v[0]);
     U.set_sy(d * v[1]);
     U.set_sz(d * v[2]);
     (*this)(i, j, k) = U;
     }
     }
     }
     */
}
Esempio n. 12
0
void BinaryStar::compute_flow_off() {
    const Real da = get_dx() * get_dx();
    int k, j, i;
    static State this_DFO;
    this_DFO = Vector<Real, STATE_NF>(0.0);
    for (k = BW; k < GNX - BW; k++) {
        for (j = BW; j < GNX - BW; j++) {
            for (i = BW; i < GNX - BW; i++) {
                if (!zone_is_refined(i, j, k)) {
                    if (is_phys_bound(XL) && i == BW) {
                        this_DFO -= (get_flux(0, i, j, k)) * da;
                    }
                    if (is_phys_bound(XU) && i == GNX - BW - 1) {
                        this_DFO += (get_flux(0, i + 1, j, k)) * da;
                    }
                    if (is_phys_bound(YL) && j == BW) {
                        this_DFO -= (get_flux(1, i, j, k)) * da;
                    }
                    if (is_phys_bound(YU) && j == GNX - BW - 1) {
                        this_DFO += (get_flux(1, i, j + 1, k)) * da;
                    }
                    if (is_phys_bound(ZL) && k == BW) {
                        this_DFO -= (get_flux(2, i, j, k)) * da;
                    }
                    if (is_phys_bound(ZU) && k == GNX - BW - 1) {
                        this_DFO += (get_flux(2, i, j, k + 1)) * da;
                    }
                    if (!State::cylindrical) {
                        const int lx = State::sx_index;
                        const int ly = State::sy_index;
                        this_DFO[ly] = 0.0;
                        if (is_phys_bound(XL) && i == BW) {
                            this_DFO[ly] -= (get_flux(0, i, j, k))[ly] * da * HydroGrid::xf(i);
                            this_DFO[ly] += (get_flux(0, i, j, k))[lx] * da * HydroGrid::yc(j);
                        }
                        if (is_phys_bound(XU) && i == GNX - BW - 1) {
                            this_DFO[ly] += (get_flux(0, i + 1, j, k))[ly] * da * HydroGrid::xf(i + 1);
                            this_DFO[ly] -= (get_flux(0, i + 1, j, k))[lx] * da * HydroGrid::yc(j + 1);
                        }
                        if (is_phys_bound(YL) && j == BW) {
                            this_DFO[ly] -= (get_flux(1, i, j, k))[ly] * da * HydroGrid::xc(i);
                            this_DFO[ly] += (get_flux(1, i, j, k))[lx] * da * HydroGrid::yc(j);
                        }
                        if (is_phys_bound(YU) && j == GNX - BW - 1) {
                            this_DFO[ly] += (get_flux(1, i, j + 1, k))[ly] * da * HydroGrid::xc(i);
                            this_DFO[ly] -= (get_flux(1, i, j + 1, k))[lx] * da * HydroGrid::yc(j);
                        }
                        if (is_phys_bound(ZL) && k == BW) {
                            this_DFO[ly] -= (get_flux(2, i, j, k))[ly] * da * HydroGrid::xc(i);
                            this_DFO[ly] += (get_flux(2, i, j, k))[lx] * da * HydroGrid::yc(j);
                        }
                        if (is_phys_bound(ZU) && k == GNX - BW - 1) {
                            this_DFO[ly] += (get_flux(2, i, j, k + 1))[ly] * da * HydroGrid::xc(i);
                            this_DFO[ly] -= (get_flux(2, i, j, k + 1))[lx] * da * HydroGrid::yc(j);
                        }
                    }
                }
            }
        }
    }
    DFO += this_DFO;
}
Esempio n. 13
0
	double get_position(int di) const {
		double pos;
		const double dx = get_dx();
		pos = loc[di] * dx;
		return pos;
	}
Esempio n. 14
0
void sprite_move(sprite_t *p_sprite, dir_t dir)
{
  p_sprite->pt.x += get_dx(dir)*TILE_W;
  p_sprite->pt.y += get_dy(dir)*TILE_H;
}