Exemplo n.º 1
0
void cMapManager::Draw() {
    int shiftX = 0;
    int shiftY = 0;
    for(int i = start.x; i <= end.x; i++){
        for(int j = start.y; j <= end.y; j++){
            if(chunks[i][j] != NULL){
                shiftX = camera.x - (i * GetCommon()->mapChunkWidthPx);
                shiftY = camera.y - (j * GetCommon()->mapChunkHeightPx);
                chunks[i][j]->DrawBot(-shiftX, -shiftY);
                chunks[i][j]->DrawTop(-shiftX, -shiftY, drawTriggerGrid);
            } else {
                chunks[i][j] = new cMapChunk();
                char tmpName[50];
                sprintf(tmpName, "%dx%d", i, j);
                switch(chunks[i][j]->Load(tmpName)){
                    case CHUNK_NOT_FOUND:
                        chunks[i][j]->InitEmpty(1);
                        break;
                    case CHUNK_INVALID_FILE:
                        break;
                }
                loadedChunks.push_back(sPoint(i, j));
            }
        }
    }
}
Exemplo n.º 2
0
void cMapManager::Init() {
    for(int i = 0; i < GetCommon()->mapWorldWidth; i++){
        std::vector<cMapChunk*> tmpVec;
        
        for(int j = 0; j < GetCommon()->mapWorldHeight; j++){
            tmpVec.push_back(NULL);
        }
        
        chunks.push_back(tmpVec);
        tmpVec.clear();
    }
    
    S_AddTimedCallback(
                new cStormCallbacker(this, 
                                    &cMapManager::Clear, 
                                    GetCommon()->mapChunkTimeout));
    
    
    HandleCamera(1, 1);
    
    debugMapEditor = new cDebgMapEditor();
    debugMapEditor->Init();
    
    StormPrintLog(STORM_LOG_INFO, "cMapManager", "Initialized");
}
Exemplo n.º 3
0
sMapTile *cMapManager::GetTile(int x, int y) {
    int chunkX = x / GetCommon()->mapChunkWidth;
    int chunkY = y / GetCommon()->mapChunkHeight;
    if(chunks[chunkX][chunkY] == NULL)
            return NULL;
    x -= chunkX * GetCommon()->mapChunkWidth;
    y -= chunkY * GetCommon()->mapChunkHeight;
    return chunks[chunkX][chunkY]->GetTile(x, y);
}
Exemplo n.º 4
0
void cMapManager::CalculateVisible() {
    start.x = camera.x / GetCommon()->mapChunkWidthPx;
    start.y = camera.y / GetCommon()->mapChunkHeightPx;

    if(start.x < 0)
            start.x = 0;
    if(start.y < 0)
            start.y = 0;

    end.x = start.x + 2;
    end.y = start.y + 2;
}
Exemplo n.º 5
0
void cEntityManager::Draw() {
    sPoint *cam = GetCommon()->mapManager->GetCamera();
    
    for(int i = 0; i < (int)entities.size(); i++){
        cEntity *tmpE = entities[i];
        if(tmpE->IsPawn()){
            ((cPawn*)tmpE)->Draw(cam->x, cam->y);
        }
    }
}
Exemplo n.º 6
0
int cMapManager::GetTriggerScreen(int x, int y) {
    sMapTile *ch = GetTileScreen(x, y);
    int tx = ((int)x / GetCommon()->mapChunkWidthPx) * GetCommon()->mapChunkWidthPx;
    int ty = ((int)y / GetCommon()->mapChunkHeightPx) * GetCommon()->mapChunkHeightPx;
    x = (x - tx) / (GetCommon()->mapChunkWidthPx / 2);
    y = (y - ty) / (GetCommon()->mapChunkHeightPx / 2);
    return ch->triggers[x][y];
}
Exemplo n.º 7
0
void cMapManager::SetTriggerScreen(int x, int y, int v) {
    sMapTile *ch = GetTileScreen(x, y);
    int tx = ((x + camera.x) / GetCommon()->mapTileWidth) * GetCommon()->mapTileWidth;
    int ty = ((y + camera.y) / GetCommon()->mapTileHeight) * GetCommon()->mapTileHeight;
    x = ((x + camera.x) - tx) / (GetCommon()->mapTileWidth / 2);
    y = ((y + camera.y) - ty) / (GetCommon()->mapTileHeight / 2);
    
    ch->triggers[x][y] = v;
}
Exemplo n.º 8
0
void cMapManager::Clear(void *data) {
    if(loadedChunks.size() < 9)
        return;
    for(int i = 0; i < loadedChunks.size(); i++){
        sPoint tmpC = loadedChunks[i];
        cMapChunk *tmpCh = chunks[tmpC.x][tmpC.y];
        
        //Check if this chunk is still needed
        if(tmpC.x >= start.x && tmpC.x <= end.x 
                && tmpC.y >= start.y && tmpC.y <= end.y){
            //This chunk is still needed
            if(tmpCh->GetTimeout() > 0)
                tmpCh->SetTimeout(0);
            continue;
        }
        
        if(tmpCh == NULL){
            loadedChunks.erase(loadedChunks.begin() + i);
            i = (i > 0) ? i - 1 : 0;
            continue;
        }
        
        if(tmpCh->GetTimeout() == 0){
            //If timeout timer is not started, start it
            tmpCh->SetTimeout(S_GetTime());
            continue;
        }
        
        if(S_GetTime() - tmpCh->GetTimeout() >= GetCommon()->mapChunkTimeout){
            //Chunk timeouted. Delete it...
            //TODO: Maybe save chunk file if it was changed ...
            delete tmpCh;
            chunks[tmpC.x][tmpC.y] = NULL;
            loadedChunks.erase(loadedChunks.begin() + i);
            i = (i > 0) ? i - 1 : 0;
            
            StormPrintLog(STORM_LOG_INFO, "cMapManager",
                            "Chunk %dx%d has just been deleted form memory",
                            tmpC.x, tmpC.y);
        }
    }
}
Exemplo n.º 9
0
cMapChunk *cMapManager::GetChunkScreen(int x, int y) {
    x = (x + camera.x) / GetCommon()->mapChunkWidthPx;
    y = (y + camera.y) / GetCommon()->mapChunkHeightPx;
    return chunks[x][y];
}
Exemplo n.º 10
0
sMapTile *cMapManager::GetTileScreen(int x, int y) {
    x = (x + camera.x) / GetCommon()->mapTileWidth;
    y = (y + camera.y) / GetCommon()->mapTileHeight;
    return GetTile(x, y);
}
Exemplo n.º 11
0
void cCameraManager::Tick(){
    sCommon *tmpC = GetCommon();
    cVector2d *tmp = tmpC->playerDriver->GetCharacter()->GetLoc();
    tmpC->mapManager->HandleCamera((int)tmp->x, (int)tmp->y);
}
Exemplo n.º 12
0
int64 CountTriangles2(const PNGraph &Graph) {
  struct timeval start, end;
  float delta;
  TTmProfiler Profiler;
  int TimerId = Profiler.AddTimer("Profiler");
  const int NNodes = Graph->GetNodes();

  TIntV MapV(NNodes);
  TVec<TNGraph::TNodeI> NV(NNodes);
  NV.Reduce(0);

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

  int MxId = -1;
  int ind = 0;
  for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++)   {
    NV.Add(NI);
    int Id = NI.GetId();
    if (Id > MxId) {
      MxId = Id;
    }
    MapV[ind] = Id;
    ind++;
  }

  TIntV IndV(MxId+1);

  for (int j = 0; j < NNodes; j++) {
    IndV[MapV[j]] = j;
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
          end.tv_usec - start.tv_usec) / 1.e6;
  printf("__nodemap__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

  ind = MapV.Len();

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

  TVec<TIntV> HigherDegNbrV(ind);

  for (int i = 0; i < ind; i++) {
    HigherDegNbrV[i] = TVec<TInt>();
    HigherDegNbrV[i].Reserve(NV[i].GetDeg());
    HigherDegNbrV[i].Reduce(0);
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
            end.tv_usec - start.tv_usec) / 1.e6;
  printf("__valloc__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

#pragma omp parallel for schedule(dynamic)
  for (TInt i = 0; i < ind; i++) {
    TNGraph::TNodeI NI = NV[i];
    //HigherDegNbrV[i] = TVec<TInt>();
    //HigherDegNbrV[i].Reserve(NI.GetDeg());
    //HigherDegNbrV[i].Reduce(0);

    GetMergeSortedV(HigherDegNbrV[i], NI);

    int k = 0;
    for (TInt j = 0; j < HigherDegNbrV[i].Len(); j++) {
      TInt Vert = HigherDegNbrV[i][j];
      TInt Deg = NV[IndV[Vert]].GetDeg();
      if (Deg > NI.GetDeg() ||
         (Deg == NI.GetDeg() && Vert > NI.GetId())) {
        HigherDegNbrV[i][k] = Vert;
        k++;
      }
    }
    HigherDegNbrV[i].Reduce(k);
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
            end.tv_usec - start.tv_usec) / 1.e6;
  printf("__sort__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

  int64 cnt = 0;
#pragma omp parallel for schedule(dynamic) reduction(+:cnt)
  for (TInt i = 0; i < HigherDegNbrV.Len(); i++) {
    for (TInt j = 0; j < HigherDegNbrV[i].Len(); j++) {
      //TInt NbrInd = H.GetDat(HigherDegNbrV[i][j]);
      TInt NbrInd = IndV[HigherDegNbrV[i][j]];

      int64 num = GetCommon(HigherDegNbrV[i], HigherDegNbrV[NbrInd]);
      cnt += num;
    }
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
            end.tv_usec - start.tv_usec) / 1.e6;
  printf("__count__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  return cnt;
}
Exemplo n.º 13
0
// Rok #13
//template<class PGraph> 
int64 CountTriangles1(const TVec<TNGraph::TNodeI,int>& NV, const TIntV& IndV, const TIntV& MapV) {
  struct timeval start, end;
  float delta;
  TTmProfiler Profiler;
  int TimerId = Profiler.AddTimer("Profiler");

  int ind = MapV.Len();

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

  TVec<TIntV> HigherDegNbrV(ind);

  for (int i = 0; i < ind; i++) {
    HigherDegNbrV[i] = TVec<TInt>();
    HigherDegNbrV[i].Reserve(NV[i].GetDeg());
    HigherDegNbrV[i].Reduce(0);
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
            end.tv_usec - start.tv_usec) / 1.e6;
  printf("__valloc__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

#pragma omp parallel for schedule(dynamic)
  for (TInt i = 0; i < ind; i++) {
    TNGraph::TNodeI NI = NV[i];
    //HigherDegNbrV[i] = TVec<TInt>();
    //HigherDegNbrV[i].Reserve(NI.GetDeg());
    //HigherDegNbrV[i].Reduce(0);

    GetMergeSortedV(HigherDegNbrV[i], NI);

    int k = 0;
    for (TInt j = 0; j < HigherDegNbrV[i].Len(); j++) {
      TInt Vert = HigherDegNbrV[i][j];
      TInt Deg = NV[IndV[Vert]].GetDeg();
      if (Deg > NI.GetDeg() ||
         (Deg == NI.GetDeg() && Vert > NI.GetId())) {
        HigherDegNbrV[i][k] = Vert;
        k++;
      }
    }
    HigherDegNbrV[i].Reduce(k);
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
            end.tv_usec - start.tv_usec) / 1.e6;
  printf("__sort__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  Profiler.ResetTimer(TimerId);
  Profiler.StartTimer(TimerId);
  gettimeofday(&start, NULL);

  int64 cnt = 0;
#pragma omp parallel for schedule(dynamic) reduction(+:cnt)
  for (TInt i = 0; i < HigherDegNbrV.Len(); i++) {
    for (TInt j = 0; j < HigherDegNbrV[i].Len(); j++) {
      //TInt NbrInd = H.GetDat(HigherDegNbrV[i][j]);
      TInt NbrInd = IndV[HigherDegNbrV[i][j]];

      int64 num = GetCommon(HigherDegNbrV[i], HigherDegNbrV[NbrInd]);
      cnt += num;
    }
  }

  gettimeofday(&end, NULL);
  Profiler.StopTimer(TimerId);
  delta = ((end.tv_sec  - start.tv_sec) * 1000000u +
            end.tv_usec - start.tv_usec) / 1.e6;
  printf("__count__\ttime %7.3f\tcpu %8.3f\n", delta, Profiler.GetTimerSec(TimerId));

  return cnt;
}
Exemplo n.º 14
0
FRAGMENT_INF * GetInf() {  return (FRAGMENT_INF*)GetCommon();  }
Exemplo n.º 15
0
SCHEMA_EXPORT  STEEL_DATA *  GetSteelData() { return (STEEL_DATA*)GetCommon();  }