Author Topic: Scalable head ANIs [patch]  (Read 2001 times)

0 Members and 1 Guest are viewing this topic.

Offline Yarn

  • 210
Scalable head ANIs [patch]
Anyone who's tried to play the main Wings of Dawn campaign with the Stranded add-on installed knows that the head animation does not fill the head gauge with that setup. This happens because Stranded includes a HUD table that uses a larger head gauge to accommodate Stranded's larger head animations. This inspired me to implement a way to scale head animations, which FSO cannot currently do. Here's the patch that I made:
Code: [Select]
Index: code/hud/hudmessage.cpp
===================================================================
--- code/hud/hudmessage.cpp (revision 11090)
+++ code/hud/hudmessage.cpp (working copy)
@@ -1227,7 +1227,9 @@
 {
  anim_play_struct aps;
 
- anim_play_init(&aps, anim_data, position[0] + Anim_offsets[0] + fl2i(HUD_offset_x), position[1] + Anim_offsets[1] + fl2i(HUD_offset_y), base_w, base_h);
+ float scale_x = i2fl(Anim_size[0]) / i2fl(anim_data->width);
+ float scale_y = i2fl(Anim_size[1]) / i2fl(anim_data->height);
+ anim_play_init(&aps, anim_data, fl2ir((position[0] + Anim_offsets[0] + HUD_offset_x) / scale_x), fl2ir((position[1] + Anim_offsets[1] + HUD_offset_y) / scale_y), base_w, base_h);
  aps.start_at = anim_start_frame;
 
  // aps.color = &HUD_color_defaults[HUD_color_alpha];
@@ -1261,10 +1263,13 @@
  resetClip();
 
  renderBitmap(Head_frame.first_frame, position[0], position[1]); // head ani border
- gr_set_screen_scale(base_w, base_h);
+ float scale_x = i2fl(Anim_size[0]) / i2fl(head_anim->width);
+ float scale_y = i2fl(Anim_size[1]) / i2fl(head_anim->height);
+ gr_set_screen_scale(fl2ir(base_w / scale_x), fl2ir(base_h / scale_y));
  setGaugeColor();
- generic_anim_render(head_anim,frametime, position[0] + Anim_offsets[0] + fl2i(HUD_offset_x), position[1] + Anim_offsets[1] + fl2i(HUD_offset_y));
+ generic_anim_render(head_anim,frametime, fl2ir((position[0] + Anim_offsets[0] + HUD_offset_x) / scale_x), fl2ir((position[1] + Anim_offsets[1] + HUD_offset_y) / scale_y));
  // draw title
+ gr_set_screen_scale(base_w, base_h);
  renderString(position[0] + Header_offsets[0], position[1] + Header_offsets[1], XSTR("message", 217));
  } else {
  for (int j = 0; j < Num_messages_playing; ++j) {
Index: code/hud/hudparse.cpp
===================================================================
--- code/hud/hudparse.cpp (revision 11090)
+++ code/hud/hudparse.cpp (working copy)
@@ -3743,8 +3743,12 @@
  stuff_int_list(Anim_offsets, 2);
  }
  if(optional_string("Animation Background Size:")) {
+ mprintf(("Animation Background Size in hud_gauges.tbl and -hdg.tbms is deprecated. Use \"Animation Size\" instead.\n"));
  stuff_int_list(Anim_size, 2);
  }
+ if(optional_string("Animation Size:")) {
+ stuff_int_list(Anim_size, 2);
+ }
 
  hud_gauge->initAnimOffsets(Anim_offsets[0], Anim_offsets[1]);
  hud_gauge->initAnimSizes(Anim_size[0], Anim_size[1]);


The patch scales head animations to the size specified by either "Animation Background Size" or the new "Animation Size" in the head gauge's hud_gauges.tbl entry. Both parameters do the same thing, but the former is deprecated because it no longer accurately describes its function (and, judging by the rest of the code, it looks like it was always meant to define the animation size anyway).

To try it out, copy the text below into a new HUD table (big_head-hdg.tbm works fine). A larger talking head gauge will be used, and the head animations will be scaled to fit. Alternatively, you can just try the main Wings of Dawn campaign with Stranded installed.
Code: [Select]
#Gauge Config
$Base: (1024, 768)
$Min: (1024, 600)
$Gauges:
+Talking Head:
Font: 2
Filename: 2_head1.ani
Header Offsets: (3, 3)
Animation Offsets: (3, 16)
Animation Background Size: (250, 187)
$End Gauges
#End

(And yes, I did use "Animation Background Size", which I said is deprecated. I did that so the table can also be used with existing builds for comparison purposes.)
"Your fighter is running out of oil.  Please check under the hood and add more if necessary"
--strings.tbl, entry 177

"Freespace is very tired.  It is shutting down to get some rest."
--strings.tbl, entry 178

 

Offline niffiwan

  • 211
  • Eluder Class
Re: Scalable head ANIs [patch]
So I don't forget about this, could you put this on mantis in code review? Thanks :)
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...

 

Offline Yarn

  • 210
"Your fighter is running out of oil.  Please check under the hood and add more if necessary"
--strings.tbl, entry 177

"Freespace is very tired.  It is shutting down to get some rest."
--strings.tbl, entry 178