void ListFilesInDirRecursive(const std::string &Dir, long *Epoch, Vector<std::string> *V, bool TopDir) { auto E = GetEpoch(Dir); if (Epoch) if (E && *Epoch >= E) return; DIR *D = opendir(Dir.c_str()); if (!D) { Printf("No such directory: %s; exiting\n", Dir.c_str()); exit(1); } while (auto E = readdir(D)) { std::string Path = DirPlusFile(Dir, E->d_name); if (E->d_type == DT_REG || E->d_type == DT_LNK || (E->d_type == DT_UNKNOWN && IsFile(Path))) V->push_back(Path); else if ((E->d_type == DT_DIR || (E->d_type == DT_UNKNOWN && IsDirectory(Path))) && *E->d_name != '.') ListFilesInDirRecursive(Path, Epoch, V, false); } closedir(D); if (Epoch && TopDir) *Epoch = E; }
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V, long *Epoch) { long E = Epoch ? *Epoch : 0; for (auto &X : ListFilesInDir(Path, Epoch)) { auto FilePath = DirPlusFile(Path, X); if (Epoch && GetEpoch(FilePath) < E) continue; V->push_back(FileToVector(FilePath)); } }
void StarGeneratorInterface::__IntegerValueUpdated( SpinBox& sender, int value ) { if ( sender == GUI->RAHours_SpinBox || sender == GUI->RAMins_SpinBox ) GetRA(); else if ( sender == GUI->DecDegs_SpinBox || sender == GUI->DecMins_SpinBox ) GetDec(); else if ( sender == GUI->EpochYear_SpinBox || sender == GUI->EpochMonth_SpinBox || sender == GUI->EpochDay_SpinBox ) GetEpoch(); }
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V, long *Epoch) { long E = Epoch ? *Epoch : 0; auto Files = ListFilesInDir(Path, Epoch); for (size_t i = 0; i < Files.size(); i++) { auto &X = Files[i]; auto FilePath = DirPlusFile(Path, X); if (Epoch && GetEpoch(FilePath) < E) continue; if ((i % 1000) == 0 && i) Printf("Loaded %zd/%zd files from %s\n", i, Files.size(), Path); V->push_back(FileToVector(FilePath)); } }
std::string OrbitalBody::ToString(const std::string& prefix) const { std::ostringstream os; os << prefix << "Name: " << GetName() << std::endl; os << prefix << "Physical properties:" << std::endl; os << GetPhysicalProperties().ToDetailedString(prefix + " "); os << prefix << "Epoch:" << std::endl; os << GetEpoch().ToDetailedString(prefix + " "); os << prefix << "Orbit:" << std::endl; os << GetOrbit().ToString(prefix + " ") << std::endl; //os << prefix << "Ephemeris:" << std::endl; return os.str(); }
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V, long *Epoch, size_t MaxSize) { long E = Epoch ? *Epoch : 0; std::vector<std::string> Files; ListFilesInDirRecursive(Path, Epoch, &Files, /*TopDir*/true); size_t NumLoaded = 0; for (size_t i = 0; i < Files.size(); i++) { auto &X = Files[i]; if (Epoch && GetEpoch(X) < E) continue; NumLoaded++; if ((NumLoaded & (NumLoaded - 1)) == 0 && NumLoaded >= 1024) Printf("Loaded %zd/%zd files from %s\n", NumLoaded, Files.size(), Path); V->push_back(FileToVector(X, MaxSize)); } }
void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V, long *Epoch, size_t MaxSize) { long E = Epoch ? *Epoch : 0; auto Files = ListFilesInDir(Path, Epoch); size_t NumLoaded = 0; for (size_t i = 0; i < Files.size(); i++) { auto &X = Files[i]; auto FilePath = DirPlusFile(Path, X); if (Epoch && GetEpoch(FilePath) < E) continue; NumLoaded++; if ((NumLoaded & (NumLoaded - 1)) == 0 && NumLoaded >= 1024) Printf("Loaded %zd/%zd files from %s\n", NumLoaded, Files.size(), Path); V->push_back(FileToVector(FilePath, MaxSize)); } }
static std::vector<std::string> ListFilesInDir(const std::string &Dir, long *Epoch) { std::vector<std::string> V; if (Epoch) { auto E = GetEpoch(Dir.c_str()); if (*Epoch >= E) return V; *Epoch = E; } DIR *D = opendir(Dir.c_str()); if (!D) return V; while (auto E = readdir(D)) { if (E->d_type == DT_REG || E->d_type == DT_LNK) V.push_back(E->d_name); } closedir(D); return V; }
void MpcorbBody::VInitialize() { const auto& name = GetName(); const auto& epoch = GetEpoch(); // Init the physical properties m_physicalProperties = m_ephemeris.GetPhysicalProperties(name); // Init the reference epoch and orbital elements m_referenceEpoch = m_ephemeris.GetReferenceEpoch(name); m_referenceOrbitalElements = m_ephemeris.GetReferenceOrbitalElements(name); // Init the orbit double mu = m_ephemeris.GetGravitationalParameterCentralBody(name); m_orbit = keplerian::Orbit(mu, m_referenceOrbitalElements, keplerian::Orbit::Direction::Prograde); m_orbit.Propagate(epoch - m_referenceEpoch); }
static std::vector<std::string> ListFilesInDir(const std::string &Dir, long *Epoch) { std::vector<std::string> V; if (Epoch) { auto E = GetEpoch(Dir); if (E && *Epoch >= E) return V; *Epoch = E; } DIR *D = opendir(Dir.c_str()); if (!D) { Printf("No such directory: %s; exiting\n", Dir.c_str()); exit(1); } while (auto E = readdir(D)) { if (E->d_type == DT_REG || E->d_type == DT_LNK) V.push_back(E->d_name); } closedir(D); return V; }
void GameProcessSessionBuffer(session_node *s) { client_msg msg; unsigned short security; s->game->game_last_message_time = GetTime(); if (s->game->game_state != GAME_NORMAL) { GameSyncProcessSessionBuffer(s); return; } /* need to copy only as many bytes as we can hold */ while (s->receive_list != NULL) { if (PeekSessionBytes(s,HEADERBYTES,&msg) == False) return; if (msg.len != msg.len_verify) { /* dprintf("GPSB found len != len_verify %i %i\n",msg_len,msg_len_verify); */ GameSendResync(s); GameSyncInit(s); GameSyncProcessSessionBuffer(s); return; } if (msg.len > LEN_MAX_CLIENT_MSG) { eprintf("GameProcessSessionBuffer got message too long %i\n",msg.len); GameSendResync(s); GameSyncInit(s); GameSyncProcessSessionBuffer(s); return; } /* now read the header for real, plus the actual data */ if (ReadSessionBytes(s,msg.len+HEADERBYTES,&msg) == False) return; /* dprintf("got crc %08x\n",msg.crc16); */ security = GameRandomStreamsStep(s); /* dprintf("%08x is the next stream thing\n",security); */ security ^= msg.len; security ^= ((unsigned int)msg.data[0] << 4); security ^= GetCRC16(msg.data,msg.len); /* dprintf("%08x is the next stream thing after xor\n",security); */ if (msg.crc16 != security && !s->seeds_hacked) { s->seeds_hacked = True; if (ConfigBool(SECURITY_LOG_SPOOFS)) { lprintf("GameProcessSessionBuffer found invalid security account %i\n", s->account->account_id); } if (ConfigBool(SECURITY_HANGUP_SPOOFS)) { HangupSession(s); } // can't use the packet, so throw it away and go into resync mode GameSendResync(s); GameSyncInit(s); GameSyncProcessSessionBuffer(s); return; } if (msg.seqno != GetEpoch()) /* old sequence ok, just ignore */ { /* dprintf("Game got bad epoch from session %i\n",s->session_id); */ continue; } /* give up receive mutex, so the interface/socket thread can read data for us, even if doing something long (GC/save/reload sys) */ if (!ReleaseMutex(s->muxReceive)) eprintf("GPSB released mutex it didn't own in session %i\n",s->session_id); GameProtocolParse(s,&msg); if (WaitForSingleObject(s->muxReceive,10000) != WAIT_OBJECT_0) { eprintf("GPSB bailed waiting for mutex on session %i\n",s->session_id); return; } /* if hung up, don't touch */ if (s->hangup == True) return; if (s->state != STATE_GAME) return; if (s->game->game_state != GAME_NORMAL) return; } }