void* Init(const char* strFile, unsigned int filecache, int* channels,
           int* samplerate, int* bitspersample, int64_t* totaltime,
           int* bitrate, AEDataFormat* format, const AEChannel** channelinfo)
{
  int track=0;
  std::string toLoad(strFile);
  if (toLoad.find(".asapstream") != std::string::npos)
  {
    size_t iStart=toLoad.rfind('-') + 1;
    track = atoi(toLoad.substr(iStart, toLoad.size()-iStart-11).c_str());
    //  The directory we are in, is the file
    //  that contains the bitstream to play,
    //  so extract it
    size_t slash = toLoad.rfind('\\');
    if (slash == std::string::npos)
      slash = toLoad.rfind('/');
    toLoad = toLoad.substr(0, slash);
  }

  void* file = XBMC->OpenFile(toLoad.c_str(),0);
  if (!file)
    return NULL;

  int len = XBMC->GetFileLength(file);
  uint8_t* data = new uint8_t[len];
  XBMC->ReadFile(file, data, len);
  XBMC->CloseFile(file);

  ASAPContext* result = new ASAPContext;
  result->asap = ASAP_New();

  // Now load the module
  if (!ASAP_Load(result->asap, toLoad.c_str(), data, len))
  {
    delete[] data;
    delete result;
  }
  delete[] data;

  const ASAPInfo* info = ASAP_GetInfo(result->asap);

  *channels = ASAPInfo_GetChannels(info);
  *samplerate = 44100;
  *bitspersample = 16;
  *totaltime = ASAPInfo_GetDuration(info, track);
  *format = AE_FMT_S16NE;
  *channelinfo = NULL;
  *bitrate = 0;

  ASAP_PlaySong(result->asap, track, *totaltime);

  return result;
}
bool ReadTag(const char* strFile, char* title, char* artist,
             int* length)
{
  int track=1;
  std::string toLoad(strFile);
  if (toLoad.find(".asapstream") != std::string::npos)
  {
    size_t iStart=toLoad.rfind('-') + 1;
    track = atoi(toLoad.substr(iStart, toLoad.size()-iStart-11).c_str());
    //  The directory we are in, is the file
    //  that contains the bitstream to play,
    //  so extract it
    size_t slash = toLoad.rfind('\\');
    if (slash == std::string::npos)
      slash = toLoad.rfind('/');
    toLoad = toLoad.substr(0, slash);
  }
  void* file = XBMC->OpenFile(toLoad.c_str(), 0);
  if (!file)
    return false;

  int len = XBMC->GetFileLength(file);
  uint8_t* data = new uint8_t[len];
  XBMC->ReadFile(file, data, len);
  XBMC->CloseFile(file);

  ASAP* asap = ASAP_New();

  // Now load the module
  if (!ASAP_Load(asap, strFile, data, len))
  {
    delete[] data;
    return false;
  }

  delete[] data;

  const ASAPInfo* info = ASAP_GetInfo(asap);
  strcpy(artist, ASAPInfo_GetAuthor(info));
  strcpy(title, ASAPInfo_GetTitleOrFilename(info));
  *length = ASAPInfo_GetDuration(info, track);

  return true;
}
void* Init(const char* strFile, unsigned int filecache, int* channels,
           int* samplerate, int* bitspersample, int64_t* totaltime,
           int* bitrate, AEDataFormat* format, const AEChannel** channelinfo)
{
  VorbisContext* result = new VorbisContext;
  result->track=0;
  std::string toLoad(strFile);
  if (toLoad.find(".oggstream") != std::string::npos)
  {
    size_t iStart=toLoad.rfind('-') + 1;
    result->track = atoi(toLoad.substr(iStart, toLoad.size()-iStart-10).c_str());
    //  The directory we are in, is the file
    //  that contains the bitstream to play,
    //  so extract it
    size_t slash = toLoad.rfind('\\');
    if (slash == std::string::npos)
      slash = toLoad.rfind('/');
    toLoad = toLoad.substr(0, slash);
  }

  result->file = XBMC->OpenFile(toLoad.c_str(), 0);
  if (!result->file)
  {
    delete result;
    return NULL;
  }
  result->callbacks = GetCallbacks(strFile);

  if (ov_open_callbacks(result->file, &result->vorbisfile,
                         NULL, 0, result->callbacks) != 0)
  {
    delete result;
    return NULL;
  }

  long iStreams=ov_streams(&result->vorbisfile);
  if (iStreams>1)
  {
    if (result->track > iStreams)
    {
      DeInit(result);
      return NULL;
    }
  }

  //  Calculate the offset in secs where the bitstream starts
  result->timeoffset = 0;
  for (int i=0; i<result->track; ++i)
    result->timeoffset += ov_time_total(&result->vorbisfile, i);

  vorbis_info* pInfo=ov_info(&result->vorbisfile, result->track);
  if (!pInfo)
  {
    XBMC->Log(ADDON::LOG_ERROR, "OGGCodec: Can't get stream info from %s", toLoad.c_str());
    DeInit(result);
    return NULL;
  }

  *channels      = pInfo->channels;
  *samplerate    = pInfo->rate;
  *bitspersample = 16;
  *totaltime     = (int64_t)ov_time_total(&result->vorbisfile, result->track)*1000;
  *format        = AE_FMT_S16NE;
  static enum AEChannel map[8][9] = {
    {AE_CH_FC, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FR, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FC, AE_CH_FR, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FR, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FC, AE_CH_FR, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FC, AE_CH_FR, AE_CH_BL, AE_CH_BR, AE_CH_LFE, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FC, AE_CH_FR, AE_CH_SL, AE_CH_SR, AE_CH_BL, AE_CH_BR, AE_CH_NULL},
    {AE_CH_FL, AE_CH_FC, AE_CH_FR, AE_CH_SL, AE_CH_SR, AE_CH_BL, AE_CH_BR, AE_CH_LFE, AE_CH_NULL}
  };

  *channelinfo = NULL;
  if (*channels <= 8)
    *channelinfo = map[*channels - 1];
  *bitrate = pInfo->bitrate_nominal;

  if (*samplerate == 0 || *channels == 0 || *bitspersample == 0 || *totaltime == 0)
  {
    XBMC->Log(ADDON::LOG_ERROR, "OGGCodec: Can't get stream info, SampleRate=%i, Channels=%i, BitsPerSample=%i, TotalTime=%" PRIu64, *samplerate, *channels, *bitspersample, *totaltime);
    delete result;
    return NULL;
  }

  if (result->timeoffset > 0.0)
  {
    if (ov_time_seek(&result->vorbisfile, result->timeoffset)!=0)
    {
      XBMC->Log(ADDON::LOG_ERROR, "OGGCodec: Can't seek to the bitstream start time (%s)", toLoad.c_str());
      DeInit(result);
      return NULL;
    }
  }

  return result;
}
Beispiel #4
0
int main( int argc, char *argv[] )
{
    GLFWwindow *window;
    int Edit;
    //File name to load
    string fileName;
    //whether name inputtted is valid
    bool validFile = false;

    //Try to determine file input
    while(validFile == false) {
        printf("Type the file to load (Special options: 'd' = default, 'c' = clean):\n");
        scanf("%s", &fileName[0]);

        ifstream toLoad(&fileName[0]);
        validFile = toLoad.good();

        //If 'c' was entered, then load a clean level
        if(strcmp(&fileName[0], "c") == 0) {
            printf("Loading clean level...\n");
            fileName = "clean";
            validFile = true;
        }
        //If 'd' was entered, then deafult level
        else if(strcmp(&fileName[0], "d") == 0) {
            printf("Loading default level...\n");
            fileName = "default";
            validFile = true;
        }
        else if(validFile == false) {
            printf("Bad file, please type another file to load.\n");
        }
        else if(validFile == true) {
            toLoad.close();
        }
    }

    //Determine mode
    printf("Type 0 to play, any other int to edit\n");
    scanf("%i", &Edit);

    glfwSetErrorCallback(glfwError);
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }

    //If Edit Mode
    if(Edit) {
        //World Edit Init
        //initWorldEdit(window);
        window = glfwCreateWindow(800, 800, "World Editor", NULL, NULL);
        if (!window) {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        srand(time(0));
        glfwMakeContextCurrent(window);
        glfwSetWindowPos(window, 80, 80);
        glfwSetWindowSizeCallback(window, glfwWindowResize);
        glfwSetWindowSize(window,1600,800);
        g_height =800;
        g_width = 1600;
        setDistance(7);
        SetEdit(1);
        paused = false;

        glfwSetKeyCallback( window, glfwEditKeyPress);
        glfwSetCursorPosCallback( window, glfwEditGetCursorPos );
        glfwSetMouseButtonCallback( window, glfwEditMouse );
        glfwSetScrollCallback( window, glfwEditScroll );

        glewInit();
        glInitialize(window);
        physicsInit();
        InitGeom();
        initLevelLoader();
        loadLevel(fileName);
    }
    //If Play Mode
    else {
        //Game Play Init
        //initGamePlay(window);
        window = glfwCreateWindow(800, 800, "Grapple", NULL, NULL);
        if (!window) {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }
        srand(time(0));
        SetEye(vec3(0, 0, 0));
        glfwMakeContextCurrent(window);
        glfwSetWindowPos(window, 80, 80);
        glfwSetWindowSizeCallback(window, glfwWindowResize);
        glfwSetWindowSize(window,1600,800);
        g_height =800;
        g_width = 1600;
        setDistance(10);
        paused = false;

        glfwSetKeyCallback(window, glfwGameKeyPress);
        glfwSetCursorPosCallback( window, glfwGameGetCursorPos );

        glewInit();
        glInitialize(window);
        physicsInit();
        InitGeom();
        initLevelLoader();
        loadLevel(fileName);
    }

    ShadowMap *shadowMap = new ShadowMap();
    if (shadowMap->MakeShadowMap(g_width, g_height) == -1) {
        printf("SHADOW MAP FAILED\n");
        exit(EXIT_FAILURE);
    }

    // Start the main execution loop.
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
        if(Edit) {
            if(paused == false) {
                //Keep the cursor centered
                glfwSetCursorPos(window,g_width/2,g_height/2);
                renderScene(window, shadowMap);
                glfwEditGetCursorPos(NULL,g_width/2.0,g_height/2.0);
                //glfw Game Keyboard
                glfwEditKeyboard();
            }
        }
        else {
            if(paused == false) {
                //player appy physics controls
                SetLookAt(glm::vec3(physGetPlayerX(),physGetPlayerY(),physGetPlayerZ()));
                SetSpeed(.05*magnitude(getPlayerSpeed()));
                //Keep the cursor centered
                glfwSetCursorPos(window,g_width/2,g_height/2);
                physStep();
                //Draw stuff
                renderScene(window, shadowMap);
                glfwGameGetCursorPos(NULL,g_width/2.0,g_height/2.0);
                //glfw Game Keyboard
                glfwGameKeyboard();
            }
        }
        usleep(15000);
    }

    // Clean up after GLFW.
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}
hypergraph *first_choice_coarsener::coarsen(const hypergraph &h) {
  load_for_coarsening(h);
  // ###
  // back off if the hypergraph too small
  // ###

  if (numVertices < minimum_number_of_nodes_)
    return nullptr;

  int numNotMatched = numVertices;
  int bestMatch;
  int bestMatchWt = -1;
  int numNeighbours;
  int limitOnIndex;

  int candVertex;
  int candVertexEntry;

  int i;
  int j;
  int ij;

  int v;
  int coarseIndex;

  int endVerOffset;
  int endHedgeOffset;
  int hEdge;

  double reducedBy;
  double maxMatchMetric;
  double metricVal;

  dynamic_array<int> neighVerts;
  dynamic_array<int> neighPairWts;
  dynamic_array<int> vertices(numVertices);
  dynamic_array<int> vertexAdjEntry(numVertices);
  dynamic_array<int> coarseWts;

  dynamic_array<double> connectVals;

  bit_field toLoad(numHedges);
  toLoad.set();

  for (i = 0; i < numVertices; ++i) {
    vertices[i] = i;
    vertexAdjEntry[i] = -1;

#ifdef DEBUG_COARSENER
    assert(matchVector[i] == -1);
#endif
  }

  if (currPercentile < 100)
    compute_hyperedges_to_load(toLoad);

  vertices.random_permutation();

  metricVal = static_cast<double>(numVertices) / reduction_ratio_;
  limitOnIndex = numVertices - static_cast<int>(floor(metricVal - 1.0));

  i = 0;
  coarseIndex = 0;

  for (; i < numVertices; ++i) {
    if (matchVector[vertices[i]] == -1) {
      v = vertices[i];
      bestMatch = -1;
      maxMatchMetric = 0;
      numNeighbours = 0;

      endVerOffset = vOffsets[v + 1];

      for (j = vOffsets[v]; j < endVerOffset; ++j) {
        hEdge = vToHedges[j];

        if (toLoad(hEdge) == 1) {
          endHedgeOffset = hEdgeOffsets[hEdge + 1];

          for (ij = hEdgeOffsets[hEdge]; ij < endHedgeOffset; ++ij) {
            candVertex = pinList[ij];

            if (candVertex != v) {
              candVertexEntry = vertexAdjEntry[candVertex];

              if (candVertexEntry == -1) {
                neighVerts[numNeighbours] = candVertex;

                if (matchVector[candVertex] == -1)
                  neighPairWts[numNeighbours] = vWeight[v] + vWeight[candVertex];
                else
                  neighPairWts[numNeighbours] = vWeight[v] + coarseWts[matchVector[candVertex]];

                if (util_fan_out_)
                  connectVals[numNeighbours] = static_cast<double>(hEdgeWeight[hEdge]) / (endHedgeOffset - (hEdgeOffsets[hEdge] + 1));
                else
                  connectVals[numNeighbours] = static_cast<double>(hEdgeWeight[hEdge]);

                vertexAdjEntry[candVertex] = numNeighbours;
                ++numNeighbours;
              } else {
                if (util_fan_out_)
                  connectVals[candVertexEntry] +=
                      static_cast<double>(hEdgeWeight[hEdge]) /
                      (endHedgeOffset - (hEdgeOffsets[hEdge] + 1));
                else
                  connectVals[candVertexEntry] +=
                      static_cast<double>(hEdgeWeight[hEdge]);
              }
            }
          }
        }
      }

      if (numNeighbours == 0) {
        // match vertex v as singleton as not connected

        matchVector[v] = coarseIndex;
        coarseWts[coarseIndex++] = vWeight[v];
        --numNotMatched;
      } else {
        // else need to pick the best match

        for (j = 0; j < numNeighbours; ++j) {
          if (neighPairWts[j] < maximum_vertex_weight_) {
            metricVal = connectVals[j];

            if (divide_by_cluster_weight_)
              metricVal /= neighPairWts[j];

            if (metricVal > maxMatchMetric) {
              maxMatchMetric = metricVal;
              bestMatch = neighVerts[j];
              bestMatchWt = neighPairWts[j];
            }
          }

          vertexAdjEntry[neighVerts[j]] = -1;
        }

        if (bestMatch == -1) {
          // no best match as all would violate max
          // vertex weight - match as singleton

          matchVector[v] = coarseIndex;
          coarseWts[coarseIndex++] = vWeight[v];
          --numNotMatched;
        } else {
          if (matchVector[bestMatch] == -1) {
            // match with another unmatched

            matchVector[v] = coarseIndex;
            matchVector[bestMatch] = coarseIndex;
            coarseWts[coarseIndex++] = bestMatchWt;
            numNotMatched -= 2;
          } else {
            // match with existing cluster of coarse vertices

            matchVector[v] = matchVector[bestMatch];
            coarseWts[matchVector[v]] += vWeight[v];
            --numNotMatched;
          }
        }
      }

      // check if hypergraph sufficiently shrunk

      if (i > limitOnIndex) {
        reducedBy =
            static_cast<double>(numVertices) / (numNotMatched + coarseIndex);

        if (reducedBy > reduction_ratio_)
          break;
      }
    }
  }

  if (i == numVertices) {
    // cannot sufficiently reduce hypergraph
    // back off
    return nullptr;
  }

  // match remaining unmatched vertices as singletons

  for (; i < numVertices; ++i) {
    v = vertices[i];

    if (matchVector[v] == -1) {
      matchVector[v] = coarseIndex;
      coarseWts[coarseIndex++] = vWeight[v];
    }
  }

#ifdef DEBUG_COARSENER
  for (j = 0; j < numVertices; ++j)
    assert(matchVector[j] >= 0 && matchVector[j] < coarseIndex);
#endif

  coarseWts.reserve(coarseIndex);

  return (build_coarse_hypergraph(coarseWts, coarseIndex, h.total_weight()));
}