← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1480928 into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1480928 into lp:widelands with lp:~widelands-dev/widelands/one_tribe as a prerequisite.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1480928 in widelands: "Lumberjack animation glitches"
  https://bugs.launchpad.net/widelands/+bug/1480928

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1480928/+merge/275633

Animations now have a "play_once" switch. Used it to keep felled trees from getting up again.

A map for easy testing is attached to the bug.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1480928 into lp:widelands.
=== modified file 'src/graphic/animation.cc'
--- src/graphic/animation.cc	2015-10-24 18:22:41 +0000
+++ src/graphic/animation.cc	2015-10-24 18:22:53 +0000
@@ -125,7 +125,7 @@
 	const Point& hotspot() const override;
 	const std::string& representative_image_from_disk_filename() const override;
 	virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*)
-	   const override;
+		const override;
 	void trigger_soundfx(uint32_t framenumber, uint32_t stereo_position) const override;
 
 
@@ -136,6 +136,8 @@
 	// Load the needed graphics from disk.
 	void load_graphics();
 
+	uint32_t current_frame(uint32_t time) const;
+
 	uint32_t frametime_;
 	Point hotspot_;
 	bool hasplrclrs_;
@@ -149,11 +151,13 @@
 	// TODO(sirver): this should be done using playFX in a program instead of
 	// binding it to the animation.
 	string sound_effect_;
+	bool play_once_;
 };
 
 NonPackedAnimation::NonPackedAnimation(const LuaTable& table)
 		: frametime_(FRAME_LENGTH),
-		  hasplrclrs_(false) {
+		  hasplrclrs_(false),
+		  play_once_(false) {
 	try {
 		get_point(*table.get_table("hotspot"), &hotspot_);
 
@@ -166,6 +170,10 @@
 			g_sound_handler.load_fx_if_needed(directory, name, sound_effect_);
 		}
 
+		if (table.has_key("play_once")) {
+			play_once_ = table.get_bool("play_once");
+		}
+
 		const std::string templatedirname = table.get_string("directory");
 		const std::string templatefilename = table.get_string("template");
 
@@ -290,11 +298,22 @@
 	return image_files_[0];
 }
 
+uint32_t NonPackedAnimation::current_frame(uint32_t time) const {
+	if (nr_frames() > 1) {
+		return (play_once_ && time / frametime_ > static_cast<uint32_t>(nr_frames() - 1)) ?
+					static_cast<uint32_t>(nr_frames() - 1) :
+					time / frametime_ % nr_frames();
+	}
+	return 0;
+}
+
 void NonPackedAnimation::trigger_soundfx(uint32_t time, uint32_t stereo_position) const {
 	if (sound_effect_.empty()) {
 		return;
 	}
-	const uint32_t framenumber = time / frametime_ % nr_frames();
+
+	const uint32_t framenumber = current_frame(time);
+
 	if (framenumber == 0) {
 		g_sound_handler.play_fx(sound_effect_, stereo_position, 1);
 	}
@@ -305,7 +324,7 @@
 {
 	assert(target);
 
-	const int idx = time / frametime_ % nr_frames();
+	const uint32_t idx = current_frame(time);
 	assert(idx < nr_frames());
 
 	if (!hasplrclrs_ || clr == nullptr) {

=== modified file 'src/graphic/animation.h'
--- src/graphic/animation.h	2015-10-24 18:22:41 +0000
+++ src/graphic/animation.h	2015-10-24 18:22:53 +0000
@@ -74,7 +74,7 @@
 	/// Blit the animation frame that should be displayed at the given time index
 	/// so that the given point is at the top left of the frame. Srcrc defines
 	/// the part of the animation that should be blitted. The 'clr' is the player
-	/// color used for blitting - the parameter can be NULL in which case the
+	/// color used for blitting - the parameter can be nullptr in which case the
 	/// neutral image will be blitted. The Surface is the target for the blit
 	/// operation and must be non-null.
 	virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) const = 0;

=== modified file 'world/immovables/trees/aspen/init.lua'
--- world/immovables/trees/aspen/init.lua	2015-10-24 18:22:41 +0000
+++ world/immovables/trees/aspen/init.lua	2015-10-24 18:22:53 +0000
@@ -96,7 +96,7 @@
          "seed=aspen_summer_sapling",
       },
       fall = {
-         "animate=falling 1200",
+         "animate=falling 1400",
          "transform=fallentree",
       },
    },
@@ -116,6 +116,7 @@
          directory = dirname .. "old/",
          hotspot = { 20, 59 },
          fps = 10,
+         play_once = true
       },
    },
 }

=== removed file 'world/immovables/trees/aspen/old/f_tree_09.png'
Binary files world/immovables/trees/aspen/old/f_tree_09.png	2014-04-09 11:33:39 +0000 and world/immovables/trees/aspen/old/f_tree_09.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'world/immovables/trees/aspen/old/f_tree_10.png'
Binary files world/immovables/trees/aspen/old/f_tree_10.png	2014-04-09 11:33:39 +0000 and world/immovables/trees/aspen/old/f_tree_10.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'world/immovables/trees/aspen/old/f_tree_11.png'
Binary files world/immovables/trees/aspen/old/f_tree_11.png	2014-04-09 11:33:39 +0000 and world/immovables/trees/aspen/old/f_tree_11.png	1970-01-01 00:00:00 +0000 differ
=== modified file 'world/immovables/trees/oak/init.lua'
--- world/immovables/trees/oak/init.lua	2015-10-24 18:22:41 +0000
+++ world/immovables/trees/oak/init.lua	2015-10-24 18:22:53 +0000
@@ -93,7 +93,7 @@
          "seed=oak_summer_sapling",
       },
       fall = {
-         "animate=falling 1200",
+         "animate=falling 1400",
          "transform=fallentree",
       },
    },
@@ -113,6 +113,7 @@
          directory = dirname .. "old/",
          hotspot = { 10, 60 },
          fps = 10,
+         play_once = true
       },
    },
 }

=== removed file 'world/immovables/trees/oak/old/f_tree_07.png'
Binary files world/immovables/trees/oak/old/f_tree_07.png	2014-04-09 11:35:41 +0000 and world/immovables/trees/oak/old/f_tree_07.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'world/immovables/trees/oak/old/f_tree_08.png'
Binary files world/immovables/trees/oak/old/f_tree_08.png	2014-04-09 11:35:41 +0000 and world/immovables/trees/oak/old/f_tree_08.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'world/immovables/trees/oak/old/f_tree_09.png'
Binary files world/immovables/trees/oak/old/f_tree_09.png	2014-04-09 11:35:41 +0000 and world/immovables/trees/oak/old/f_tree_09.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'world/immovables/trees/oak/old/f_tree_10.png'
Binary files world/immovables/trees/oak/old/f_tree_10.png	2014-04-09 11:35:41 +0000 and world/immovables/trees/oak/old/f_tree_10.png	1970-01-01 00:00:00 +0000 differ
=== removed file 'world/immovables/trees/oak/old/f_tree_11.png'
Binary files world/immovables/trees/oak/old/f_tree_11.png	2014-04-09 11:35:41 +0000 and world/immovables/trees/oak/old/f_tree_11.png	1970-01-01 00:00:00 +0000 differ

Follow ups