2019-12-07 11:55 EST


View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002385FSSCPtablespublic2011-02-04 12:19
ReporterFUBAR-BDHR 
Assigned ToThe_E 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionfixed 
Product Version3.6.13 
Target VersionFixed in Version3.6.13 
Summary0002385: Animation code should be using subobject names not numbers
DescriptionThis is kind of a feature and a bug so putting it here. The issue with using subobject numbers for the animation code is that they change. Something as simple as opening an older versions of a model in a newer version of pcs2 can result in different subobject numbers. Max constantly rearranges them. Even saving and reopening a model will often result in different subobject numbers on export.

Of course we would need to keep the existing subobject number option for backward compatibility. Adding a +sub_name option would probably be the best. It would also allow for better error checking in the future as a deleted object would no longer be found.
TagsNo tags attached.
Attached Files
  • patch file icon 2385.patch (2,267 bytes) 2011-01-24 12:04 -
    Index: model/modelanim.h
    ===================================================================
    --- model/modelanim.h	(revision 6969)
    +++ model/modelanim.h	(working copy)
    @@ -66,6 +66,8 @@
     	int loop_sound;
     	int end_sound;
     	float snd_rad;
    +
    +	char sub_name[NAME_LENGTH];
     };
     
     /*
    Index: ship/ship.cpp
    ===================================================================
    --- ship/ship.cpp	(revision 6969)
    +++ ship/ship.cpp	(working copy)
    @@ -375,6 +375,8 @@
     
     bool warning_too_many_ship_classes = false;
     
    +int ship_get_subobj_model_num(ship_info* sip, char* subobj_name);
    +
     // set the ship_obj struct fields to default values
     void ship_obj_list_reset_slot(int index)
     {
    @@ -3177,7 +3179,13 @@
     						current_trigger->subtype = ANIMATION_SUBTYPE_ALL;
     					}
     
    +					if(optional_string("+sub_name:")) {
    +						stuff_string(current_trigger->sub_name, F_NAME, NAME_LENGTH);
    +					} else {
    +						strcpy_s(current_trigger->sub_name, "<none>");
    +					}
     
    +
     					if(current_trigger->type == TRIGGER_TYPE_INITIAL){
     						//the only thing initial animation type needs is the angle, 
     						//so to save space lets just make everything optional in this case
    @@ -3340,7 +3348,21 @@
     
     	strcpy_s(parse_error_text, "");
     
    +	// Fix up animation code references
    +	for (int i = 0; i < sip->n_subsystems; i++) {
    +		for (int j = 0; j < sip->subsystems[i].n_triggers; j++) {
    +			if (stricmp(sip->subsystems[i].triggers[j].sub_name, "<none>")) {
    +				int idx = ship_get_subobj_model_num(sip, sip->subsystems[i].triggers[j].sub_name);
    +				if (idx != -1) {
    +					sip->subsystems[i].triggers[j].subtype = idx;
    +				} else {
    +					WarningEx(LOCATION, "Could not find subobject %s in ship class %s. Animation triggers will not work correctly.\n", sip->subsystems[i].triggers[j].sub_name, sip->name);
    +				}
    +			}
    +		}
    +	}
     
    +
     	return rtn;	//0 for success
     }
     
    @@ -16922,3 +16944,13 @@
     			Warning(LOCATION, "Unrecognized weapon '%s' found when setting weapon targeting priorities.\n", tempname);
     	}
     }
    +
    +int ship_get_subobj_model_num(ship_info* sip, char* subobj_name) 
    +{
    +	for (int i = 0; i < sip->n_subsystems; i++) {
    +		if (!stricmp(sip->subsystems[i].name, subobj_name))
    +			return sip->subsystems[i].subobj_num;
    +	}
    +
    +	return -1;
    +}
    \ No newline at end of file
    
    patch file icon 2385.patch (2,267 bytes) 2011-01-24 12:04 +
  • patch file icon 2385-2.patch (2,377 bytes) 2011-01-25 13:11 -
    Index: model/modelanim.h
    ===================================================================
    --- model/modelanim.h	(revision 6976)
    +++ model/modelanim.h	(working copy)
    @@ -66,6 +66,8 @@
     	int loop_sound;
     	int end_sound;
     	float snd_rad;
    +
    +	char sub_name[NAME_LENGTH];
     };
     
     /*
    Index: ship/ship.cpp
    ===================================================================
    --- ship/ship.cpp	(revision 6976)
    +++ ship/ship.cpp	(working copy)
    @@ -375,6 +375,8 @@
     
     bool warning_too_many_ship_classes = false;
     
    +int ship_get_subobj_model_num(ship_info* sip, char* subobj_name);
    +
     // set the ship_obj struct fields to default values
     void ship_obj_list_reset_slot(int index)
     {
    @@ -3177,7 +3179,13 @@
     						current_trigger->subtype = ANIMATION_SUBTYPE_ALL;
     					}
     
    +					if(optional_string("+sub_name:")) {
    +						stuff_string(current_trigger->sub_name, F_NAME, NAME_LENGTH);
    +					} else {
    +						strcpy_s(current_trigger->sub_name, "<none>");
    +					}
     
    +
     					if(current_trigger->type == TRIGGER_TYPE_INITIAL){
     						//the only thing initial animation type needs is the angle, 
     						//so to save space lets just make everything optional in this case
    @@ -3340,7 +3348,6 @@
     
     	strcpy_s(parse_error_text, "");
     
    -
     	return rtn;	//0 for success
     }
     
    @@ -5214,6 +5221,20 @@
     		ship_recalc_subsys_strength( shipp );
     	}
     
    +	// Fix up animation code references
    +	for (int i = 0; i < sinfo->n_subsystems; i++) {
    +		for (int j = 0; j < sinfo->subsystems[i].n_triggers; j++) {
    +			if (stricmp(sinfo->subsystems[i].triggers[j].sub_name, "<none>")) {
    +				int idx = ship_get_subobj_model_num(sinfo, sinfo->subsystems[i].triggers[j].sub_name);
    +				if (idx != -1) {
    +					sinfo->subsystems[i].triggers[j].subtype = idx;
    +				} else {
    +					WarningEx(LOCATION, "Could not find subobject %s in ship class %s. Animation triggers will not work correctly.\n", sinfo->subsystems[i].triggers[j].sub_name, sinfo->name);
    +				}
    +			}
    +		}
    +	}
    +
     	return 1;
     }
     
    @@ -16922,3 +16943,13 @@
     			Warning(LOCATION, "Unrecognized weapon '%s' found when setting weapon targeting priorities.\n", tempname);
     	}
     }
    +
    +int ship_get_subobj_model_num(ship_info* sip, char* subobj_name) 
    +{
    +	for (int i = 0; i < sip->n_subsystems; i++) {
    +		if (!stricmp(sip->subsystems[i].subobj_name, subobj_name))
    +			return sip->subsystems[i].subobj_num;
    +	}
    +
    +	return -1;
    +}
    \ No newline at end of file
    
    patch file icon 2385-2.patch (2,377 bytes) 2011-01-25 13:11 +

-Relationships
+Relationships

-Notes

~0012611

The_E (administrator)

Proposed patch is attached. Adds "+sub_name" to the animation code, to be placed after or instead of "+sub_type".

~0012612

FUBAR-BDHR (developer)

Last edited: 2011-01-25 01:02

Doesn't seem to work. I changed 5 turret doors to use +sub_name and while they do trigger to open they never stop rotating and never close. Left the rest on +sub_type and they still work.

Found and fixed one bug. Line 71 in that patch should be

if (!stricmp(sip->subsystems[i].subobj_name, subobj_name))

Even with that it seems that sip->subsystems[i].subobj_num is not defined yet as every single one has a value of 0xcccccccc

~0012613

The_E (administrator)

Yeah, I was sort of afraid of that. Second patch uploaded, this one moves the fixing of animation references into ship_set, during mission load (which is where model data is mated with tbl data. Didn't want to slow down the init process by having to load the model during startup....)

~0012614

FUBAR-BDHR (developer)

Looks good.

~0012623

The_E (administrator)

Committed to trunk in revision 7000
+Notes

-Issue History
Date Modified Username Field Change
2011-01-24 00:00 FUBAR-BDHR New Issue
2011-01-24 12:04 The_E File Added: 2385.patch
2011-01-24 12:05 The_E Note Added: 0012611
2011-01-25 00:18 FUBAR-BDHR Note Added: 0012612
2011-01-25 01:02 FUBAR-BDHR Note Edited: 0012612
2011-01-25 13:04 The_E Note Added: 0012613
2011-01-25 13:11 The_E File Added: 2385-2.patch
2011-01-25 13:11 The_E Status new => assigned
2011-01-25 13:11 The_E Assigned To => The_E
2011-01-25 18:50 FUBAR-BDHR Note Added: 0012614
2011-02-04 12:19 The_E Note Added: 0012623
2011-02-04 12:19 The_E Status assigned => resolved
2011-02-04 12:19 The_E Fixed in Version => 3.6.13
2011-02-04 12:19 The_E Resolution open => fixed
+Issue History