Revision: 1388
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1388&view=rev
Author: rorthomas
Date: 2010-05-17 17:58:07 +0000 (Mon, 17 May 2010)
Log Message:
-----------
updated syntax a bit. more information:
http://wiki.rigsofrods.com/pages/Truck_Description_File/Syntax
two more commands ported
Modified Paths:
--------------
trunk/source/serializer/serializationmodules.cpp
trunk/source/serializer/serializer.cpp
Modified: trunk/source/serializer/serializationmodules.cpp
===================================================================
--- trunk/source/serializer/serializationmodules.cpp 2010-05-16 23:37:09 UTC
(rev 1387)
+++ trunk/source/serializer/serializationmodules.cpp 2010-05-17 17:58:07 UTC
(rev 1388)
@@ -583,6 +583,7 @@
// setup the base descriptions, etc, then register ourself
s->registerModuleSerializer(this);
s->addCommandHandler("fileinfo", this);
+ s->addCommandHandler("fileformatversion", this);
}
void FileInfoSerializer::initData(rig_t *rig)
@@ -596,8 +597,29 @@
int FileInfoSerializer::deserialize(char *line, rig_t *rig, std::string
activeSection)
{
if(!initiated) initData(rig);
- return checkRes(1, sscanf(line, "fileinfo %s, %i, %i",
rig->fileinfo->uniquetruckid, &rig->fileinfo->categoryid,
&rig->fileinfo->truckversion));
+ string linestr = string(line);
+ if(linestr.substr(0, 8) == "fileinfo")
+ {
+ return checkRes(1, sscanf(line, "fileinfo %s, %i, %i",
rig->fileinfo->uniquetruckid, &rig->fileinfo->categoryid,
&rig->fileinfo->truckversion));
+ } else if(linestr.substr(0, 17) == "fileformatversion")
+ {
+ int fileformatversion;
+ int result = sscanf(line,"fileformatversion %i",
&fileformatversion);
+ if (result < 1 || result == EOF)
+ {
+ //LogManager::getSingleton().logMessage("Error parsing
File (fileformatversion) " + String(fname) +" line " +
StringConverter::toString(linecounter) + ". trying to continue ...");
+ return 0;
+ }
+ if (fileformatversion > TRUCKFILEFORMATVERSION)
+ {
+ //LogManager::getSingleton().logMessage("The Truck File
" + String(fname) +" is for a newer version or RoR! trying to continue ...");
+ return 0;
+ }
+ mode=0;
+ }
+ return 0;
}
+
int FileInfoSerializer::serialize(char *line, rig_t *rig)
{
return sprintf(line, "fileinfo %s, %i, %i\n",
rig->fileinfo->uniquetruckid, rig->fileinfo->categoryid,
rig->fileinfo->truckversion);
@@ -677,6 +699,7 @@
// setup the base descriptions, etc, then register ourself
s->registerModuleSerializer(this);
s->addSectionHandler("engine", this);
+ s->addCommandHandler("patchEngineTorque", this);
}
void EngineSerializer::initData(rig_t *rig)
@@ -684,13 +707,21 @@
if(initiated) return;
rig->engine_section = new engine_section_t();
memset(rig->engine_section, 0, sizeof(engine_section_t));
+
+ // set engoption defaults
+ rig->engine_section->clutch = -1;
+ rig->engine_section->shifttime = -1;
+ rig->engine_section->clutchtime = -1;
+ rig->engine_section->postshifttime = -1;
+ rig->engine_section->type = 't';
+
initiated = true;
}
int EngineSerializer::deserialize(char *line, rig_t *rig, std::string
activeSection)
{
// ignore section header
- if(!strcmp(line, "engine"))
+ if(std::string(line) == activeSection)
return 1;
if(!initiated) initData(rig);
@@ -698,37 +729,61 @@
// shortcuts
engine_section_t *e = rig->engine_section;
- //parse engine
- int numgears;
- if(rig->driveable == MACHINE)
- // ignore engine section on machines
+ // parse some command
+ if (!strcmp("patchEngineTorque",line))
+ {
+ e->patchEngineTorque = true;
return 1;
+ }
- rig->driveable = TRUCK;
- int result = sscanf(line, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f,
%f, %f, %f, %f, %f, %f, %f, %f, %f, %f", \
- &e->minrpm, \
- &e->maxrpm, \
- &e->torque, \
- &e->dratio, \
- &e->rear, \
-
&e->gears[0],&e->gears[1],&e->gears[2],&e->gears[3],&e->gears[4],&e->gears[5],&e->gears[6],&e->gears[7],&e->gears[8],&e->gears[9],&e->gears[10],&e->gears[11],&e->gears[12],&e->gears[13],&e->gears[14],&e->gears[15]
- );
-
- if (result < 7 || result == EOF)
+ if(activeSection == "engine")
{
- //LogManager::getSingleton().logMessage("Error parsing File
(Engine) " + String(fname) +" line " + StringConverter::toString(linecounter) +
". trying to continue ...");
- return 0;
+ //parse engine
+ int numgears;
+ if(rig->driveable == MACHINE)
+ // ignore engine section on machines
+ return 1;
+
+ rig->driveable = TRUCK;
+ int result = sscanf(line, "%f, %f, %f, %f, %f, %f, %f, %f, %f,
%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f", \
+ &e->minrpm, \
+ &e->maxrpm, \
+ &e->torque, \
+ &e->dratio, \
+ &e->rear, \
+
&e->gears[0],&e->gears[1],&e->gears[2],&e->gears[3],&e->gears[4],&e->gears[5],&e->gears[6],&e->gears[7],&e->gears[8],&e->gears[9],&e->gears[10],&e->gears[11],&e->gears[12],&e->gears[13],&e->gears[14],&e->gears[15]
+ );
+
+ if (result < 7 || result == EOF)
+ {
+ //LogManager::getSingleton().logMessage("Error parsing
File (Engine) " + String(fname) +" line " +
StringConverter::toString(linecounter) + ". trying to continue ...");
+ return 0;
+ }
+ for (numgears = 0; numgears < MAX_GEARS; numgears++)
+ if (e->gears[numgears] <= 0)
+ break;
+ if (numgears < 3)
+ {
+ //LogManager::getSingleton().logMessage("Trucks with
less than 3 gears are not supported! " + String(fname) +" line " +
StringConverter::toString(linecounter) + ". trying to continue ...");
+ return -1;
+ }
+ e->numgears = numgears;
+ return result;
}
- for (numgears = 0; numgears < MAX_GEARS; numgears++)
- if (e->gears[numgears] <= 0)
- break;
- if (numgears < 3)
+
+ if(activeSection == "engoption")
{
- //LogManager::getSingleton().logMessage("Trucks with less than
3 gears are not supported! " + String(fname) +" line " +
StringConverter::toString(linecounter) + ". trying to continue ...");
- return -1;
+ //parse engoption
+ int result = sscanf(line,"%f, %c, %f, %f, %f, %f", &e->inertia,
&e->type, &e->clutch, &e->shifttime, &e->clutchtime, &e->postshifttime);
+ if (result < 1 || result == EOF)
+ {
+ //LogManager::getSingleton().logMessage("Error parsing
File (Engoption) " + String(fname) +" line " +
StringConverter::toString(linecounter) + ". trying to continue ...");
+ return 0;
+ }
+ return result;
}
- e->numgears = numgears;
- return result;
+
+ return 0;
}
int EngineSerializer::serialize(char *line, rig_t *rig)
Modified: trunk/source/serializer/serializer.cpp
===================================================================
--- trunk/source/serializer/serializer.cpp 2010-05-16 23:37:09 UTC (rev
1387)
+++ trunk/source/serializer/serializer.cpp 2010-05-17 17:58:07 UTC (rev
1388)
@@ -120,24 +120,32 @@
int RoRSerializer::processModules(char *line, rig_t *rig, SerializationContext
*ctx, std::string &activeSection)
{
+ string linestr = string(line);
// parse for commands or other sections
// commands
std::map < std::string, RoRSerializationModule *>::iterator it;
for(it = commands.begin(); it != commands.end() ; it++)
{
+ if(!it->first.size()) continue;
+
// check if that command is matched
- if(it->first.size() && !strncmp(it->first.c_str(), line,
it->first.size()))
+ if(linestr.substr(0, it->first.size()+2) == "=="+it->first))
{
- // match, using this module
- return it->second->deserialize(line, rig);
+ // new format
+ return it->second->deserialize(line+2, rig);
+ } else if(linestr.substr(0, it->first.size()) == it->first)
+ {
+ // old format
+ return it->second->deserialize(line, rig);
}
}
// sections
for(it = sections.begin(); it != sections.end() ; it++)
{
+ if(!it->first.size()) continue;
// check for a new section
- if(it->first.size() && !strcmp(it->first.c_str(), line))
+ if((it->first == linestr || "=" + it->first == linestr)
{
// match, using this module
//set section as active
@@ -145,6 +153,14 @@
// parse this as well, could be that the section header
contains information as well
return it->second->deserialize(line, rig,
activeSection);
}
+
+ // check for a section end
+ if("end_" + it->first == linestr || "=end_"+it->first ==
linestr)
+ {
+ // found section end
+ activeSection = string();
+ return 1;
+ }
}
// if we are in a section, parse it in its module handler
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel