void EntityResourceManager::loadResource(const std::string filepath) { //open up the file std::filebuf fb; fb.open(filepath, std::ios::in); //try to parse it Json::Value root; Json::Reader reader; bool parseSuccessful = reader.parse(std::istream(&fb), root); //now we have it parsed we can close it fb.close(); if(!parseSuccessful) { std::cerr << "Unable to load entity: " << filepath << std::endl; std::cerr << reader.getFormattedErrorMessages() << std::endl; return; } Entity *entityPtr = loadType(root); if(entityPtr == NULL) { std::cerr << "Invalid type in entity file " << filepath << std::endl; return; } loadGenerics(*entityPtr, root); loadDamagingEntity(*entityPtr, root); loadCharacter(*entityPtr, root); std::string behaviour = root.get("behaviour", "").asString(); if(!behaviour.empty()) { loadBehaviour(*entityPtr, root); } Json::Value animations = root["animations"]; if(animations.size() > 0) { loadAnimations(*entityPtr, root); } Json::Value abilities = root["abilities"]; if(abilities.size() > 0) { loadAbilities(*entityPtr, root); } resourceMap[filepath] = entityPtr; }
MyCar::MyCar(TrackDesc* track, tCarElt* car, tSituation *situation) { AEROMAGIC = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_AMAGIC, (char*)NULL, 1.6f); CFRICTION = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_FMAGIC, (char*)NULL, 1.0f); /* init pointer to car data */ setCarPtr(car); initCGh(); initCarGeometry(); updatePos(); updateDir(); updateSpeedSqr(); updateSpeed(); /* damage and fuel status */ lastfuel = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_FUEL, NULL, 100.0); undamaged = situation->_maxDammage; if (undamaged == 0) undamaged = 10000; MAXDAMMAGE = undamaged / 2; fuelperlap = 0.0; lastpitfuel = 0.0; /* set up some car properties */ wheelbase = car->priv.wheel[FRNT_RGT].relPos.x - car->priv.wheel[REAR_RGT].relPos.x; wheeltrack = 2* fabs(car->priv.wheel[REAR_RGT].relPos.y); carmass = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_MASS, NULL, 0.0); mass = carmass + lastfuel; /* which wheels are driven */ char *traintype = GfParmGetStr(car->_carHandle, SECT_DRIVETRAIN, PRM_TYPE, VAL_TRANS_RWD); if (strcmp(traintype, VAL_TRANS_RWD) == 0) { drivetrain = DRWD; } else if (strcmp(traintype, VAL_TRANS_FWD) == 0) { drivetrain = DFWD; } else if (strcmp(traintype, VAL_TRANS_4WD) == 0) { drivetrain = D4WD; } updateCa(); double cx = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_CX, (char*)NULL, 0.0); double frontarea = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_FRNTAREA, (char*)NULL, 0.0); cw = 0.625*cx*frontarea; cgcorr_b = 0.46; pf = new Pathfinder(track, car, situation); currentsegid = destsegid = pf->getCurrentSegment(car); currentseg = track->getSegmentPtr(currentsegid); destseg = track->getSegmentPtr(destsegid); currentpathseg = pf->getPathSeg(currentsegid); destpathseg = pf->getPathSeg(destsegid); turnaround = 0.0; tr_mode = 0; accel = 1.0; fuelchecked = false; startmode = true; trtime = 0.0; derror = 0.0; /* DIST; MAXRELAX; MAXANGLE; ACCELINC; SPEEDSQRFACTOR; GCTIME; ACCELLIMIT; PATHERRFACTOR */ double ba[6][8] = { {1.2, 0.9, 25.0, 0.1, 1.2, 0.2, 1.0, 5.0}, {1.2, 0.9, 20.0, 0.1, 1.1, 0.5, 1.0, 5.0}, {1.2, 0.9, 15.0, 0.1, 1.0, 0.5, 1.0, 5.0}, {1.3, 0.9, 15.0, 0.02, 0.98, 0.5, 1.0, 5.0}, {1.6, 0.9, 15.0, 0.01, 0.95, 0.5, 1.0, 5.0}, {1.2, 0.9, 45.0, 0.1, 1.0, 0.5, 1.0, 1.0} }; for (int i = 0; i < 6; i++) { for (int j = 0; j < 8; j++) { behaviour[i][j] = ba[i][j]; } } loadBehaviour(NORMAL); /* this call is needed! perhaps i shold move it into the constructor of pathfinder. */ pf->plan(this); }
MyCar::MyCar(TrackDesc* track, tCarElt* car, tSituation *situation) { AEROMAGIC = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_AMAGIC, (char*)NULL, 1.6f); CFRICTION = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_FMAGIC, (char*)NULL, 1.0f); setCarPtr(car); initCGh(); initCarGeometry(); updatePos(); updateDir(); updateSpeedSqr(); updateSpeed(); // Damage and fuel status. lastfuel = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_FUEL, NULL, 100.0); undamaged = situation->_maxDammage; if (undamaged == 0) { undamaged = 10000; } MAXDAMMAGE = undamaged / 2; fuelperlap = 0.0; lastpitfuel = 0.0; // Set up some car properties. wheelbase = car->priv.wheel[FRNT_RGT].relPos.x - car->priv.wheel[REAR_RGT].relPos.x; wheeltrack = 2* fabs(car->priv.wheel[REAR_RGT].relPos.y); carmass = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_MASS, NULL, 0.0); mass = carmass + lastfuel; // Which wheels are driven. const char *traintype = GfParmGetStr(car->_carHandle, SECT_DRIVETRAIN, PRM_TYPE, VAL_TRANS_RWD); if (strcmp(traintype, VAL_TRANS_RWD) == 0) { drivetrain = DRWD; } else if (strcmp(traintype, VAL_TRANS_FWD) == 0) { drivetrain = DFWD; } else if (strcmp(traintype, VAL_TRANS_4WD) == 0) { drivetrain = D4WD; } updateCa(); double cx = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_CX, (char*)NULL, 0.0); double frontarea = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_FRNTAREA, (char*)NULL, 0.0); cw = 0.625*cx*frontarea; // Get PGAIN. STEER_P_CONTROLLER_GAIN = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_STEERPGAIN, (char*)NULL, 0.02f); STEER_P_CONTROLLER_MAX = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_STEERPGAIN_MAX, (char*)NULL, 0.1f); //printf("PC: %f, %f\n", STEER_P_CONTROLLER_GAIN, STEER_P_CONTROLLER_MAX); // Magic number for friction in pit lane, because the current code does not consider the pit surface. // TODO: Consider the pit surface properties. cgcorr_b = 0.46; pf = new Pathfinder(track, car, situation); currentsegid = destsegid = pf->getCurrentSegment(car); currentseg = track->getSegmentPtr(currentsegid); destseg = track->getSegmentPtr(destsegid); currentpathsegid = currentsegid; destpathsegid = destsegid; dynpath = pf->getPath(); turnaround = 0.0; tr_mode = 0; accel = 1.0; fuelchecked = false; startmode = true; trtime = 0.0; derror = 0.0; clutchtime = 0.0; // DIST; MAXRELAX; MAXANGLE; ACCELINC; SPEEDSQRFACTOR; GCTIME; ACCELLIMIT; PATHERRFACTOR double ba[6][8] = { {1.2, 0.9, 25.0, 0.1, 1.2, 0.2, 1.0, 5.0}, {1.2, 0.9, 20.0, 0.1, 1.1, 0.5, 1.0, 5.0}, {1.2, 0.9, 15.0, 0.1, 1.0, 0.5, 1.0, 5.0}, {1.3, 0.9, 15.0, 0.02, 0.98, 0.5, 1.0, 5.0}, {1.6, 0.9, 15.0, 0.01, 0.95, 0.5, 1.0, 5.0}, {1.2, 0.9, 45.0, 0.1, 1.0, 0.5, 1.0, 1.0} }; for (int i = 0; i < 6; i++) { for (int j = 0; j < 8; j++) { behaviour[i][j] = ba[i][j]; } } loadBehaviour(NORMAL); // Init optimal trajectory. pf->plan(this, currentsegid); }