Author Topic: Patch: allow event intervals to be given as floats  (Read 1772 times)

0 Members and 1 Guest are viewing this topic.

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Patch: allow event intervals to be given as floats
Currently event intervals can only be supplied as ints representing whole seconds, and I think this ought to allow them to be supplied as floats as well, so if you want sub-second intervals you don't need hacky events to do so but can simply use for example 0.25 for a quarter-second interval.

It works for me in-game, but since I can't compile FRED myself I don't know whether it works there or not. If anyone would like to test this or otherwise point out whether there's something wrong with it then that'd be great.

Code: [Select]
Index: fred2/messageeditordlg.cpp
===================================================================
--- fred2/messageeditordlg.cpp (revision 8847)
+++ fred2/messageeditordlg.cpp (working copy)
@@ -433,7 +433,7 @@
  m_event_num = Num_mission_events++;
  string_copy(Mission_events[m_event_num].name, m_message_name, NAME_LENGTH - 1);
  Mission_events[m_event_num].repeat_count = 1;
- Mission_events[m_event_num].interval = 1;
+ Mission_events[m_event_num].interval = 1.0f;
  Mission_events[m_event_num].score = 0;
  Mission_events[m_event_num].chain_delay = -1;
  Mission_events[m_event_num].objective_text = NULL;
Index: fred2/eventeditor.cpp
===================================================================
--- fred2/eventeditor.cpp (revision 8847)
+++ fred2/eventeditor.cpp (working copy)
@@ -37,7 +37,7 @@
  //{{AFX_DATA_INIT(event_editor)
  m_repeat_count = 0;
  m_trigger_count = 0;
- m_interval = 0;
+ m_interval = 0.0f;
  m_event_score = 0;
  m_chain_delay = 0;
  m_chained = FALSE;
@@ -711,7 +711,7 @@
 
  m_events[num].repeat_count = 1;
  m_events[num].trigger_count = 1;
- m_events[num].interval = 1;
+ m_events[num].interval = 1.0f;
  m_events[num].score = 0;
  m_events[num].chain_delay = -1;
  m_events[num].objective_text = NULL;
@@ -928,7 +928,7 @@
  if (cur_event < 0) {
  m_repeat_count = 1;
  m_trigger_count = 1;
- m_interval = 1;
+ m_interval = 1.0f;
  m_chain_delay = 0;
  m_team = -1;
  m_obj_text.Empty();
@@ -980,7 +980,7 @@
  GetDlgItem(IDC_TRIGGER_COUNT)->EnableWindow(TRUE);
 
  if (( m_repeat_count <= 1) && (m_trigger_count <= 1)) {
- m_interval = 1;
+ m_interval = 1.0f;
  GetDlgItem(IDC_INTERVAL_TIME) -> EnableWindow(FALSE);
  } else {
  GetDlgItem(IDC_INTERVAL_TIME) -> EnableWindow(TRUE);
Index: fred2/eventeditor.h
===================================================================
--- fred2/eventeditor.h (revision 8847)
+++ fred2/eventeditor.h (working copy)
@@ -56,7 +56,7 @@
  event_sexp_tree m_event_tree;
  UINT m_repeat_count;
  UINT m_trigger_count;
- UINT m_interval;
+ float m_interval;
  int m_event_score;
  int m_chain_delay;
  BOOL m_chained;
Index: fred2/missionsave.cpp
===================================================================
--- fred2/missionsave.cpp (revision 8847)
+++ fred2/missionsave.cpp (working copy)
@@ -3323,7 +3323,7 @@
  fout("\n+Interval:");
  }
 
- fout(" %d", Mission_events[i].interval);
+ fout(" %f", Mission_events[i].interval);
 
  if ( Mission_events[i].score != 0 ) {
  if ( optional_string_fred("+Score:", "$Formula:")){
Index: mission/missiongoals.h
===================================================================
--- mission/missiongoals.h (revision 8847)
+++ mission/missiongoals.h (working copy)
@@ -89,7 +89,7 @@
  int result; // result of most recent evaluation of event
  int repeat_count; // number of times to test this goal
  int trigger_count; // number of times to allow this goal to trigger
- int interval; // interval (in seconds) at which an evaulation is repeated once true.
+ float interval; // interval (in seconds) at which an evaulation is repeated once true.
  int timestamp; // set at 'interval' seconds when we start to eval.
  int score; // score for this event
  int chain_delay;
Index: mission/missionparse.cpp
===================================================================
--- mission/missionparse.cpp (revision 8847)
+++ mission/missionparse.cpp (working copy)
@@ -4488,9 +4488,9 @@
  event->trigger_count = 1;
  }
 
- event->interval = -1;
+ event->interval = -1.0f;
  if ( optional_string("+Interval:")){
- stuff_int( &(event->interval) );
+ stuff_float( &(event->interval) );
  }
 
  event->score = 0;
Index: parse/lua.cpp
===================================================================
--- parse/lua.cpp (revision 8847)
+++ parse/lua.cpp (working copy)
@@ -939,7 +939,7 @@
 ADE_VIRTVAR(Interval, l_Event, "number", "Time for event to repeat (in seconds)", "number", "Repeat time, or 0 if invalid handle")
 {
  int idx;
- int newinterval = 0;
+ float newinterval = 0.0f;
  if(!ade_get_args(L, "o|i", l_Event.Get(&idx), &newinterval))
  return ade_set_error(L, "i", 0);
 
Index: mission/missiongoals.cpp
===================================================================
--- mission/missiongoals.cpp (revision 8847)
+++ mission/missiongoals.cpp (working copy)
@@ -976,7 +976,7 @@
  // this event didn't trigger this frame.
  else if (bump_timestamp || (!( Mission_events[event].repeat_count == -1 && Mission_events[event].trigger_count > 0 ))) {
  // set the timestamp to time out 'interval' seconds in the future. 
- Mission_events[event].timestamp = timestamp( Mission_events[event].interval * 1000 );
+ Mission_events[event].timestamp = timestamp( int(Mission_events[event].interval * 1000.0f) );
  }
  }
 

 

Offline Trivial Psychic

  • 212
  • Snoop Junkie
Re: Patch: allow event intervals to be given as floats
Well, we already have is-event-true-msecs-delay, but I could see the use of non-whole numbers in the chain interval and repeat interval boxes.
The Trivial Psychic Strikes Again!

 
Re: Patch: allow event intervals to be given as floats
Thank you. I mean it.

 

Offline Shivan Hunter

  • 210
  • FRED needs lambdas!
Re: Patch: allow event intervals to be given as floats
I love you :D

 

Offline Mastadon

  • Contributes SCP patches and doesn't afraid of anything
  • 26
Re: Patch: allow event intervals to be given as floats
It works for me in-game, but since I can't compile FRED myself I don't know whether it works there or not. If anyone would like to test this or otherwise point out whether there's something wrong with it then that'd be great.

You wouldn't happen to be running Windows 7, would you? If so, then what I've found is that you need to add the windowscodecs.lib file (included with the Windows 7 SDK) to Fred2's Additional Dependencies for each release you want to compile for.

Alternatively, you can apply the attached patch and it will add the windowscoecs.lib reference to all configurations.

[attachment deleted by a ninja]

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: Patch: allow event intervals to be given as floats
Floating-point numbers are inherently inexact.  This has the potential to screw up any event comparison in ways that may not be immediately apparent, such as where an interval needs to be a multiple of another interval.  Furthermore, nowhere else in the event or sexp system do we use floats.

A better way to solve this problem would be to add an interval_msecs field.

  

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Patch: allow event intervals to be given as floats
Floating-point numbers are inherently inexact.  This has the potential to screw up any event comparison in ways that may not be immediately apparent, such as where an interval needs to be a multiple of another interval.

I knew there was something wrong with the idea but I just couldn't put my finger on it! :D

I agree it's much smarter to just have FRED write out milliseconds from now on.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]