void MeshBufferReader::setMeshPyramid()
{
    TICK("setupMeshBufferRendering");
    
    visibilityMaskPyramid.resize(m_nNumMeshLevels);
    outputInfoPyramid.resize(m_nNumMeshLevels);
    outputPropPyramid.resize(m_nNumMeshLevels);

    for(int i = 0; i < m_nNumMeshLevels; ++i)
    {
        int numVertices = currentMeshPyramid.levels[i].numVertices;
        visibilityMaskPyramid[i].resize(numVertices,true);

        vector<CoordinateType> proj2D;
        proj2D.resize(2); proj2D[0] = 0; proj2D[1] = 0;

        outputInfoPyramid[i].meshData = std::move(currentMeshPyramid.levels[i]);
        // outputInfoPyramid[i].meshDataGT = currentMeshPyramid.levels[i];
        // outputInfoPyramid[i].meshDataColorDiff = currentMeshPyramid.levels[i];
        outputInfoPyramid[i].nRenderLevel = i;
        outputInfoPyramid[i].meshProj.resize(numVertices, proj2D);
        // outputInfoPyramid[i].meshProjGT = outputInfoPyramid[i].meshProj;
        outputInfoPyramid[i].visibilityMask.resize(numVertices, true);
        memset(outputInfoPyramid[i].camPose, 0, 6*sizeof(double));

        UpdateRenderingData(outputInfoPyramid[i], KK, camPose, outputInfoPyramid[i].meshData);

        //////////////////////////// outputPropPyramid

        if(meshLoadingSettings.loadProp)
        {
            outputPropPyramid[i].meshData = std::move(propMeshPyramid.levels[i]);
            // outputPropPyramid[i].meshDataGT = propMeshPyramid.levels[i];
            // outputPropPyramid[i].meshDataColorDiff = propMeshPyramid.levels[i];
            outputPropPyramid[i].nRenderLevel = i;
            outputPropPyramid[i].meshProj.resize(numVertices, proj2D);
            // outputPropPyramid[i].meshProjGT = outputPropPyramid[i].meshProj;
            outputPropPyramid[i].visibilityMask.resize(numVertices, true);
            memset(outputPropPyramid[i].camPose, 0, 6*sizeof(double));

            UpdateRenderingData(outputPropPyramid[i], KK, camPose, outputPropPyramid[i].meshData);
        }

        // update the visibility of each vertex
        if(useVisibilityMask)
        {
            TICK( "visibilityMask" + std::to_string(i) );

            UpdateVisibilityMaskGL(outputInfoPyramid[i], visibilityMaskPyramid[i], KK, camPose, m_nWidth, m_nHeight);
            if(meshLoadingSettings.loadProp)
            UpdateVisibilityMaskGL(outputPropPyramid[i], visibilityMaskPyramid[i], KK, camPose, m_nWidth, m_nHeight);

            TOCK( "visibilityMask" + std::to_string(i) );
            
        }
    }

    TOCK("setupMeshBufferRendering");
    
}
Пример #2
0
bool MainEngine::ProcessOneFrame(int nFrame)
{
    // read input
    // if(!GetInput(nFrame))
    // return false;
    

    // if(inputThreadGroup.size() > 0){
    //     inputThreadGroup.join_all();
    //     memcpy(m_pColorImageRGB, m_pColorImageRGBBuffer, m_nWidth * m_nHeight * 3);
    //     inputThreadGroup.remove_thread(pInputThread);
    //     pInputThread = inputThreadGroup.create_thread( boost::bind(&MainEngine::GetInput, this, nFrame) );
    // }
    // // for the first frame, we have to wait
    // else{
    //     pInputThread = inputThreadGroup.create_thread( boost::bind(&MainEngine::GetInput, this, nFrame) );
    //     inputThreadGroup.join_all();
    //     memcpy(m_pColorImageRGB, m_pColorImageRGBBuffer, m_nWidth * m_nHeight * 3);
    // }

    TICK("timePerFrame");

    TICK("getInput");
    if(pInputThread == NULL)
    {
        pInputThread = new boost::thread(boost::bind(&MainEngine::GetInput, this, nFrame));
        pInputThread->join();
        memcpy(m_pColorImageRGB, m_pColorImageRGBBuffer, m_nWidth * m_nHeight * 3);
    }
    else
    {
        pInputThread->join();
        memcpy(m_pColorImageRGB, m_pColorImageRGBBuffer, m_nWidth * m_nHeight * 3);
        delete pInputThread;
        pInputThread = new boost::thread(boost::bind(&MainEngine::GetInput, this, nFrame));
    }
    TOCK("getInput");

    if(!inputFlag)
    {
        cout << "getting input failure" << endl;
        return false;
    }
    
    // do tracking
    TICK("tracking");
    if(!m_pTrackingEngine->trackFrame(nFrame, m_pColorImageRGB, &pOutputInfo))
    {
        cout << "tracking failed: " << endl;
        return false;
    }
    TOCK("tracking");

    TOCK("timePerFrame");

    return true;
}
Пример #3
0
inline static int pfile_write_unlocked(int fd, lsn_t off, const byte *dat,
                                       lsn_t len) {
  int error = 0;
  ssize_t bytes_written = 0;
  TICK(write_hist);
  while (bytes_written < len) {

    ssize_t count = pwrite(fd,
                           dat + bytes_written,
                           len - bytes_written,
                           off + bytes_written);

    if (count == -1) {
      if (errno == EAGAIN || errno == EINTR) {
        // @see file.c for an explanation; basically; we ignore these,
        // and try again.
        count = 0;
      } else {
        if (errno == EBADF) {
          error = EBADF;
        } else {
          error = errno;
        }
        break;
      }
    }
    bytes_written += count;
    if (bytes_written != len) {
      DEBUG("pwrite spinning\n");
    }
  }
  TOCK(write_hist);
  return error;
}
MeshPyramidReader::MeshPyramidReader(MeshLoadingSettings& settings, int width,
    int height, double K[3][3], int startFrame, int numTrackingFrames): trackerInitialized(false)
{
    m_nWidth = width;
    m_nHeight = height;
    startFrameNo = startFrame;
    currentFrameNo = startFrame;

    pCurrentColorImageRGB = new unsigned char[3*width*height];
    // in this case camPose will always be zero
    for(int i = 0; i < 6; ++i)
    camPose[i] = 0;

    useVisibilityMask = settings.visibilityMask;

    setIntrinsicMatrix(K);

    TICK("loadingMesh");
    
    currentMeshPyramid = std::move(PangaeaMeshPyramid(settings.meshPath,
            settings.meshLevelFormat, currentFrameNo, settings.meshLevelList));
    if(settings.loadProp)
    {
        propMeshPyramid = std::move(PangaeaMeshPyramid(settings.meshPath,
            settings.propLevelFormat, currentFrameNo, settings.meshLevelList));
    }

    TOCK("loadingMesh");

    m_nNumMeshLevels = settings.meshLevelList.size();

}
Пример #5
0
static long unimplementedos(long d0)
{
    long retval;

    switch(d0)
    {
        case 0x77: /* CountADBs */
        case 0x78: /* GetIndADB */
        case 0x79: /* GetADBInfo */
        case 0x7A: /* SetADBInfo */
        case 0x7B: /* ADBReInit */
        case 0x7C: /* ADBOp */
        case 0x3D: /* DrvrInstall */
        case 0x3E: /* DrvrRemove */
        case 0x4F: /* RDrvrInstall */
            retval = 1;
            break;
        case 0x8B: /* Communications Toolbox */
            retval = ROMlib_creator == TICK("KR09"); /* kermit */
            break;
        default:
            retval = 0;
            break;
    }
    return retval;
}
Пример #6
0
static void
wheel_handler (game_time t, void *client_data)
{
  int  wheel_crash;

  wheel_crash = (wheel_x<car_x && wheel_y==LINES-5 && ground2[wheel_x]==' ');
  if (wheel_x < car_x)  mvwaddch (moon, wheel_y, wheel_x, ' ');
  wheel_x -= 1;
  switch (car_x - wheel_x) {
  case 1:
  case 5:
  case 7:
  case 8:
  case 9:
    wheel_y = LINES - 6;
    break;
  case 2:
  case 3:
  case 4:
    wheel_y = LINES - 7;
    break;
  default:
    wheel_y = LINES - 5;
    break;
  }
  if (wheel_x >= 0 && ! wheel_crash) {
    mvwaddch (moon, wheel_y, wheel_x, 'o');
    add_event (t+TICK(2.3), wheel_handler, NULL);
  } else {
    crash_detected = 1000;
  }
  wnoutrefresh (moon);
}
Пример #7
0
void run_benchmarks(void) {
  int asizes[] = {2, 5, 10, 30, 500};
  int i, j;
  yatrie_t trie = (yatrie_t)NULL;
  int set_time = 0; int get_time = 0;

  BENCHMARK_INIT();

  for (i = 0; i < 5; i++) {
    int array_size = asizes[i];
    
    /* Contiguous keys */
    TICK();
    for (j = 0; j < array_size; j++)
      trie = yatrie_insert(trie, j, j);
    TOCK();
    set_time += benchmark_total_time * 500 / array_size;

    TICK();
    for (j = 0; j < array_size; j++)
      yatrie_get(trie, j);
    TOCK();
    get_time += benchmark_total_time * 500 / array_size;
    yatrie_free(trie); trie = (yatrie_t)NULL;

    /* Uniform keys */
    srand(1234567);
    TICK();
    for (j = 0; j < array_size; j++)
      trie = yatrie_insert(trie, rand(), j);
    TOCK();
    set_time += benchmark_total_time * 500 / array_size;

    TICK();
    for (j = 0; j < array_size; j++)
      yatrie_get(trie, rand());
    TOCK();
    get_time += benchmark_total_time * 500 / array_size;
    yatrie_free(trie); trie = (yatrie_t)NULL;
  }
  
  printf("%i %i\n", get_time, set_time);
}
Пример #8
0
PUBLIC void
PutScrapX (LONGINT type, LONGINT length, char *p, int scrap_count)
{
  static int old_count = -1;

  if (OpenClipboard (cygwin_sdlwindow ()) &&
      (scrap_count == old_count || EmptyClipboard ()))
    {
      UINT format;
      int new_length;
      HANDLE data;

      new_length = calc_length_and_format (&format, type, length, p);
      data = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE, new_length);
      if (type == TICK ("PICT"))
	{
	  if (clip_data)
	    LocalFree (clip_data);
	  clip_data = LocalAlloc (LMEM_FIXED, new_length);
	}
      if (data)
	{
	  char *destp;

	  destp = GlobalLock (data);
	  fill_in_data (destp, type, length, p);
	  GlobalUnlock (data);
	  SetClipboardData (format, data);
	  if (type == TICK ("PICT"))
	    {
	      fill_in_data ((char *) clip_data, type, length, p);
	      SetClipboardData (CF_DIB, NULL); /* we can create a DIB if
						    asked to do so */
	    }
	  CloseClipboard ();
	  old_count = scrap_count;
	}
    }
}
Пример #9
0
static int pfile_read(stasis_handle_t *h, lsn_t off, byte *buf, lsn_t len) {
  pfile_impl *impl = (pfile_impl*)(h->impl);
  int error = 0;

  if (off < 0) {
    error = EDOM;
  } else {
    ssize_t bytes_read = 0;
    TICK(read_hist);
    while (bytes_read < len) {
      ssize_t count = pread(impl->fd,
                            buf + bytes_read,
                            len - bytes_read,
                            off + bytes_read);
      if (count == -1) {
        if (errno == EAGAIN || errno == EINTR) {
          count = 0;
        } else {
          if (errno == EBADF) {
            h->error = EBADF;
          } else {
            int err = errno;
            // The other errors either involve memory bugs (EFAULT), logic bugs
            // (EISDIR, EFIFO, EOVERFLOW), or bad hardware (EIO), so print
            // something to console, and uncleanly crash.
            perror("pfile_read encountered an unknown error code.");
            fprintf(stderr, "pread() returned -1; errno is %d\n",err);
            abort();
          }
          error = errno;
          break;
        }
      } else if(count == 0) {
        // EOF
        if(bytes_read != 0) {
          fprintf(stderr, "short read at end of storefile.  Assuming that this is due to strange recovery scenario, and continuing.\n");
        }
        error = EDOM;
        break;
      } else {
        bytes_read += count;
        if (bytes_read != len) {
          DEBUG("pread spinning\n");
        }
      }
    }
    TOCK(read_hist);
    assert(error || bytes_read == len);
  }
  return error;
}
void MeshSequenceReader::trackerUpdate(TrackerOutputInfo& outputInfo)
{
    TICK("visualRenderingUpdate");

    UpdateRenderingData(outputInfo, KK, camPose, currentMesh);
    UpdateRenderingDataFast(outputInfo, KK, currentMesh);

    if(useVisibilityMask)
    {
        UpdateVisibilityMaskGL(outputInfo, visibilityMask, KK, camPose, m_nWidth, m_nHeight);
        //UpdateVisibilityMask(outputInfo, visibilityMask, m_nWidth, m_nHeight);
        UpdateColorDiff(outputInfo, visibilityMask, colorImageSplit);
    }

    TOCK("visualRenderingUpdate");
}
Пример #11
0
void
fire_laser (double t)
{
  struct beam *b;

  if (! beam_table.data)  DA_INIT (beam_table, struct beam *);
  b = xmalloc (sizeof (struct beam));
  b->state = bs_START;
  b->count = 40;
  b->left = car_x-8;
  b->right = car_x;
  b->y = car_y;
  DA_ADD (beam_table, struct beam *, b);
  add_event (t+TICK(0.25), beam_handler, b);
  adjust_score (-1);
}
Пример #12
0
void ExtendedTrack::fill(Dict *d) const{
    Track::fill(d);
    d->SetValueAndShowSection("NOTES", notes, "HAS_NOTES");
    d->SetValueAndShowSection("LICENSE", license, "HAS_LICENSE");
    d->ShowSection(airable ? "IS_AIRABLE" : "NOT_AIRABLE");
    // Tags
    if(!tags.empty()){
        d->ShowSection("HAS_TAGS");
        for(std::vector<std::string>::const_iterator i=tags.begin(); i!=tags.end(); i++)
            d->SetValueAndShowSection("TAG", *i, "TAG");
    }
    // License
    d->SetValue("LICENSE", license);
    d->ShowSection(license == "Copyright" ? "COPYRIGHT" : "OTHER_LICENSE");
    TICK("CC BY", "CC_BY");
    else TICK("CC BY-NC", "CC_BY_NC");
Пример #13
0
PUBLIC Ptr
ROMlib_kchr_ptr (void)
{
  if (!kchr_ptr)
    {
      ZONE_SAVE_EXCURSION
	(SysZone,
	 {
	   Handle kchr_hand;

	   kchr_hand = GetResource (TICK ("KCHR"), kchr_id);
	   gui_assert (kchr_hand);
	   LoadResource (kchr_hand);
	   HLock (kchr_hand);
	   kchr_ptr = STARH (kchr_hand);
	 });
bool MeshSequenceReader::setCurrentFrame(int curFrame)
{
    if(currentFrameNo != curFrame)
    {
        currentFrameNo = curFrame;

        // changing new frame time
        TICK("setCurrentFrame");

        if(!loadMesh(meshLoadingSettings.meshPath,
                meshLoadingSettings.meshFormat,currentFrameNo))
        return false;

        TOCK("setCurrentFrame");
    }
    return true;
}
Пример #15
0
int main(int argc, char *argv[])
{
  float *u = new float[N];
  float *v = new float[N];
  float alpha = 2.3;
  double time4=0;

  initializeVectors(u,v);

  TICK();
  axpyGPU(u,v,alpha,N);
  TOCK(time4);

  outputStats(time4);  

  delete [] u; 
  delete [] v;
}
bool MeshPyramidReader::setCurrentFrame(int curFrame)
{
    if(currentFrameNo != curFrame)
    {
        currentFrameNo = curFrame;

        TICK("setCurrentFrame");
        
        if(!loadMeshPyramid(meshLoadingSettings.meshPath,
                meshLoadingSettings.meshLevelFormat, currentFrameNo,
                meshLoadingSettings.meshLevelList))
        return false;

        TOCK("setCurrentFrame");
        
    }
    return true;
   
}
Пример #17
0
static int pfile_force_range(stasis_handle_t *h, lsn_t start, lsn_t stop) {
  TICK(force_range_hist);
  pfile_impl * impl = h->impl;
#ifdef HAVE_SYNC_FILE_RANGE
  // stop of zero syncs to eof.
  DEBUG("pfile_force_range calling sync_file_range %lld %lld\n",
	 start, stop-start); fflush(stdout);
  int ret = sync_file_range(impl->fd, start, stop-start,
			      SYNC_FILE_RANGE_WAIT_BEFORE |
			      SYNC_FILE_RANGE_WRITE |
			      SYNC_FILE_RANGE_WAIT_AFTER);
  if(ret) {
    int error = errno;
    assert(ret == -1);
    // With the possible exceptions of ENOMEM and ENOSPACE, all of the sync
    // errors are unrecoverable.
    h->error = EBADF;
    ret = error;
  }
#else
#ifdef HAVE_FDATASYNC
  DEBUG("pfile_force_range() is calling fdatasync()\n");
  fdatasync(impl->fd);
#else
  DEBUG("pfile_force_range() is calling fsync()\n");
  fsync(impl->fd);
#endif
  int ret = 0;
#endif
#ifdef HAVE_POSIX_FADVISE
  if(impl->sequential) {
    int err = posix_fadvise(impl->fd, start, stop-start, POSIX_FADV_DONTNEED);
    if(err) perror("Attempt to pass POSIX_FADV_SEQUENTIAL (for a range of a file) to kernel failed");
  }
#endif
  TOCK(force_range_hist);
  return ret;
}
Пример #18
0
static int pfile_force(stasis_handle_t *h) {
  TICK(force_hist);
  pfile_impl *impl = h->impl;
  if(!(impl->file_flags & O_SYNC)) {
#ifdef HAVE_FDATASYNC
    DEBUG("pfile_force() is calling fdatasync()\n");
    fdatasync(impl->fd);
#else
    DEBUG("pfile_force() is calling fsync()\n");
    fsync(impl->fd);
#endif
  } else {
    DEBUG("File was opened with O_SYNC.  pfile_force() is a no-op\n");
  }
  if(impl->sequential) {
#ifdef HAVE_POSIX_FADVISE
    int err = posix_fadvise(impl->fd, 0, 0, POSIX_FADV_DONTNEED);
    if(err) perror("Attempt to pass POSIX_FADV_SEQUENTIAL to kernel failed");
#endif
  }
  TOCK(force_hist);
  return 0;
}
Пример #19
0
bool MainFrame::ProcessOneFrame(int nFrame)
{
    // if(trackingType != DEFORMNRSFM && m_pControlPanel->m_nCurrentFrame == nFrame && m_nCurrentFrame == nFrame)
    // return true;
    isTrackingFinished =  false;
    cout << "processing frame: " << nFrame << endl;

    // // read input
    // TICK("getInput");
    // if(!GetInput(nFrame))
    // return false;
    // TOCK("getInput");

    // // do tracking
    // TICK("tracking");
    // if(!m_pTrackingEngine->trackFrame(nFrame, m_pColorImageRGB, &pOutputInfo))
    // {
    //     cout << "tracking failed: " << endl;
    //     return false;
    // }
    // TOCK("tracking");
    if(!MainEngine::ProcessOneFrame(nFrame))
    return false;

    // update imagePanel
    TICK("update2DRendering");
    m_pOverlayPane->updateImage(m_pColorImageRGB, m_nWidth, m_nHeight);
    m_pImagePane->updateImage(m_pColorImageRGB, m_nWidth, m_nHeight);
    TOCK("update2DRendering");

    isTrackingFinished =  true;

    Stopwatch::getInstance().printAll();

    return true;
}
Пример #20
0
/**
 * Main game loop.
 */
static void loop(void)
{
    extern nyancat_t nc;
    gametime_t time;
    int key_ready = 0, ch;

    /* switch to intro mode */
    gamemode_enter(mode_intro);
    gamemode_draw();

    while (gamemode_valid()) {
        /* look for the first to run event */
        time = queue_get_first_time();
        if (time) {
            /* wait for time to run the first event form queue or the first
             * keypress, wichever comes first. */
            key_ready = io_wait_for_key(time);
        } else {
            /* no event queue item found */
            io_wait_for_key(0);
            key_ready = 1;
        }
        if (key_ready > 0) {
            ch = getch();
            /* no redraw call explicite because this should be done bey the
             * key handlers called functions */
            gamemode_key(ch);
        } else {
            /* TODO find a better way for prevening hight cpu usage here. But
             * for now insert a sleep for the minimum ticks used in game */
            usleep(SECOND * TICK(0.1));
            queue_run_until(time);
        }
        doupdate();
    }
}
Пример #21
0
bool inline TrackerInterface::process()
{
    if(firstRun)
    {
        cudaSafeCall(cudaSetDevice(ConfigArgs::get().gpu));
        firstRun = false;
    }

    if(!threadPack.pauseCapture.getValue())
    {
        TICK(threadIdentifier);

        uint64_t start = Stopwatch::getCurrentSystemTime();

        bool returnVal = true;

        bool shouldEnd = endRequested.getValue();

        if(!logRead->grabNext(returnVal, currentFrame) || shouldEnd)
        {
            threadPack.pauseCapture.assignValue(true);
            threadPack.finalised.assignValue(true);

            finalise();

            while(!threadPack.cloudSliceProcessorFinished.getValueWait())
            {
                frontend->cloudSignal.notify_all();
            }

            return shouldEnd ? false : returnVal;
        }

        depth.data = (unsigned short *)logRead->decompressedDepth;
        rgb24.data = (PixelRGB *)logRead->decompressedImage;
        
        currentFrame++;

        depth.step = Resolution::get().width() * 2;
        depth.rows = Resolution::get().rows();
        depth.cols = Resolution::get().cols();

        rgb24.step = Resolution::get().width() * 3;
        rgb24.rows = Resolution::get().rows();
        rgb24.cols = Resolution::get().cols();

        depth_device.upload(depth.data, depth.step, depth.rows, depth.cols);
        colors_device.upload(rgb24.data, rgb24.step, rgb24.rows, rgb24.cols);

        TICK("processFrame");
        frontend->processFrame(depth_device,
                               colors_device,
                               logRead->decompressedImage,
                               logRead->decompressedDepth,
                               logRead->timestamp,
                               logRead->isCompressed,
                               logRead->compressedDepth,
                               logRead->compressedDepthSize,
                               logRead->compressedImage,
                               logRead->compressedImageSize);
        TOCK("processFrame");

        uint64_t duration = Stopwatch::getCurrentSystemTime() - start;

        if(threadPack.limit.getValue() && duration < 33333)
        {
            int sleepTime = std::max(int(33333 - duration), 0);
            usleep(sleepTime);
        }

        TOCK(threadIdentifier);
    }
    
    return true;
}
void MeshSequenceReader::trackerInitSetup(TrackerOutputInfo& outputInfo)
{
    TICK("visualRenderingInit");

    outputInfo.meshData = currentMesh;
    outputInfo.meshDataGT = outputInfo.meshData;

    // get 2d projections
    double X,Y,Z;
    double u,v,w;
    vector<CoordinateType> proj2D, proj2DGT;
    proj2D.resize(2); proj2DGT.resize(2);
    for(int vertex = 0; vertex < currentMesh.numVertices; ++vertex)
    {

        X = currentMesh.vertices[vertex][0];
        Y = currentMesh.vertices[vertex][1];
        Z = currentMesh.vertices[vertex][2];

        if(KK[0][2] == 0) // this is orthographic camera
        {
           proj2D[0] = X; proj2D[1] = Y;
           proj2DGT[0] = X; proj2DGT[1] = Y;
        }
        else
        {
            u = KK[0][0] * X + KK[0][1] * Y + KK[0][2] * Z;
            v = KK[1][0] * X + KK[1][1] * Y + KK[1][2] * Z;
            w = KK[2][0] * X + KK[2][1] * Y + KK[2][2] * Z;

            if(w != 0)
            {
                u = u/w;
                v = v/w;
            }

            proj2D[0] = u; proj2D[1] = v;
            proj2DGT[0] = u; proj2DGT[1] = v;

        }

        outputInfo.meshProj.push_back(proj2D);
        outputInfo.meshProjGT.push_back(proj2DGT);

    }

    outputInfo.visibilityMask.resize(outputInfo.meshData.numVertices,true);
    // update the visiblity mask
    if(useVisibilityMask)
    {
        UpdateVisibilityMaskGL(outputInfo, visibilityMask, KK, camPose, m_nWidth, m_nHeight);
        //UpdateVisibilityMask(outputInfo, visibilityMask, m_nWidth, m_nHeight);
        outputInfo.meshDataColorDiff = outputInfo.meshData;
        UpdateColorDiff(outputInfo, visibilityMask, colorImageSplit);
    }

    // camera pose is always 0 in this case
    for(int i = 0; i < 6; ++i)
    outputInfo.camPose[i] = 0;

    trackerInitialized = true;

    TOCK("visualRenderingInit");

}
Пример #23
0
 * the queue was free'd by gamemode switching. */
typedef struct {
    gametime_t time;
    eventhandler_fn callback;
} event_backup;

static event_backup eventbackup_specialmode;
static event_backup eventbackup_gem;
static event_backup eventbackup_milk;

extern coordinate_t screen;

static cat_t cat;

static movement_t move_fall[] = {
    {TICK(3.5), 1, CatStateGlideDown, &move_fall[1]},
    {TICK(2.5), 1, CatStateGlideDown, &move_fall[2]},
    {TICK(2.5), 1, CatStateFall,      &move_fall[3]},
    {TICK(2.5), 1, CatStateFall,      &move_fall[4]},
    {TICK(2.5), 1, CatStateFall,      &move_fall[5]},
    {TICK(2.1), 1, CatStateFall,      &move_fall[6]},
    {TICK(2.1), 1, CatStateFall,      &move_fall[7]},
    {TICK(2.1), 1, CatStateFall,      &move_fall[8]},
    {TICK(1),   1, CatStateFallFast,  &move_fall[8]}
};
static movement_t move_walk[] = {
    {TICK(1),    0, CatStateWalk, &move_walk[1]},
    {TICK(1),    0, CatStateGlide, move_fall}
};
static movement_t move_jump[] = {
    {TICK(2.5), -1, CatStateJumpUp, &move_jump[1]},
Пример #24
0
/*!
  Routine to compute an approximate solution to Ax = b

  @param[in]    geom The description of the problem's geometry.
  @param[inout] A    The known system matrix
  @param[inout] data The data structure with all necessary CG vectors preallocated
  @param[in]    b    The known right hand side vector
  @param[inout] x    On entry: the initial guess; on exit: the new approximate solution
  @param[in]    max_iter  The maximum number of iterations to perform, even if tolerance is not met.
  @param[in]    tolerance The stopping criterion to assert convergence: if norm of residual is <= to tolerance.
  @param[out]   niters    The number of iterations actually performed.
  @param[out]   normr     The 2-norm of the residual vector after the last iteration.
  @param[out]   normr0    The 2-norm of the residual vector before the first iteration.
  @param[out]   times     The 7-element vector of the timing information accumulated during all of the iterations.
  @param[in]    doPreconditioning The flag to indicate whether the preconditioner should be invoked at each iteration.

  @return Returns zero on success and a non-zero value otherwise.

  @see CG_ref()
*/
int CG(const SparseMatrix & A, CGData & data, const Vector & b, Vector & x,
    const int max_iter, const double tolerance, int & niters, double & normr, double & normr0,
    double * times, bool doPreconditioning) {

  double t_begin = mytimer();  // Start timing right away
  normr = 0.0;
  double rtz = 0.0, oldrtz = 0.0, alpha = 0.0, beta = 0.0, pAp = 0.0;


  double t0 = 0.0, t1 = 0.0, t2 = 0.0, t3 = 0.0, t4 = 0.0, t5 = 0.0;
//#ifndef HPCG_NOMPI
//  double t6 = 0.0;
//#endif
  local_int_t nrow = A.localNumberOfRows;
  Vector & r = data.r; // Residual vector
  Vector & z = data.z; // Preconditioned residual vector
  Vector & p = data.p; // Direction vector (in MPI mode ncol>=nrow)
  Vector & Ap = data.Ap;

  if (!doPreconditioning && A.geom->rank==0) HPCG_fout << "WARNING: PERFORMING UNPRECONDITIONED ITERATIONS" << std::endl;

#ifdef HPCG_DEBUG
  int print_freq = 1;
  if (print_freq>50) print_freq=50;
  if (print_freq<1)  print_freq=1;
#endif
  // p is of length ncols, copy x to p for sparse MV operation
  CopyVector(x, p);     //TODO paralel
  TICK(); ComputeSPMV(A, p, Ap); TOCK(t3); // Ap = A*p
  TICK(); ComputeWAXPBY(nrow, 1.0, b, -1.0, Ap, r, A.isWaxpbyOptimized);  TOCK(t2); // r = b - Ax (x stored in p)
  TICK(); ComputeDotProduct(nrow, r, r, normr, t4, A.isDotProductOptimized); TOCK(t1);
  normr = sqrt(normr);
#ifdef HPCG_DEBUG
  if (A.geom->rank==0) HPCG_fout << "Initial Residual = "<< normr << std::endl;
#endif

  // Record initial residual for convergence testing
  normr0 = normr;

  // Start iterations

  for (int k=1; k<=max_iter && normr/normr0 > tolerance; k++ ) {
    TICK();
    if (doPreconditioning)
      ComputeMG(A, r, z); // Apply preconditioner
    else
      CopyVector (r, z); // copy r to z (no preconditioning)
    TOCK(t5); // Preconditioner apply time

    if (k == 1) {
      TICK(); ComputeWAXPBY(nrow, 1.0, z, 0.0, z, p, A.isWaxpbyOptimized); TOCK(t2); // Copy Mr to p
      TICK(); ComputeDotProduct (nrow, r, z, rtz, t4, A.isDotProductOptimized); TOCK(t1); // rtz = r'*z
    } else {
      oldrtz = rtz;
      TICK(); ComputeDotProduct (nrow, r, z, rtz, t4, A.isDotProductOptimized); TOCK(t1); // rtz = r'*z
      beta = rtz/oldrtz;
      TICK(); ComputeWAXPBY (nrow, 1.0, z, beta, p, p, A.isWaxpbyOptimized);  TOCK(t2); // p = beta*p + z
    }

    TICK(); ComputeSPMV(A, p, Ap); TOCK(t3); // Ap = A*p
    TICK(); ComputeDotProduct(nrow, p, Ap, pAp, t4, A.isDotProductOptimized); TOCK(t1); // alpha = p'*Ap
    alpha = rtz/pAp;
    TICK(); ComputeWAXPBY(nrow, 1.0, x, alpha, p, x, A.isWaxpbyOptimized);// x = x + alpha*p
    ComputeWAXPBY(nrow, 1.0, r, -alpha, Ap, r, A.isWaxpbyOptimized);  TOCK(t2);// r = r - alpha*Ap
    TICK(); ComputeDotProduct(nrow, r, r, normr, t4, A.isDotProductOptimized); TOCK(t1);
    normr = sqrt(normr);
#ifdef HPCG_DEBUG
    if (A.geom->rank==0 && (k%print_freq == 0 || k == max_iter))
      HPCG_fout << "Iteration = "<< k << "   Scaled Residual = "<< normr/normr0 << std::endl;
#endif
    niters = k;
  }

  // Store times
  times[1] += t1; // dot-product time
  times[2] += t2; // WAXPBY time
  times[3] += t3; // SPMV time
  times[4] += t4; // AllReduce time
  times[5] += t5; // preconditioner apply time
//#ifndef HPCG_NOMPI
//  times[6] += t6; // exchange halo time
//#endif
  times[0] += mytimer() - t_begin;  // Total time. All done...
  return(0);
}
Пример #25
0
static MRESULT APIENTRY Button1Up ( HWND Window, MESG, MPARAM1 mp1, MPARAM2 ) {

 /***************************************************************************
  * Find the instance data.                                                 *
  ***************************************************************************/

  PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ;

 /***************************************************************************
  * If the mouse wasn't captured, return.                                   *
  ***************************************************************************/

  if ( NOT Data->Capture )
    return ( MRFROMSHORT ( FALSE ) ) ;

 /***************************************************************************
  * Get the presentation space.                                             *
  ***************************************************************************/

  WorkSpace PS ( "HRuler::Button1Up", 0, Window, Data->pDevice, int(Data->Metric) ) ;
  PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ;

 /***************************************************************************
  * Find out where the mouse touched.                                       *
  ***************************************************************************/

  RECTL Rectangle ;
  WinQueryWindowRect ( Window, &Rectangle ) ;

  POINTL Mouse = { SHORT1FROMMP(mp1), SHORT2FROMMP(mp1) } ;
  PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, 1, &Mouse ) ;

  PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, Rectangle ) ;

  POINTL ButtonSize = { 8, 8 } ;
  PS.Transform ( CVTC_DEVICE, CVTC_PAGE, 1, &ButtonSize ) ;

  #ifdef DEBUG
     Log ( "HRuler::Button1Up:   Mouse at %i,%i (%i,%i).  Rectangle %i,%i-%i,%i.  ButtonSize %i.%i (8x8).",
        Mouse.x, Mouse.y, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), 
        Rectangle.xLeft, Rectangle.yBottom, Rectangle.xRight, Rectangle.yTop,
        ButtonSize.x, ButtonSize.y ) ;
  #endif

 /***************************************************************************
  * Erase the previous hairline.                                            *
  ***************************************************************************/

  PS.SetMix ( FM_INVERT ) ;
  PS.SetLineType ( LINETYPE_ALTERNATE ) ;
  POINTL Point = { Data->Tick, Rectangle.yBottom } ;
  PS.Move ( Point ) ;
  Point.y = Rectangle.yTop ;
  PS.DrawLine ( Point ) ;

 /***************************************************************************
  * Release the mouse.                                                      *
  ***************************************************************************/

  Data->Capture = FALSE ;
  Sys_ReleaseCapture ( ) ;

 /***************************************************************************
  * Restore the normal mouse pointer.                                       *
  ***************************************************************************/

  HPOINTER Ptr = WinQuerySysPointer ( HWND_DESKTOP, SPTR_ARROW, FALSE ) ;
  WinSetPointer ( HWND_DESKTOP, Ptr ) ;

 /***************************************************************************
  * Restore the keyboard focus.                                             *
  ***************************************************************************/

  Sys_SetFocus ( Data->HadFocus ) ;

 /***************************************************************************
  * Process final location of mouse.                                        *
  ***************************************************************************/

  switch ( Data->Mode ) {

    case MOVELEFT:
    {
      Data->Tick = TICK(Mouse.x) ;
      if ( ( Data->Tick < 0 ) OR ( Data->Tick >= Data->RightMargin ) )
      {
        Sys_BeepError ( ) ;
        break ;
      }
      Sys_SendMessage ( OWNER(Window), WM_SET_LEFTMARGIN, MPFROMLONG(Data->Tick), 0 ) ;
      break ;
    }

    case MOVERIGHT:
    {
      Data->Tick = TICK(Mouse.x) ;
      if ( ( Data->Tick <= Data->LeftMargin ) OR ( Data->Tick > Data->PageWidth ) )
      {
        Sys_BeepError ( ) ;
        break ;
      }
      Sys_SendMessage ( OWNER(Window), WM_SET_RIGHTMARGIN, MPFROMLONG(Data->Tick), 0 ) ;
      break ;
    }

    case MOVETAB:
    {
      Data->Tick = TICK(Mouse.x) ;
      if ( ( Mouse.y > Rectangle.yTop )
        OR ( Mouse.y < Rectangle.yBottom )
        OR ( Data->Tick <= Data->LeftMargin )
        OR ( Data->Tick >= Data->RightMargin ) )
      {
        Sys_SendMessage ( OWNER(Window), WM_CLEAR_TAB, MPFROMLONG(Data->Tabs[Data->TabIndex]), 0 ) ;
        break ;
      }

      Sys_SendMessage ( OWNER(Window), WM_MOVE_TAB, MPFROMLONG(Data->Tabs[Data->TabIndex]), MPFROMLONG(Data->Tick) ) ;
      break ;
    }

    case SETTAB:
    {
      Data->Tick = TICK(Mouse.x) ;
      if ( ( Mouse.y > Rectangle.yTop )
        OR ( Mouse.y < Rectangle.yBottom )
        OR ( Data->Tick <= Data->LeftMargin )
        OR ( Data->Tick >= Data->RightMargin ) )
      {
        Sys_BeepError ( ) ;
        break ;
      }

      Sys_SendMessage ( OWNER(Window), WM_SET_TAB, MPFROMLONG(Data->Tick), 0 ) ;
      break ;
    }
  }

 /***************************************************************************
  * Reset mode.                                                             *
  ***************************************************************************/

  Data->Mode = NOTMOVING ;

 /***************************************************************************
  * We're done.                                                             *
  ***************************************************************************/

  return ( MRFROMSHORT ( TRUE ) ) ;
}
MeshBufferReader::MeshBufferReader(MeshLoadingSettings& settings, int width,
                                   int height, double K[3][3], int startFrame, int numTrackingFrames): trackerInitialized(false)
{
  m_nWidth = width;
  m_nHeight = height;
  startFrameNo = startFrame;
  currentFrameNo = startFrame;

  pCurrentColorImageRGB = new unsigned char[3*width*height];
  // in this case camPose will always be zero
  for(int i = 0; i < 6; ++i)
    camPose[i] = 0;

  useVisibilityMask = settings.visibilityMask;

  setIntrinsicMatrix(K);

  nRenderingLevel = 0;
  m_nNumMeshLevels = settings.meshLevelList.size();

  // a bit ugly
  nFrameStep = imageSourceSettings.frameStep;

  // loading meshes into buffer
  // outputInfoPyramidBuffer.resize(numTrackingFrames);
  // outputPropPyramidBuffer.resize(numTrackingFrames);
  int bufferSize = (numTrackingFrames - startFrameNo)/nFrameStep + 1;
  outputInfoPyramidBuffer.resize(bufferSize);
  outputPropPyramidBuffer.resize(bufferSize);

  m_nGoodFrames = 0;

  TICK("loadingMeshBuffer");

  for(int i = startFrameNo; i <= numTrackingFrames; i = i + nFrameStep)
    {

      // TICK("loadingOneFrame");

      if(!existenceTest(settings.meshPath, settings.meshLevelFormat,
                        i, settings.meshLevelList))
        break;

      ++m_nGoodFrames;
      currentMeshPyramid = std::move(PangaeaMeshPyramid(settings.meshPath,
                                                        settings.meshLevelFormat, i, settings.meshLevelList));

      // TOCK("loadingOneFrame");

      if(settings.loadProp)
        {
          propMeshPyramid = std::move(PangaeaMeshPyramid(settings.meshPath,
                                                         settings.propLevelFormat, i, settings.meshLevelList));
        }
      if(!settings.fastLoading)
        propMeshPyramid = currentMeshPyramid;


      // TICK("setOneFrame");

      setMeshPyramid();

      int bufferPos = (i-startFrameNo)/nFrameStep;
      outputInfoPyramidBuffer[ bufferPos ] = std::move(outputInfoPyramid);
      outputPropPyramidBuffer[ bufferPos ] = std::move(outputPropPyramid);

      // TOCK("setOneFrame");

      cout << "loading frame " << i << endl;
    }

  TOCK("loadingMeshBuffer");

}
Пример #27
0
int
test_decode(void *code, int k, int index[], int sz, char *s)
{
    int errors;
    int reconstruct = 0 ;
    int item, i ;

    static int prev_k = 0, prev_sz = 0;
    static u_char **d_original = NULL, **d_src = NULL ;

    if (sz < 1 || sz > 8192) {
	fprintf(stderr, "test_decode: size %d invalid, must be 1..8K\n",
		sz);
	return 1 ;
    }
    if (k < 1 || k > GF_SIZE + 1) {
	fprintf(stderr, "test_decode: k %d invalid, must be 1..%d\n",
		k, GF_SIZE + 1 );
	return 2 ;
    }
    if (prev_k != k || prev_sz != sz) {
	if (d_original != NULL) {
	    for (i = 0 ; i < prev_k ; i++ ) {
		free(d_original[i]);
		free(d_src[i]);
	    }
	    free(d_original);
	    free(d_src);
	    d_original = NULL ;
	    d_src = NULL ;
	}
    }
    prev_k = k ;
    prev_sz = sz ;
    if (d_original == NULL) {
	d_original = my_malloc(k * sizeof(void *), "d_original ptr");
	d_src = my_malloc(k * sizeof(void *), "d_src ptr");

	for (i = 0 ; i < k ; i++ ) {
	    d_original[i] = my_malloc(sz, "d_original data");
	    d_src[i] = my_malloc(sz, "d_src data");
	}
	/*
	 * build sample data
	 */
	for (i = 0 ; i < k ; i++ ) {
	    for (item=0; item < sz; item++)
		d_original[i][item] = ((item ^ i) + 3) & GF_SIZE;
	}
    }

    errors = 0 ;

    for( i = 0 ; i < k ; i++ )
	if (index[i] >= k ) reconstruct ++ ;

    TICK(ticks[2]);
    for( i = 0 ; i < k ; i++ )
	fec_encode(code, d_original, d_src[i], index[i], sz );
    TOCK(ticks[2]);

    TICK(ticks[1]);
    if (fec_decode(code, d_src, index, sz)) {
	fprintf(stderr, "detected singular matrix for %s  \n", s);
	return 1 ;
    }
    TOCK(ticks[1]);

    for (i=0; i<k; i++)
	if (bcmp(d_original[i], d_src[i], sz )) {
	    errors++;
	    fprintf(stderr, "error reconstructing block %d\n", i);
	}
    if (errors)
	fprintf(stderr, "Errors reconstructing %d blocks out of %d\n",
	    errors, k);

    fprintf(stderr,
	"  k %3d, l %3d  c_enc %10.6f MB/s c_dec %10.6f MB/s     \r",
	k, reconstruct,
	(double)(k * sz * reconstruct)/(double)ticks[2],
	(double)(k * sz * reconstruct)/(double)ticks[1]);
    return errors ;
}
Пример #28
0
int main ( int argc, char *argv[] )
{
    TIMINGS_START ();

    cmd_set_arguments ( argc, argv );

    // Version
    if ( find_arg (  "-v" ) >= 0 || find_arg (  "-version" ) >= 0 ) {
#ifdef GIT_VERSION
        fprintf ( stdout, "Version: "GIT_VERSION "\n" );
#else
        fprintf ( stdout, "Version: "VERSION "\n" );
#endif
        exit ( EXIT_SUCCESS );
    }

    // Detect if we are in dmenu mode.
    // This has two possible causes.
    // 1 the user specifies it on the command-line.
    if ( find_arg (  "-dmenu" ) >= 0 ) {
        dmenu_mode = TRUE;
    }
    // 2 the binary that executed is called dmenu (e.g. symlink to rofi)
    else{
        // Get the base name of the executable called.
        char *base_name = g_path_get_basename ( argv[0] );
        const char * const dmenu_str = "dmenu";
        dmenu_mode = ( strcmp ( base_name, dmenu_str ) == 0 );
        // Free the basename for dmenu detection.
        g_free ( base_name );
    }
    TICK ();
    // Get the path to the cache dir.
    cache_dir = g_get_user_cache_dir ();

    // Create pid file path.
    const char *path = g_get_user_runtime_dir ();
    if ( path ) {
        pidfile = g_build_filename ( path, "rofi.pid", NULL );
    }
    config_parser_add_option ( xrm_String, "pid", (void * *) &pidfile, "Pidfile location" );

    if ( find_arg ( "-config" ) < 0 ) {
        const char *cpath = g_get_user_config_dir ();
        if ( cpath ) {
            config_path = g_build_filename ( cpath, "rofi", "config", NULL );
        }
    }
    else {
        char *c = NULL;
        find_arg_str ( "-config", &c );
        config_path = rofi_expand_path ( c );
    }

    TICK ();
    // Register cleanup function.
    atexit ( cleanup );

    TICK ();
    // Get DISPLAY, first env, then argument.
    char *display_str = getenv ( "DISPLAY" );
    find_arg_str (  "-display", &display_str );

    if ( setlocale ( LC_ALL, "" ) == NULL ) {
        fprintf ( stderr, "Failed to set locale.\n" );
        return EXIT_FAILURE;
    }

    xcb->connection = xcb_connect ( display_str, &xcb->screen_nbr );
    if ( xcb_connection_has_error ( xcb->connection ) ) {
        fprintf ( stderr, "Failed to open display: %s", display_str );
        return EXIT_FAILURE;
    }
    TICK_N ( "Open Display" );

    xcb->screen = xcb_aux_get_screen ( xcb->connection, xcb->screen_nbr );

    xcb_intern_atom_cookie_t *ac     = xcb_ewmh_init_atoms ( xcb->connection, &xcb->ewmh );
    xcb_generic_error_t      *errors = NULL;
    xcb_ewmh_init_atoms_replies ( &xcb->ewmh, ac, &errors );
    if ( errors ) {
        fprintf ( stderr, "Failed to create EWMH atoms\n" );
        free ( errors );
    }

    if ( xkb_x11_setup_xkb_extension ( xcb->connection, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION,
                                       XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, NULL, NULL, &xkb.first_event, NULL ) < 0 ) {
        fprintf ( stderr, "cannot setup XKB extension!\n" );
        return EXIT_FAILURE;
    }

    xkb.context = xkb_context_new ( XKB_CONTEXT_NO_FLAGS );
    if ( xkb.context == NULL ) {
        fprintf ( stderr, "cannot create XKB context!\n" );
        return EXIT_FAILURE;
    }
    xkb.xcb_connection = xcb->connection;

    xkb.device_id = xkb_x11_get_core_keyboard_device_id ( xcb->connection );

    enum
    {
        required_events =
            ( XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY |
              XCB_XKB_EVENT_TYPE_MAP_NOTIFY |
              XCB_XKB_EVENT_TYPE_STATE_NOTIFY ),

        required_nkn_details =
            ( XCB_XKB_NKN_DETAIL_KEYCODES ),

        required_map_parts   =
            ( XCB_XKB_MAP_PART_KEY_TYPES |
              XCB_XKB_MAP_PART_KEY_SYMS |
              XCB_XKB_MAP_PART_MODIFIER_MAP |
              XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS |
              XCB_XKB_MAP_PART_KEY_ACTIONS |
              XCB_XKB_MAP_PART_VIRTUAL_MODS |
              XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP ),

        required_state_details =
            ( XCB_XKB_STATE_PART_MODIFIER_BASE |
              XCB_XKB_STATE_PART_MODIFIER_LATCH |
              XCB_XKB_STATE_PART_MODIFIER_LOCK |
              XCB_XKB_STATE_PART_GROUP_BASE |
              XCB_XKB_STATE_PART_GROUP_LATCH |
              XCB_XKB_STATE_PART_GROUP_LOCK ),
    };

    static const xcb_xkb_select_events_details_t details = {
        .affectNewKeyboard  = required_nkn_details,
        .newKeyboardDetails = required_nkn_details,
        .affectState        = required_state_details,
        .stateDetails       = required_state_details,
    };
    xcb_xkb_select_events ( xcb->connection, xkb.device_id, required_events, /* affectWhich */
                            0,                                               /* clear */
                            required_events,                                 /* selectAll */
                            required_map_parts,                              /* affectMap */
                            required_map_parts,                              /* map */
                            &details );

    xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS );
    if ( xkb.keymap == NULL ) {
        fprintf ( stderr, "Failed to get Keymap for current keyboard device.\n" );
        return EXIT_FAILURE;
    }
    xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
    if ( xkb.state == NULL ) {
        fprintf ( stderr, "Failed to get state object for current keyboard device.\n" );
        return EXIT_FAILURE;
    }

    xkb.compose.table = xkb_compose_table_new_from_locale ( xkb.context, setlocale ( LC_CTYPE, NULL ), 0 );
    if ( xkb.compose.table != NULL ) {
        xkb.compose.state = xkb_compose_state_new ( xkb.compose.table, 0 );
    }
    else {
        fprintf ( stderr, "Failed to get keyboard compose table. Trying to limp on.\n" );
    }

    if ( xcb_connection_has_error ( xcb->connection ) ) {
        fprintf ( stderr, "Connection has error\n" );
        exit ( EXIT_FAILURE );
    }
    x11_setup ( &xkb );
    if ( xcb_connection_has_error ( xcb->connection ) ) {
        fprintf ( stderr, "Connection has error\n" );
        exit ( EXIT_FAILURE );
    }

    const xcb_query_extension_reply_t *er = xcb_get_extension_data ( xcb->connection, &xcb_xinerama_id );
    if ( er ) {
        if ( er->present ) {
            xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection );
            xcb_xinerama_is_active_reply_t  *is_active    = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, NULL );
            xcb->has_xinerama = is_active->state;
            free ( is_active );
        }
    }
    main_loop = g_main_loop_new ( NULL, FALSE );

    TICK_N ( "Setup mainloop" );
    // startup not.
    xcb->sndisplay = sn_xcb_display_new ( xcb->connection, error_trap_push, error_trap_pop );
    if ( xcb_connection_has_error ( xcb->connection ) ) {
        fprintf ( stderr, "Connection has error\n" );
        exit ( EXIT_FAILURE );
    }

    if ( xcb->sndisplay != NULL ) {
        xcb->sncontext = sn_launchee_context_new_from_environment ( xcb->sndisplay, xcb->screen_nbr );
    }
    if ( xcb_connection_has_error ( xcb->connection ) ) {
        fprintf ( stderr, "Connection has error\n" );
        exit ( EXIT_FAILURE );
    }
    TICK_N ( "Startup Notification" );

    // Initialize Xresources subsystem.
    config_parse_xresource_init ();
    TICK_N ( "Initialize Xresources system" );
    // Setup keybinding
    setup_abe ();
    TICK_N ( "Setup abe" );

    if ( find_arg ( "-no-config" ) < 0 ) {
        load_configuration ( );
    }
    if ( !dmenu_mode ) {
        // setup_modi
        setup_modi ();
    }

    if ( find_arg ( "-no-config" ) < 0 ) {
        // Reload for dynamic part.
        load_configuration_dynamic ( );
    }
    // Dump.
    // catch help request
    if ( find_arg (  "-h" ) >= 0 || find_arg (  "-help" ) >= 0 || find_arg (  "--help" ) >= 0 ) {
        help ( argc, argv );
        exit ( EXIT_SUCCESS );
    }
    if ( find_arg (  "-dump-xresources" ) >= 0 ) {
        config_parse_xresource_dump ();
        exit ( EXIT_SUCCESS );
    }
    if ( find_arg (  "-dump-xresources-theme" ) >= 0 ) {
        config_parse_xresources_theme_dump ();
        exit ( EXIT_SUCCESS );
    }

    main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb->connection, main_loop_x11_event_handler, NULL, NULL );

    TICK_N ( "X11 Setup " );

    rofi_view_workers_initialize ();

    // Setup signal handling sources.
    // SIGINT
    g_unix_signal_add ( SIGINT, main_loop_signal_handler_int, NULL );

    g_idle_add ( startup, NULL );

    // Start mainloop.
    g_main_loop_run ( main_loop );

    return return_code;
}
Пример #29
0
P2 (PUBLIC pascal trap, OSErr, FSpExchangeFiles,
    FSSpecPtr, src, FSSpecPtr, dst)
{
#if 0
    save_fcb_info_t *src_fcb_info, *dst_fcb_info;
    OSErr retval;

    src_fcb_info = get_fcb_info (src);
    dst_fcb_info = get_fcb_info (dst);

    retval = exchange_forks (src, dst, datafork);
    if (retval == noErr)
    {
        retval = exchange_forks (src, dst, resourcefork);
        if (retval != noErr)
            exchange_forks (src, dst, datafork); /* try to put things back
						together */
    }

    if (retval == noErr)
        exchange_fcbs (src, src_fcb_info, dst, dst_fcb_info);
    else
    {
        restore_fcb (src_fcb_info);
        restore_fcb (dst_fcb_info);
    }

    release_fcb_info (src_fcb_info);
    release_fcb_info (dst_fcb_info);

    return retval;
#else
    OSErr retval;

    warning_unimplemented ("poorly implemented");
    if (src->vRefNum != dst->vRefNum)
        retval = diffVolErr;
    else if (ROMlib_creator != TICK("PAUP") || src->parID != dst->parID)
        retval = wrgVolTypeErr;
    else
    {
        /* Evil hack to get PAUP to work -- doesn't bother adjusting FCBs */
        FSSpec tmp_spec;
        int i;

        i = 0;
        tmp_spec = *dst;
        do
        {
            create_temp_name (tmp_spec.name, i++);
            retval = FSpRename (dst, tmp_spec.name);
        }
        while (retval == dupFNErr);
        if (retval == noErr)
        {
            retval = FSpRename (src, dst->name);
            if (retval != noErr)
                FSpRename (&tmp_spec, dst->name);
            else
            {
                retval = FSpRename (&tmp_spec, src->name);
                if (retval != noErr)
                {
                    FSpRename (dst, src->name);
                    FSpRename (&tmp_spec, dst->name);
                }
            }
        }
    }
    return retval;
#endif
}
Пример #30
-1
A1(PRIVATE, OSErr, cropen, INTEGER *, fp)
{
    OSErr retval;
    
    retval = FSOpen(MR(ScrapName), CW (BootDrive), fp);
    if (retval == fnfErr) {
        retval = Create(MR(ScrapName), CW (BootDrive), TICK("MACS"), TICK("CLIP"));
        if (retval != noErr)
            return(retval);
        return(FSOpen(MR(ScrapName), CW (BootDrive), fp));
    }
    return(retval);
}