コード例 #1
0
        large_rocky_body::large_rocky_body(const config_record & obj_config)
            : celestial_body(obj_config)
        {
            unset_flags(get_draw_flags(), NODE_DRAW_UNLIT);

            // create rotating lithosphere (the rotating body will delete its rotator)
            body_rotator *rotator = !obj_config[L"rotator"].is_empty() ? rotator = dynamic_cast<body_rotator *>(broker::global_instance()->create_object(obj_config[L"rotator"], obj_config)) : 0;
            get_rotating_frame() = get_lithosphere() = new large_lithosphere(get_name() + L" lithosphere [rotating frame]", this, rotator);

            // create atmosphere if present
            if (!obj_config[L"atmosphere_depth"].is_empty())
            {
                get_atmosphere() = new rocky_body_atmosphere(get_name() + L" atmosphere [rotating]", get_lithosphere(), 0);
            }
        } // large_rocky_body()
コード例 #2
0
ファイル: ppsctl.c プロジェクト: gdbdzgd/pps-tools
static inline int set_flags()
{
	struct timex tmx = { .modes = 0 };

	if (adjtimex(&tmx) == -1) {
		fprintf(stderr, "adjtimex get failed: %s\n", strerror(errno));
		return -1;
	}

	tmx.modes = ADJ_STATUS;
	tmx.status |= (STA_PPSFREQ | STA_PPSTIME);

	if (adjtimex(&tmx) == -1) {
		fprintf(stderr, "adjtimex set failed: %s\n", strerror(errno));
		return -1;
	}

	return 0;
}

static inline int unset_flags()
{
	struct timex tmx = { .modes = 0 };

	if (adjtimex(&tmx) == -1) {
		fprintf(stderr, "adjtimex get failed: %s\n", strerror(errno));
		return -1;
	}

	tmx.modes = ADJ_STATUS;
	tmx.status &= ~(STA_PPSFREQ | STA_PPSTIME);

	if (adjtimex(&tmx) == -1) {
		fprintf(stderr, "adjtimex set failed: %s\n", strerror(errno));
		return -1;
	}

	return 0;
}

static inline void usage(char *name)
{
	fprintf(stderr, "Usage: %s [-bBfFac] <ppsdev>\n"
			"Commands:\n"
			"  -b   bind kernel PPS consumer\n"
			"  -B   unbind kernel PPS consumer\n"
			"  -f   set kernel NTP PPS flags\n"
			"  -F   unset kernel NTP PPS flags\n"
			"Options:\n"
			"  -a   use assert edge\n"
			"  -c   use clear edge (default)\n",
			name);
}

static void parse_args(int argc, char **argv)
{
	while (1)
	{
		int c;
		/* getopt_long stores the option index here. */
		int option_index = 0;
		static struct option long_options[] =
		{
			{"bind",		no_argument,		0, 'b'},
			{"unbind",		no_argument,		0, 'B'},
			{"set-flags",		no_argument,		0, 'f'},
			{"unset-flags",		no_argument,		0, 'F'},
			{"assert",		no_argument,		0, 'a'},
			{"clear",		no_argument,		0, 'c'},
			{"help",		no_argument,		0, 'h'},
			{0, 0, 0, 0}
		};

		c = getopt_long(argc, argv, "bBfFach", long_options, &option_index);

		/* detect the end of the options. */
		if (c == -1)
			break;

		switch (c)
		{
			case 'b': {
					do_bind = 1;
					break;
				}
			case 'B': {
					do_bind = 2;
					break;
				}
			case 'f': {
					do_setflags = 1;
					break;
				}
			case 'F': {
					do_setflags = 2;
					break;
				}
			case 'a': {
					opt_edge = PPS_CAPTUREASSERT;
					break;
				}
			case 'c': {
					opt_edge = PPS_CAPTURECLEAR;
					break;
				}
			case 'h': {
					usage(argv[0]);
					exit(0);
				}
			default: {
					usage(argv[0]);
					exit(1);
				}
		}
	}

	if ((do_bind == 0) && (do_setflags == 0)) {
		printf("No command specified!\n");
		usage(argv[0]);
		exit(1);
	}

	if (optind == argc - 1) {
		device = argv[optind];
	} else {
		printf("Device name missing!\n");
		usage(argv[0]);
		exit(1);
	}
}

int main(int argc, char *argv[])
{
	pps_handle_t handle;
	int avail_mode;

	/* Check the command line */
	parse_args(argc, argv);

	if (find_source(device, &handle, &avail_mode) < 0)
		exit(EXIT_FAILURE);

	if (do_setflags == 2)
		if (unset_flags() < 0) {
			fprintf(stderr, "Failed to unset flags!\n");
			exit(EXIT_FAILURE);
		}

	if (do_bind == 2)
		if (bind(handle, 0) < 0) {
			fprintf(stderr, "Unbind failed: %s\n", strerror(errno));
			exit(EXIT_FAILURE);
		}

	if (do_bind == 1)
		if (bind(handle, opt_edge) < 0) {
			fprintf(stderr, "Bind failed: %s\n", strerror(errno));
			exit(EXIT_FAILURE);
		}

	if (do_setflags == 1)
		if (set_flags() < 0) {
			fprintf(stderr, "Failed to set flags!\n");
			exit(EXIT_FAILURE);
		}

	time_pps_destroy(handle);

	return 0;
}
コード例 #3
0
ファイル: perfroll.cpp プロジェクト: Stazed/seq32
bool
perfroll::on_focus_out_event(GdkEventFocus*)
{
    unset_flags(Gtk::HAS_FOCUS);
    return false;
}
コード例 #4
0
void item::load_info( const std::string &data )
{
    std::istringstream dump(data);
    char check=dump.peek();
    if ( check == ' ' ) {
        // sigh..
        check=data[1];
    }
    if ( check == '{' ) {
        JsonIn jsin(dump);
        try {
            deserialize(jsin);
        } catch( const JsonError &jsonerr ) {
            debugmsg("Bad item json\n%s", jsonerr.c_str() );
        }
        return;
    }

    unset_flags();
    clear_vars();
    std::string idtmp, ammotmp, item_tag, mode;
    int lettmp, damtmp, acttmp, corp, tag_count;
    int owned; // Ignoring an obsolete member.
    dump >> lettmp >> idtmp >> charges >> damtmp >> tag_count;
    for( int i = 0; i < tag_count; ++i )
    {
        dump >> item_tag;
        if( itag2ivar(item_tag, item_vars ) == false ) {
            item_tags.insert( item_tag );
        }
    }

    dump >> burnt >> poison >> ammotmp >> owned >> bday >>
         mode >> acttmp >> corp >> mission_id >> player_id;
    corpse = NULL;
    getline(dump, corpse_name);
    if( corpse_name == " ''" ) {
        corpse_name = "";
    } else {
        size_t pos = corpse_name.find_first_of( "@@" );
        while (pos != std::string::npos)  {
            corpse_name.replace( pos, 2, "\n" );
            pos = corpse_name.find_first_of( "@@" );
        }
        corpse_name = corpse_name.substr( 2, corpse_name.size() - 3 ); // s/^ '(.*)'$/\1/
    }
    gun_set_mode( mode );

    if( idtmp == "UPS_on" ) {
        idtmp = "UPS_off";
    } else if( idtmp == "adv_UPS_on" ) {
        idtmp = "adv_UPS_off" ;
    }
    convert( idtmp );

    invlet = char(lettmp);
    set_damage( damtmp );
    active = false;
    if (acttmp == 1) {
        active = true;
    }
}
コード例 #5
0
void update_bee(int idx, Boid *boids)
{
	const float MAX_A = 0.1f;
	const float MAX_V = 1.5f;
	float goto_x = 0, goto_y = 0, goto_z = 0, goto_n = 0;
	float away_x = 0, away_y = 0, away_z = 0, away_n = 0;
	float vx = 0, vy = 0, vz = 0;
	float dx, dy, dz;

	int mx = bee_target.x;
	int my = bee_target.y;

	if (boids[idx].x > mx+25 && bee_chase) {
		if (General::rand() % 3) {
			float a;
			a = General::rand() / (float)UINT_MAX
				* M_PI/2;
			if (General::rand() % 2) {
				a += M_PI * 3 / 2;
			}
			float x = cos(a) * MAX_V;
			float y = sin(a) * MAX_V;
			float nx = boids[idx].x + x;
			float ny = boids[idx].y + y;
			float nz = boids[idx].z;
			dx = mx - nx;
			dy = my - ny;
			dz = nz;
			if (sqrt(dx*dx + dy*dy + dz*dz) > 100) {
				a += M_PI;
				x = cos(a) * MAX_V;
				y = sin(a) * MAX_V;
			}
			boids[idx].x += x;
			boids[idx].y += y;
			return;
		}
	}

	dx = mx - boids[idx].x;
	dy = my - boids[idx].y;
	dz = boids[idx].z;
	if (sqrt(dx*dx + dy*dy + dz*dz) > 75) {
		goto_x = dx;
		goto_y = dy;
		goto_z = -dz;
		goto_n = 1;
	}
	else {
		// flag bees in range using sweep & prune technique
		unset_flags();
		set_flags(&boids[idx]);
		for (int i = 0; i < num_boids; i++) {
			if (i == idx) continue;
			if (boids[i].flag == false) continue;
			float dist = distance(&boids[i], &boids[idx]);
			if (dist < 5) {
				away_x += mx - boids[i].x;
				away_y += my - boids[i].y;
				away_z += (BEE_SPREAD*2) - boids[i].z;
				away_n++;
			}
			else {
				goto_x += mx - boids[i].x;
				goto_y += my - boids[i].y;
				goto_z += (BEE_SPREAD*2) - boids[i].z;
				goto_n++;
			}
		}
	}

	if (goto_n == 0 && away_n == 0)
		return;

	if (goto_n > 0) {
		vx = goto_x / goto_n;
		vy = goto_y / goto_n;
		vz = goto_z / goto_n;
	}

	if (away_n > 0) {
		vx -= away_x / away_n;
		vy -= away_y / away_n;
		vz -= away_z / away_n;
	}

	float total = fabs(vx) + fabs(vy) + fabs(vz);
	if (total == 0) return;
	vx /= total;
	vy /= total;
	vz /= total;

	boids[idx].vx += vx * MAX_A;
	boids[idx].vy += vy * MAX_A;
	boids[idx].vz += vz * MAX_A;
	if (boids[idx].vx > MAX_V) boids[idx].vx = MAX_V;
	if (boids[idx].vx < -MAX_V) boids[idx].vx = -MAX_V;
	if (boids[idx].vy > MAX_V) boids[idx].vy = MAX_V;
	if (boids[idx].vy < -MAX_V) boids[idx].vy = -MAX_V;
	if (boids[idx].vz > MAX_V) boids[idx].vz = MAX_V;
	if (boids[idx].vz < -MAX_V) boids[idx].vz = -MAX_V;

	boids[idx].x += boids[idx].vx;
	boids[idx].y += boids[idx].vy;
	boids[idx].z += boids[idx].vz;
}