Example #1
0
void Damageable::default_render_health(Graphic& graphic, const Color& color, float frames_count) const {
    if (has_hp()) {
        Box health_box;

        health_box.set_size(50.f * get_hp() / get_default_hp(), 5.f);
        health_box.set_left_top(
                get_position().x - health_box.get_width() / 2 + get_current_speed().x * frames_count,
                get_position().y - get_circle().get_radius() + get_current_speed().y * frames_count
        );

        graphic.render_box(health_box, color);
    }
}
Example #2
0
int machine_speed_init (actuator_t *act)
{
	machine_state_data_t *data;
	unsigned long *states, *all_states;
	unsigned long *in_state, *out_state;
	int state_count, filtered_count;
	
	int core_count, i;
	freq_scaler_data_t *freq_data;

	act->data = data = malloc(sizeof(machine_state_data_t));
	fail_if(!data, "cannot allocate powerstate data block");

	get_actuators(&data->core_act, NULL, 16, &data->freq_acts[0], NULL);
	fail_if(data->core_act->max > 16, "too many cores lol");
	freq_data = data->freq_acts[0]->data;
	core_count = get_core_count();
	
	all_states = create_machine_states(&state_count, core_count, freq_data->freq_count, freq_data->freq_array);
	fail_if(!all_states, "cannot generate machine states");

	qsort(all_states, state_count, STATE_SIZE(core_count), compare_states_on_speed);
	states = malloc(STATE_SIZE(core_count) * state_count);
	for (i = 0, in_state = all_states, out_state = states, filtered_count = 0; i < state_count; i++, in_state+=STATE_LEN(core_count)) {
		if (!redundant_state(in_state, core_count) &&
			!drop_equivalent(in_state, i, all_states, state_count, core_count) &&
			pareto_optimal(in_state, i, all_states, state_count, core_count) &&
			in_state[SPEED_IDX] > 0)
		{
#if DEBUG
			int j;
			printf("%lu\t%lu", in_state[SPEED_IDX], in_state[POWER_IDX]);
			for (j = 0; j < core_count; j++)
				printf("\t%lu", in_state[CORE_IDX(j)]);
			printf("\n");
#endif
			memmove (out_state, in_state, STATE_SIZE(core_count));
			out_state += STATE_LEN(core_count);
			filtered_count++;
		}
	}
	data->state_count = state_count = filtered_count;
	data->states = states = realloc(states, STATE_SIZE(core_count) * state_count);
	free(all_states);
	
	act->min = STATE_I(states, core_count, 0)[SPEED_IDX];
	act->max = STATE_I(states, core_count, state_count-1)[SPEED_IDX];
	
	data->scratch_state = malloc(STATE_SIZE(core_count));
	act->value = act->set_value = get_current_speed(act);
	
	return 0;
fail:
	return -1;
}
Example #3
0
void show_default_screen(msg_t *msg)
{
    LCD_GoTo(8,0);
    get_time_str(string_buff);
    LCD_WriteText(string_buff);
    LCD_GoTo(4, 0);
    LCD_WriteText("k/h \0");
    int offset = 1;
    switch(msg->type) {
    case MSG_SECOND_CHANGE:
        offset = calculate_speed() > 99 ? 0 : 1;
        break;
    }
    if (offset > 0) {
        LCD_GoTo(0,0);
        LCD_WriteText(" \0");
    }
    get_current_speed(string_buff);
    LCD_GoTo(offset, 0);
    LCD_WriteText(string_buff);
}
Example #4
0
int main(int argc, char **argv)
{
	int n_apps = 0;
	int apps[16];
	int err;
	int i;
	int64_t window_size;
	int64_t skip_until_beat = 0;
	int64_t last_beat = 0;
	heartbeat_record_t current;
	int core_count;
	int opt;
	int max_beats = INT_MAX;
	
	extern int actuator_count;
	extern actuator_t *controls;
	actuator_t *next_ctl;
	
	decision_function_t decision_f = machine_state_controller;
	int acted;

	/* we want to see this in realtime even when it's piped through tee */
	setlinebuf(stdout);
	
	/* getting rich with stock options */	
	while ((opt = getopt(argc, argv, "d:")) != -1) switch (opt) {
		case 'd':
			if (strcmp(optarg, "core_heuristics") == 0) decision_f = core_heuristics;
			else if (strcmp(optarg, "freq_heuristics") == 0) decision_f = freq_heuristics;
			else if (strcmp(optarg, "uncoordinated_heuristics") == 0) decision_f = uncoordinated_heuristics;
			else if (strcmp(optarg, "step_heuristics") == 0) decision_f = step_heuristics;
			else if (strcmp(optarg, "core_controller") == 0) decision_f = core_controller;
			else if (strcmp(optarg, "machine_state_controller") == 0) decision_f = machine_state_controller;
			else {
				fprintf(stderr, "%s: unknown decision function\n", argv[0]);
				exit(1);
			}
			break;
		default:
			fprintf(stderr, "Usage: %s [-d decision_function]\n", argv[0]);
			exit(1);
	}	
	argc -= optind;
	argv += optind;	
	if (argc > 1)
		max_beats = argv[1];
	
	/* setupping arbit */
	heartbeat_dir = getenv("HEARTBEAT_ENABLED_DIR");
	fail_if(heartbeat_dir == NULL, "environment variable HEARTBEAT_ENABLED_DIR undefined");
	
	while (n_apps == 0)
		n_apps = get_heartbeat_apps(apps, sizeof(apps)/sizeof(apps[0]));
	fail_if(n_apps != 1, "this service only supports a single app. please delete c:\\system32");
	printf("monitoring process %d\n", apps[0]);
	
	/* initrogenizing old river control structure */
	core_count = get_core_count();
	actuator_count = core_count + 3;
	
	controls = malloc(sizeof(actuator_t) * actuator_count);
	fail_if(!controls, "could not allocate actuators");
	/* PROBLEM!!!!! the machine speed actuator needs to init last, but act first! WHAT NOW */
	/* create the list in action order, but init in special order... QUICK AND DIRTY = OPTIMAL */
	next_ctl = controls;
	*next_ctl++ =     (actuator_t) { .id = ACTUATOR_MACHINE_SPD, .core = -1, .pid = apps[0], .init_f = machine_speed_init, .action_f = machine_speed_act };
	for (i = 0; i < core_count; i++)
		*next_ctl++ = (actuator_t) { .id = ACTUATOR_SINGLE_FREQ, .core = i,  .pid = -1,      .init_f = single_freq_init,   .action_f = single_freq_act };
	*next_ctl++ =     (actuator_t) { .id = ACTUATOR_GLOBAL_FREQ, .core = -1, .pid = -1,      .init_f = global_freq_init,   .action_f = global_freq_act };
	*next_ctl++ =     (actuator_t) { .id = ACTUATOR_CORE_COUNT,  .core = -1, .pid = apps[0], .init_f = core_init,          .action_f = core_act };
	
	
	for (i = 1; i < actuator_count; i++) {
		err = controls[i].init_f(&controls[i]);
		fail_if(err, "cannot initialize actuator");
	}
	/* initialize machine speed actuator last! */
	err = controls[0].init_f(&controls[0]);
	fail_if(err, "cannot initialize actuator");
	
	/* begin monitoration of lone protoss */
	err = heart_rate_monitor_init(&hrm, apps[0]);
	fail_if(err, "cannot start heart rate monitor");
	
	window_size = hrm_get_window_size(&hrm);
	current.beat = -1;
	
	do {
		do {
			err = hrm_get_current(&hrm, &current);
		} while (err || current.beat <= last_beat || current.window_rate == 0.0);

		last_beat = current.beat;
		if (current.beat < skip_until_beat) {
			print_status(&current, skip_until_beat, '.', actuator_count, controls);
			continue;
		}
		
		/*printf("Current beat: %lld, tag: %d, window: %lld, window_rate: %f\n",
			   current.beat, current.tag, window_size, current.window_rate);*/
		
		decision_f(&current, actuator_count, controls);
		
		acted = 0;
		for (i = 0; i < actuator_count; i++) {
			actuator_t *act = &controls[i];
			if (act->set_value != act->value) {
#if DEBUG
				printf("act %d: %d -> %d\n", i, act->value, act->set_value);
#endif
				err = act->action_f(act);	/* TODO: handle error */
				if (err) fprintf(stderr, "action %d failed: %s\n", act->id, strerror(errno));
				acted = 1;
			}
		}
		/* this is horrible but necessary */
		controls[0].value = get_current_speed(&controls[0]);

		skip_until_beat = current.beat + (acted ? window_size : 1);
		
		print_status(&current, skip_until_beat, acted ? '*' : '=', actuator_count, controls);
	} while (current.beat < max_beats);
	
	heart_rate_monitor_finish(&hrm);
	
	return 0;
fail:
	return 1;
}

/* here are some globals without lexical scoping, just to mix things up! */
int actuator_count;
actuator_t *controls;