I'm working on level saving, in the engine i've been working on.
I've created the following functions:
save:
Code:
void level::savestaticmesh(char *fname)
{
remove(fname);
for (int i=0; i<num_meshs; i++)
{
stream = fopen(fname, "a");
fprintf(stream, "%s %s %s %d %d %d %f %f %f %f %f %f %f %f %f\n",
meshP[i].filename, meshP[i].tex1, meshP[i].tex2, meshP[i].textype, meshP[i].repeatx, meshP[i].repeaty,
meshP[i].pos.x, meshP[i].pos.y, meshP[i].pos.z,
meshP[i].scale.x, meshP[i].scale.z, meshP[i].scale.y,
meshP[i].rot.x, meshP[i].rot.y, meshP[i].rot.z);
fclose(stream);
}
}
load:
Code:
void level::loadstaticmesh(char *fname)
{
stream = fopen(fname, "r");
while(1)
{
int result = fscanf(stream, "%s %s %s %d %d %d %f %f %f %f %f %f %f %f %f\n",
tmpfname, tmptex0, tmptex1, &tmptype, &tmprx, &tmpry,
&tmppos.x, &tmppos.y, &tmppos.z,
&tmpscale.x, &tmpscale.z, &tmpscale.y,
&tmprot.x, &tmprot.y, &tmprot.z);
if(result==EOF)
break;
meshnum++;
}
rewind(stream);
for(int i=0; i<meshnum; i++)
{
fscanf(stream, "%s %s %s %d %d %d %f %f %f %f %f %f %f %f %f\n",
tmpfname, tmptex0, tmptex1, &tmptype, &tmprx, &tmpry,
&tmppos.x, &tmppos.y, &tmppos.z,
&tmpscale.x, &tmpscale.z, &tmpscale.y,
&tmprot.x, &tmprot.y, &tmprot.z);
if(tmprx==0)
tmprx=1;
if(tmpry==0)
tmpry=1;
_ceStaticMesh->createstaticmesh(tmpfname, tmptex0, tmptex1, tmptype, tmprx, tmpry,
tmppos.x, tmppos.y, tmppos.z,
tmprot.x, tmprot.y, tmprot.z,
tmpscale.x, tmpscale.y, tmpscale.z);
}
fclose(stream);
}
I've run into some trouble though.
Suppose I create two cubes. They each have different texture names, and different positions. I click the 'save' button, and exit the engine. Restart the engine, both cubes are still rendered with different textures; the save appears to have worked correctly. Click 'save' and exit again. Restart, both cubes now have the same texture; the second save messed up.
Just for clarification, the load function reads through the formatted text, and creates a staticmesh entity with the createstaticmesh() function. The function arguments are stored in the array meshP[]. On save, the meshP[] array index is cycled through, and the arguments are read into the file...I'm sure you get the idea.
Any help will be very much appreciated!
-psychopath