Lean, mean and clean edition.
You are not logged in.
Kai,
I have been messing around with the vector math stuff and put it in the newest swr1.3fuss. Now, everything seems to be working great, only one thing I haven't been able to figure out. I'm trying to get the hotboot code to save ships heading, position, and all. But I can't seem to get it working right. Have you messed with this at all?
Offline
Doesn't swrfuss already do this? Does the original non-fixed version work or not? If it does it should be a mere matter of replacing ship->vx with ship->pos.x etc in write_ship() and load_ship() in hotboot.c. If the original doesn't work then it should probably be reported to the fuss project.
If it's something else I'll need a bit more details on what works and what doesn't work, and such.
Edit: some clarifications
Offline
The system is already in the FUSS hotboot system. I am testing now to see if a completely stock base has the same problem.
All I know was when I changed things over it was compiling fine, but everytime I'd hotboot it would stick me back to 0 0 0.
Will post back shortly.
Offline
Yeah, it's working stock. But when I switch it it doesn't. I was just curious if you knew about any of it.
Offline
Show me your modified write_ship() function. I have a hunch, but I need to see it.
Offline
void write_ship( FILE * fp, SHIP_DATA * ship )
{
if( !fp )
return;
/*
* What other conditions?
*/
/*
* How about only ones that landed
*/
if( ship->shipstate == SHIP_DOCKED )
return;
if( ship->ship_class > SHIP_PLATFORM )
return;
fprintf( fp, "%s", "#SHIP\n" );
fprintf( fp, "Shipfname %s~\n", ship->filename );
if( ship->currspeed != 0 )
fprintf( fp, "Currspeed %d\n", ship->currspeed );
if( ship->chaff != ship->maxchaff )
fprintf( fp, "Chaff %d\n", ship->chaff );
if( ship->shield != ship->maxshield )
fprintf( fp, "Shield %d\n", ship->shield );
if( ship->missiles != ship->maxmissiles )
fprintf( fp, "Missiles %d\n", ship->missiles );
if( ship->torpedos != ship->maxtorpedos )
fprintf( fp, "Torpedos %d\n", ship->torpedos );
if( ship->rockets != ship->maxrockets )
fprintf( fp, "Rockets %d\n", ship->rockets );
fprintf( fp, "Autorecharge %d\n", ship->autorecharge );
fprintf( fp, "Autotrack %d\n", ship->autotrack );
fprintf( fp, "Autospeed %d\n", ship->autospeed );
fprintf( fp, "Autopilot %d\n", ship->autopilot );
fprintf( fp, "VX %.0f\n", ship->pos.x );
fprintf( fp, "VY %.0f\n", ship->pos.y );
fprintf( fp, "VZ %.0f\n", ship->pos.z );
fprintf( fp, "HX %.0f\n", ship->head.x );
fprintf( fp, "HY %.0f\n", ship->head.y );
fprintf( fp, "HZ %.0f\n", ship->head.z );
fprintf( fp, "JX %.0f\n", ship->jump.x );
fprintf( fp, "JY %.0f\n", ship->jump.y );
fprintf( fp, "JZ %.0f\n", ship->jump.z );
if( ship->target0 )
fprintf( fp, "Target0 %s~\n", ship->target0->name );
if( ship->target1 )
fprintf( fp, "Target1 %s~\n", ship->target1->name );
if( ship->target2 )
fprintf( fp, "Target2 %s~\n", ship->target2->name );
fprintf( fp, "Shipstate %d\n", ship->shipstate );
if( ship->dest != NULL && ship->dest[0] != '\0' )
{
fprintf( fp, "LandDest %s~\n", ship->dest );
}
if( ship->shipstate == SHIP_HYPERSPACE )
{
fprintf( fp, "Hyperdistance %d\n", ship->hyperdistance );
fprintf( fp, "Currjump %s~\n", ship->currjump->name );
}
if( ship->energy != ship->maxenergy )
fprintf( fp, "Energy %d\n", ship->energy );
if( ship->hull != ship->maxhull )
fprintf( fp, "Hull %d\n", ship->hull );
if( ship->starsystem )
fprintf( fp, "Starsystem %s~\n", ship->starsystem->name );
fprintf( fp, "%s", "EndShip\n\n" );
return;
}
Offline
Hmm. The code looks right. You write the position and heading values to disk, then I assume you assign them to the correct ship->pos/heading in load_ship.
Try adding a log entry in load_ship.
Change this:
if( !str_cmp( word, "EndShip" ) )
{
return ship;
}To this (possible typos):
if( !str_cmp( word, "EndShip" ) )
{
log_printf( "%s: Ship %s loaded with position %.0f,%.0f,%.0f heading %.0f,%.0f,%.0f"
ship->name, ship->pos.x, ship->pos.y, ship->pos.z,
ship->head.x, ship->head.y, ship->head.z );
return ship;
}If it looks correct in the log then I don't know what else might be the problem.
Offline
Sat Feb 6 02:07:38 2010 :: Ship Raider loaded with position 0,0,0 heading 1,-1,1
That's what I got after trying that. *mindboggle*
Offline
Come to think of it, the heading needs to be saved as a float/double with at least two decimals for things to work correctly. Position does not need this accuracy. You can also use just %f instead of any precision specifiers at all to be 100% sure that the heading stays exactly the same.
So...
fprintf( fp, "HX %f\n", ship->head.x );
And of course you'll need to make sure they are actually read as float/doubles too. I don't think swrfuss has a function to read floating point numbers. If not, you can just steal the one in SWR2 Refactor. You'll find it in src/swr_support/file_io.c and it's called fread_float.
So in hotboot.c, load_ship:
KEY( "HX", ship->head.x, fread_float( fp ) ); ... etc
As for the position being 0,0,0 that's odd. I'd make triple sure that you got those KEY values in load_ship just right.
Offline
Heading appears to be saving correctly. I modified a portion of course too:
if( arg3[0] == '\0' && argument[0] == '\0' )
{
if( ( planet = get_planet_here( arg2, ship->starsystem ) ) != NULL )
{
vector_set( &vec, planet->pos.x, planet->pos.y, planet->pos.z );
}
else if( ( target = get_ship_here( arg2, ship->starsystem ) ) != NULL )
{
vector_set( &vec, target->pos.x, target->pos.y, target->pos.z );
}
else
{
vector_set( &vec, atof( arg2 ), atof( arg3 ), atof( argument ) );
}
}
else
{
vector_set( &vec, atof( arg2 ), atof( arg3 ), atof( argument ) );
Is that acceptable? When I course to anything I get and check the heading in stat it shows:
Current Heading: -0.17 -0.48 0.86
Is that what it's supposed to do? I haven't fully wrapped my mind around the vector math.
Offline
The heading vector will typically be normalized. That is, truncated to numbers between -1 and 1, so those values are perfectly reasonable. You can think of it like reducing 3/9 to 1/3 which both give the same result.
Offline
Btw, that inner "else" doesn't make sense. You already checked that arg3 and argument are \0. I'm guessing you'd rather want to tell the player that no such spaceobject/target/whatever exists and then return?
Offline
Probably. Didn't think about that, was throwing it together at 3 am. Thanks for that catch.
Should the position also be loaded as fread_float as well?
Offline
No need to load the position as float. You can if you want, but nobody is ever going to notice the difference.
Offline
Heh, I found the problem. I screwed up in load_ship. It's working now. Thansk for the assistance.
Offline