Beispiel #1
0
void LEDFader::fade(uint8_t value, unsigned int time) {
  stop_fade();
  percent_done = 0;

  // No pin defined
  if (!pin) {
    return;
  }

  // Color hasn't changed
  if (value == color) {
    return;
  }

  if (time <= MIN_INTERVAL) {
    set_value(value);
    return;
  }

  duration = time;
  to_color = (uint8_t)constrain(value, 0, 255);

  // Figure out what the interval should be so that we're chaning the color by at least 1 each cycle
  // (minimum interval is MIN_INTERVAL)
  float color_diff = abs(color - to_color);
  interval = round((float)duration / color_diff);
  if (interval < MIN_INTERVAL) {
    interval = MIN_INTERVAL;
  }

  last_step_time = millis();
}
// LP: added whether a savegame is being restored (skip Pfhortran init if that's the case)
bool entering_map(bool restoring_saved)
{
	bool success= true;

	/* if any active monsters think they have paths, we'll make them reconsider */
	initialize_monsters_for_new_level();

	/* and since no monsters have paths, we should make sure no paths think they have monsters */
	reset_paths();
	
	/* mark our shape collections for loading and load them */
	mark_environment_collections(static_world->environment_code, true);
	mark_all_monster_collections(true);
	mark_player_collections(true);
	mark_map_collections(true);

	MarkLuaCollections(true);
	MarkLuaHUDCollections(true);

#ifdef SDL
	load_collections(true, get_screen_mode()->acceleration != _no_acceleration);
#else
	load_collections(true, true);
#endif

	load_all_monster_sounds();
	load_all_game_sounds(static_world->environment_code);

#if !defined(DISABLE_NETWORKING)
	/* tell the keyboard controller to start recording keyboard flags */
	if (game_is_networked) success= NetSync(); /* make sure everybody is ready */
#endif // !defined(DISABLE_NETWORKING)

	/* make sure nobodyÕs holding a weapon illegal in the new environment */
	check_player_weapons_for_environment_change();

#if !defined(DISABLE_NETWORKING)
	if (dynamic_world->player_count>1 && !restoring_saved) initialize_net_game();
#endif // !defined(DISABLE_NETWORKING)
	randomize_scenery_shapes();

//	reset_action_queues(); //¦¦
//	sync_heartbeat_count();
//	set_keyboard_controller_status(true);

	L_Call_Init(restoring_saved);

#if !defined(DISABLE_NETWORKING)
	NetSetChatCallbacks(InGameChatCallbacks::instance());
#endif // !defined(DISABLE_NETWORKING)

	// Zero out fades *AND* any inadvertant fades from script start...
	stop_fade();
	set_fade_effect(NONE);
	
	if (!success) leaving_map();

	return success;
}
Beispiel #3
0
void LEDFader::faster(int by) {
  float cached_percent = percent_done;

  // Ends the fade
  if (duration <= by) {
    stop_fade();
    set_value(to_color);
  }
  else {
    duration -= by;
    fade(to_color, duration);
  }
  percent_done = cached_percent;
}
Beispiel #4
0
bool LEDFader::update() {

  // No pin defined
  if (!pin) {
    return false;
  }

  // No fade
  if (duration == 0) {
    return false;
  }

  unsigned long now = millis();
  unsigned int time_diff = now - last_step_time;

  // Interval hasn't passed yet
  if (time_diff < interval) {
    return true;
  }

  // How far along have we gone since last update
  float percent = (float)time_diff / (float)duration;
  percent_done += percent;

  // We've hit 100%, set LED to the final color
  if (percent >= 1) {
    stop_fade();
    set_value(to_color);
    return false;
  }

  // Move color to where it should be
  int color_diff = to_color - color;
  int increment = round(color_diff * percent);

  set_value(color + increment);

  // Update time and finish
  duration -= time_diff;
  last_step_time = millis();
  return true;
}