void PlayerShip::Load() { //Load Researched Weapons QFile rwfile("researched.glc"); if (!rwfile.open(QIODevice::ReadOnly | QIODevice::Text) ) { return; } QTextStream rw_in(&rwfile); while(!rw_in.atEnd()) { QString line = rw_in.readLine(); QStringList data = line.split(","); QString name = data.at(0); int attack = data.at(1).toInt(); int size = data.at(2).toInt(); int upkeep = data.at(3).toInt(); ResearchedWeapons->push_back(ShipWeapon(name,attack,size,upkeep)); line = ""; } rwfile.close(); //======================================== //Load Special Weapons QFile swfile("special.glc"); if (!swfile.open(QIODevice::ReadOnly | QIODevice::Text) ) { return; } QTextStream sw_in(&swfile); while(!sw_in.atEnd()) { QString line = sw_in.readLine(); QStringList data = line.split(","); QString name = data.at(0); int attack = data.at(1).toInt(); int size = data.at(2).toInt(); int upkeep = data.at(3).toInt(); int max = data.at(4).toInt(); QString type = data.at(5); int invasion = data.at(6).toInt(); double bonus = data.at(7).toDouble(); SpecialWeapons->push_back(ShipWeapon(name,attack,size,upkeep,max,type,invasion,bonus)); } swfile.close(); }
/* loop receiving kevents */ void kq_loop(void) { struct kqfile *f; struct kevent ke; int i; char buf[BUFSIZ]; while (1) { memset(&ke, 0x00, sizeof(ke)); memset(buf, 0x00, sizeof(buf)); i = kevent(kq, NULL, 0, &ke, 1, NULL); if (i == -1) err(1, "kevent"); f = (struct kqfile *)ke.udata; /* data to read */ if (ke.filter == EVFILT_READ) { if (ke.data < 0) { printf("%s has shrunk\n", f->path); lseek(f->fd, 0, SEEK_END); continue; } i = rwfile(f, buf, sizeof(buf), ke.data); if (i == -1) warn("read %s", f->path); } else if (ke.filter == EVFILT_VNODE && (ke.fflags & NOTE_DELETE || ke.fflags & NOTE_RENAME)) { if (kqfreopen(f) == -1) { warn("%s went away and didnt come back", f->path); kqfremove(f); } } } }