RuleI* RuleTerrainCenter::makeRule(size_t i_rotations) { RuleI* rule = new RuleI; Pattern pIn(3,3), pOut(3,3); pIn(0,0) = 1; pIn(1,0) = 1; pIn(2,0) = 1; pIn(0,1) = 1; pIn(1,1) = 1; pIn(2,1) = 1; pIn(0,2) = 1; pIn(1,2) = 1; pIn(2,2) = 1; pOut(0,0) = 0; pOut(1,0) = 0; pOut(2,0) = 0; pOut(0,1) = 0; pOut(1,1) = 2; pOut(2,1) = 0; pOut(0,2) = 0; pOut(1,2) = 0; pOut(2,2) = 0; rule->d_input = pIn; rule->addOutputPattern( pOut ); return rule; }
RuleI* RuleTerrainInsideCorner::makeRule(size_t i_rotations) { RuleI* rule = new RuleI; Pattern pIn(2,2), pOut(2,2); pIn(0,0) = 1; pIn(1,0) = 1; pIn(0,1) = 2; pIn(1,1) = 1; pOut(0,0) = 3; pOut(1,0) = 3; pOut(0,1) = 4; pOut(1,1) = 3; for(size_t i=0;i<i_rotations;++i) { pIn = pIn.rotate(); pOut = pOut.rotate(); } rule->d_input = pIn; rule->addOutputPattern( pOut ); return rule; }
RuleI* RuleSimpleChange::makeRule(size_t) { RuleI* rule = new RuleI; Pattern pIn(1,1), pOut(1,1); pIn(0,0) = 1; pOut(0,0) = 2; rule->d_input = pIn; rule->addOutputPattern( pOut ); return rule; }
void PTrackManager::UpdateGraphics() { // Update Graphics Module pOut("\tUpdating Graphics Module.\n"); raceManager->_reGraphicItf.PGrDetach3DDesc(track->GetTrackDesc()); // Detach existing description from scene graph pOut("\tGenerating new 3D Description.\n"); // Update the AC File UpdateACFile(); // Append existing 3D Description raceManager->_reGraphicItf.PGrAppend3DDesc(track); // Reattach 3D description raceManager->_reGraphicItf.PGrAttach3DDesc(track->GetTrackDesc()); }
/** * @function WavStop * @brief stop the WAV playback * @param none * @return none */ void WavStop(void) { if(state != WAV_STOPPED) { state = WAV_STOPPED; TmrStop(WAV_TIMER); /*disable the callback*/ f_close(&pFile); pOut(0x8000); /*clear the DAC*/ } }
inline Vectors::Point2DCont transform(const Vectors::Point2DCont &pt) const { // transformaion is: // Ybase=[sin_a; cos_a] // Xbase=[cos_a;-sin_a] const double x= pt[0]*_cos_a + pt[1]*_sin_a; const double y=-pt[0]*_sin_a + pt[1]*_cos_a; Vectors::Point2DCont pOut( x+_pos[0], y+_pos[1] ); // verctor + offset return pOut; // return result };
void PTrackManager::AddSegment(const PSeg& segment) { pOut("Adding new Segment....\n"); // Add Segment pOut("\tAdding segment to track.\n"); track->AddSegment(segment); pOut("New segment added.\n"); // Calculate new segment ranges if (segment.type != TR_STR) { PCornerType t; if (segment.type == TR_LFT) t = PCornerType::CTLeft; else t = PCornerType::CTRight; segFactory->UpdateRanges(track->GetEnd()->arc, t); } }
/** * @function WavPlaback_1CH_16BITS * @brief wav handle for 1 channel, 16bits * @param none * @return none */ static void Callback_1CH_16BITS(void) { /*use buffer 1?*/ if(bufferToUse == BUFFER_1 && isBuffer1Empty == false) { pOut(0x8000 + buf1[posBuf1]); posBuf1++; if(posBuf1 >= BUF_SIZE) { bufferToUse = BUFFER_2; isBuffer1Empty = true; } } /*use buffer 2?*/ else if(bufferToUse == BUFFER_2 && isBuffer2Empty == false) { pOut(0x8000 + buf2[posBuf2]); posBuf2++; if(posBuf2 >= BUF_SIZE) { bufferToUse = BUFFER_1; isBuffer2Empty = true; } } }
P2DVec2 CoordinateInterface::MapToEngine(QPointF pIn) {//qDebug()<<"MapToEngine input"<<pIn; float32 x = (pIn.x()-(-SCENE_WIDTH_HALF)) / (SCENE_WIDTH_HALF*2) * (ENGINE_SCENE_MAXIMUM_HALF*2) + (-ENGINE_SCENE_MAXIMUM_HALF); float32 y = (pIn.y()-(-SCENE_HEIGHT_HALF)) / (SCENE_HEIGHT_HALF*2) * (ENGINE_SCENE_MAXIMUM_HALF*2) + (-ENGINE_SCENE_MAXIMUM_HALF); P2DVec2 pOut(x,y); return pOut; }
QPointF CoordinateInterface::MapToScene(P2DVec2 pIn) {//qDebug()<<"MapToScene input"<<pIn; qreal x = (pIn.x-(-ENGINE_SCENE_MAXIMUM_HALF)) / (ENGINE_SCENE_MAXIMUM_HALF*2) * (SCENE_WIDTH_HALF*2) + (-SCENE_WIDTH_HALF); qreal y = (pIn.y-(-ENGINE_SCENE_MAXIMUM_HALF)) / (ENGINE_SCENE_MAXIMUM_HALF*2) * (SCENE_HEIGHT_HALF*2) + (-SCENE_HEIGHT_HALF); QPointF pOut(x,y); return pOut; }
void TimeDifference<Qin, Qout>::operator()() { rtb::Concurrency::Latch internalLatch(3); TimeProbe<Qin> pIn(queueIn_, internalLatch); TimeProbe<Qout> pOut(queueOut_, internalLatch); std::thread thrIn(std::ref(pIn)); std::thread thrOut(std::ref(pOut)); internalLatch.wait(); doneWithSubscriptions_.wait(); thrIn.join(); thrOut.join(); doneWithExecutions_.wait(); wallClockDifference_ = pOut.getWallClockTimes() - pIn.getWallClockTimes(); cpuClockDifference_ = pOut.getCpuClockTimes() - pIn.getCpuClockTimes(); }
void PTrackManager::InitTrack() { // Retrieve the load state from the file manager PTrackLoadState loadState = PFileManager::Get()->GetTrackLoadState(); // If no config is set, then set to the first config in the directory if (!loadState.ConfigName().compare(NO_CONFIG_SET)) { PFileManager* fManager = PFileManager::Get(); std::vector<std::string> configs = fManager->DirectoriesInDirectory(std::string(fManager->GetCurrentDir()) + "tracks\\procedural\\"); loadState.SetConfiguration(configs[0], "tracks/procedural/" + configs[0] + "/"); } pOut("Track manager obtaining pointer to segment factory...\n"); segFactory = PSegFactory::GetInstance(); // Obtain pointer to segment factory pOut("Initializing segment factory...\n"); segFactory->SetChances(45.f, 65.f); // Set neccesary paths std::string modeldir("tracks/procedural/" + loadState.ConfigName() + "/"); std::string texturedir("data/textures"); pOut("Setting Track 3D Description Loader Options...\n"); ssgLoaderOptions* lopts = new ssgLoaderOptions(); lopts->setModelDir(modeldir.c_str()); lopts->setTextureDir(texturedir.c_str()); if (loadState.LoadType() == PLoadType::CONFIG) // Default TORCS Adaptive track initialization - initializes a configuration for a procedural track { pOut("Initialize procedural track configuration...\n"); pOut("Setting track file path and file names...\n"); std::string acname(loadState.ConfigName() + ".ac"); std::string acpath("tracks/procedural/" + loadState.ConfigName() + "/"); std::string configpath(acpath); std::string configname(loadState.ConfigFileName()); // Initialize the procedural track. pOut("Initializing procedural track structure...\n"); track = new PTrack(loadState.Length(), configpath, acpath, configname, acname, lopts); // Point the racemanager to the procedural track pOut("Setting racemanager track to procedural track...\n"); raceManager->track = track->trk; previousSegType = track->GetEnd()->type; // Set track type trackType = PTrackType::PROCEDURAL; } else if (loadState.LoadType() == PLoadType::TRACK) // Initialization if a pre-generated track is to be loaded { // Read in the segments std::vector<PSeg> segs = PFileManager::Get()->ReadTrackSegments(loadState.TrackPath() + loadState.TrackFileName()); // Construct paths and names std::string acname(loadState.TrackName() + ".ac"); std::string acpath("tracks/procedural/" + loadState.ConfigName() + "/previousTracks/" + loadState.TrackName() + "/"); std::string configpath("tracks/procedural/" + loadState.ConfigName() + "/"); std::string configname(loadState.ConfigFileName()); // Obtain track length void* handle = GfParmReadFile((loadState.TrackPath() + loadState.TrackFileName()).c_str(), GFPARM_RMODE_STD); tdble trkLength = GfParmGetNum(handle, P_TRK_SECT_HDR, P_TRK_ATT_LENGTH, (char*)nullptr, 1000); // Initialize the procedural track object track = new PTrack(segs, trkLength, configpath, acpath, configname, acname, lopts); // Add a finish line track->AddFinishLine(); // Point the racemanager to the procedural track raceManager->track = track->trk; // Set the track's name raceManager->track->name = new char[loadState.TrackName().length()]; strcpy((char*)raceManager->track->name, loadState.TrackName().c_str()); strcpy(raceManager->track->internalname, loadState.TrackName().c_str()); // Set track type trackType = PTrackType::PREGENERATED; } // Create a random previous corner type to start with int c = segFactory->CreateRandomCnr(0).type; if (c == TR_LFT) previousCornerType = PCornerType::CTLeft; else previousCornerType = PCornerType::CTRight; }
PTrackManager::PTrackManager(tRmInfo* RaceManager) { pOut("Initializing procedural track manager...\n"); raceManager = RaceManager; // Save pointer to race manager }
void VDCreateTestPal8Video(VDGUIHandle h) { CPUEnableExtensions(CPUCheckForExtensions()); try { tVDInputDrivers inputDrivers; std::vector<int> xlat; VDGetInputDrivers(inputDrivers, IVDInputDriver::kF_Video); const VDStringW filter(VDMakeInputDriverFileFilter(inputDrivers, xlat)); const VDFileDialogOption opt[]={ { VDFileDialogOption::kSelectedFilter }, 0 }; int optval[1]={0}; const VDStringW srcfile(VDGetLoadFileName('pl8s', h, L"Choose source file", filter.c_str(), NULL, opt, optval)); if (srcfile.empty()) return; IVDInputDriver *pDrv; int filtidx = xlat[optval[0] - 1]; if (filtidx < 0) pDrv = VDAutoselectInputDriverForFile(srcfile.c_str(), IVDInputDriver::kF_Video); else { tVDInputDrivers::iterator itDrv(inputDrivers.begin()); std::advance(itDrv, filtidx); pDrv = *itDrv; } vdrefptr<InputFile> pIF(pDrv->CreateInputFile(0)); pIF->Init(srcfile.c_str()); const VDStringW dstfile(VDGetSaveFileName('pl8d', h, L"Choose destination 8-bit file", L"Audio-video interleaved (*.avi)\0*.avi\0All files\0*.*", L"avi", NULL, NULL)); if (dstfile.empty()) return; vdrefptr<IVDVideoSource> pVS; pIF->GetVideoSource(0, ~pVS); IVDStreamSource *pVSS = pVS->asStream(); const VDPosition frames = pVSS->getLength(); if (!pVS->setTargetFormat(nsVDPixmap::kPixFormat_XRGB8888)) throw MyError("Cannot set decompression format to 32-bit."); vdautoptr<IVDMediaOutputAVIFile> pOut(VDCreateMediaOutputAVIFile()); IVDMediaOutputStream *pVSOut = pOut->createVideoStream(); const VDPixmap& pxsrc = pVS->getTargetFormat(); const uint32 rowbytes = (pxsrc.w+3) & ~3; AVIStreamHeader_fixed hdr; hdr.fccType = 'sdiv'; hdr.fccHandler = 0; hdr.dwFlags = 0; hdr.wPriority = 0; hdr.wLanguage = 0; hdr.dwScale = pVSS->getStreamInfo().dwScale; hdr.dwRate = pVSS->getStreamInfo().dwRate; hdr.dwStart = 0; hdr.dwLength = 0; hdr.dwInitialFrames = 0; hdr.dwSuggestedBufferSize = 0; hdr.dwQuality = -1; hdr.dwSampleSize = 0; hdr.rcFrame.left = 0; hdr.rcFrame.top = 0; hdr.rcFrame.right = (short)pxsrc.w; hdr.rcFrame.bottom = (short)pxsrc.h; pVSOut->setStreamInfo(hdr); vdstructex<BITMAPINFOHEADER> bih; bih.resize(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*252); bih->biSize = sizeof(BITMAPINFOHEADER); bih->biWidth = pxsrc.w; bih->biHeight = pxsrc.h; bih->biPlanes = 1; bih->biBitCount = 8; bih->biCompression = BI_RGB; bih->biSizeImage = rowbytes*pxsrc.h; bih->biXPelsPerMeter = 0; bih->biYPelsPerMeter = 0; bih->biClrUsed = 252; bih->biClrImportant = 252; RGBQUAD *pal = (RGBQUAD *)((char *)bih.data() + sizeof(BITMAPINFOHEADER)); for(int i=0; i<252; ++i) { pal[i].rgbRed = (BYTE)((i/42)*51); pal[i].rgbGreen = (BYTE)((((i/6)%7)*85)>>1); pal[i].rgbBlue = (BYTE)((i%6)*51); pal[i].rgbReserved = 0; } pVSOut->setFormat(bih.data(), bih.size()); pOut->init(dstfile.c_str()); ProgressDialog dlg((HWND)h, "Processing video stream", "Palettizing frames", (long)frames, true); vdblock<uint8> outbuf(rowbytes * pxsrc.h); const vdpixsize w = pxsrc.w; const vdpixsize h = pxsrc.h; try { for(uint32 frame=0; frame<frames; ++frame) { pVS->getFrame(frame); const uint8 *src = (const uint8 *)pxsrc.data; ptrdiff_t srcpitch = pxsrc.pitch; uint8 *dst = &outbuf[rowbytes * (pxsrc.h - 1)]; for(int y=0; y<h; ++y) { const uint8 *dr = ditherred[y & 15]; const uint8 *dg = dithergrn[y & 15]; const uint8 *db = ditherblu[y & 15]; for(int x=0; x<w; ++x) { const uint8 b = (uint8)((((src[0] * 1286)>>8) + dr[x&15]) >> 8); const uint8 g = (uint8)((((src[1] * 1543)>>8) + dg[x&15]) >> 8); const uint8 r = (uint8)((((src[2] * 1286)>>8) + db[x&15]) >> 8); src += 4; dst[x] = (uint8)(r*42 + g*6 + b); } vdptrstep(dst, -(ptrdiff_t)rowbytes); vdptrstep(src, srcpitch - w*4); } pVSOut->write(AVIOutputStream::kFlagKeyFrame, outbuf.data(), outbuf.size(), 1); dlg.advance(frame); dlg.check(); } } catch(const MyUserAbortError&) { } pVSOut->flush(); pOut->finalize(); } catch(const MyError& e) { e.post((HWND)h, g_szError); } }