예제 #1
0
파일: Video.cpp 프로젝트: PZerua/GameVoid
void Video::drawScanLine()
{
	BYTE control = _memory->read(LCDC);
	if (testBit(control, 0))
		renderTiles();

	if (testBit(control, 1))
		renderSprites();
}
예제 #2
0
void VRAMCache::renderAllFlips(
    int tileIndex,
    GGTileSet& tiles,
    GGPalette& palette,
    Graphic::TileTransferTransOption tileTransOption) {
    // Render to main cache
    renderTiles(cache_,
                tileIndex,
                tiles,
                palette,
                tileTransOption);

    // Create flipped variants
    for (int j = 0; j < tiles.numTiles(); j++) {
        tiles[j].flipHorizontal();
    }

    renderTiles(horizontalFlipCache_,
                tileIndex,
                tiles,
                palette,
                tileTransOption);

    for (int j = 0; j < tiles.numTiles(); j++) {
        tiles[j].flipHorizontal();
        tiles[j].flipVertical();
    }

    renderTiles(verticalFlipCache_,
                tileIndex,
                tiles,
                palette,
                tileTransOption);

    for (int j = 0; j < tiles.numTiles(); j++) {
        tiles[j].flipHorizontal();
    }

    renderTiles(bothFlipCache_,
                tileIndex,
                tiles,
                palette,
                tileTransOption);
}
예제 #3
0
void EmuinoSDL::render()
{
    if (!setup) return;
    
    renderTiles();
    
    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    
    SDL_UpdateTexture(screenTexture, NULL, screenSurface->pixels, screenSurface->pitch);
    
    // get camera offset
    int16_t camX = 0, camY = 0;
    
    SharedRAM.read(REG_SCROLL_X | 0x8000, &camX, 2);
    SharedRAM.read(REG_SCROLL_Y | 0x8000, &camY, 2);
    
    // render everything on the screen texture such as sprites and tilemaps
    SDL_SetRenderTarget(renderer, screenTexture);
    for (int i = 0; i < NUM_TILE_LAYERS; i++) {
        int16_t offsetX, offsetY;
        int w = tileMapSurfaces[i]->w;
        int h = tileMapSurfaces[i]->h;
        SharedRAM.read(TILE_LAYER_REG(i, TILE_OFFSET_X) | 0x8000, &offsetX, 2);
        SharedRAM.read(TILE_LAYER_REG(i, TILE_OFFSET_Y) | 0x8000, &offsetY, 2);
        
        // add camera offset
        offsetX -= camX;
        offsetY -= camY;
        
        // hacky repetition, will need to be replaced with proper OpenGL texture repetition
        offsetX = offsetX % w;
        if (offsetX < 0)
            offsetX += w;
        
        offsetY = offsetY % h;
        if (offsetY < 0)
            offsetY += w;
        
        SDL_Rect offsetRect = {offsetX, offsetY, w, h};
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
        offsetRect.x -= w;
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
        offsetRect.y -= w;
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
        offsetRect.x = offsetX;
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
    }
    SDL_SetRenderTarget(renderer, NULL);
    
    // render the screen texture
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, screenTexture, NULL, NULL);
    SDL_RenderPresent(renderer);
}
예제 #4
0
파일: lcd.c 프로젝트: MajoraBora/CoolBoy
void drawScanline(struct gameboy * gameboy)
{
	//printf("draw scanline\n");
	if (backgroundTilesEnabled(gameboy)){
	//	printf("Rendering tiles\n");
		renderTiles(gameboy);
	}
	
	if (spritesEnabled(gameboy)){
	//	printf("Rendering Sprites\n");
		//renderSprites(gameboy);
	}
}
예제 #5
0
void GraphicsTCOD::render() {

    entMap->refreshEntityMap();

    renderTiles();
    renderEntities();



    TCODConsole::blit(output, 0, 0, MAIN_WIDTH, MAIN_HEIGHT, TCODConsole::root, 0, 0);
    TCODConsole::flush();


}
예제 #6
0
MapGraphicsView::MapGraphicsView(MapGraphicsScene *scene, QWidget *parent) :
    QWidget(parent)
{
    //Setup the given scene and set the default zoomLevel to 3
    this->setScene(scene);
    _zoomLevel = 2;

    //The default drag mode allows us to drag the map around to move the view
    this->setDragMode(MapGraphicsView::ScrollHandDrag);

    //Start the timer that will cause the tiles to periodically move to follow the view
    QTimer * renderTimer = new QTimer(this);
    connect(renderTimer,
            SIGNAL(timeout()),
            this,
            SLOT(renderTiles()));
    renderTimer->start(200);
}
void VRAMEditorLayeredGraphicScene::render(
                    Graphic& dst,
                    Box srcbox,
                    double scale) {
  // Create empty graphic with white background (TODO: selectable BG color)
  // The normal background color is black, so unused tiles will show up
  // as white
//  Graphic g(nativeWidth(), nativeHeight());
//  g.clear(Color(0, 0, 0, 0));
  g_.clear();
  
  // Get level graphics header containing graphics to render
  int levelGraphicsHeaderIndex
    = levelGraphicsData_.levelHeaderIndexByMapnum(areaNum_,
                                                  mapNum_);
  LevelGraphicsHeader& levelGraphicsHeader
    = levelGraphicsData_.levelGraphicsHeader(levelGraphicsHeaderIndex);
    
  // Look up palette header for this level
  LevelPaletteHeader& levelPaletteHeader
    = paletteHeaders_.headerByIndex(
        paletteHeaders_.indexOfMapNum(areaNum_,
                                      mapNum_));
  
  // Get level palettes
  GGPalette palette0
    = palettes_.palette(levelPaletteHeader.palette0Index());
  GGPalette palette1
    = palettes_.palette(levelPaletteHeader.palette1Index());
  
  // Get map graphic index
  int mapGraphicIndex = levelGraphicsHeader.mapGraphicIndex();
  
  // Get map graphic
  GGTileSet mapGraphic
    = levelGraphicsData_.compressedGraphic(mapGraphicIndex);
  
  // Get index of the start of the map tiles
  int mapTileIndex
    = vramAddressToTileIndex(levelGraphicsHeader.vdpWriteAddress());
    
  // Render map graphic
  renderTiles(g_,
              mapTileIndex,
              mapGraphic,
              palette0,
              Graphic::noTileTrans);
    
  // Get object graphics header index
  int objectGraphicsHeaderIndex
    = levelGraphicsHeader.objectGraphicsHeaderIndex();
    
  // Get object graphics header
  ObjectGraphicsHeader& objectGraphicsHeader
    = levelGraphicsData_.objectGraphicsHeader(objectGraphicsHeaderIndex);
    
  // Iterate over graphics subheaders and add object graphics to render
  for (int i = 0; i < objectGraphicsHeader.size(); i++) {
    ObjectGraphicSubheader& subheader
      = objectGraphicsHeader.subheader(i);
    
    int objectGraphicIndex = subheader.objectGraphicIndex();
    
    // Get graphic
    GGTileSet objectGraphic
      = levelGraphicsData_.compressedGraphic(objectGraphicIndex);
      
    // Flip tiles if horizontal flip flag is set
    if (subheader.substitutionOption()
          == ObjectGraphicSubheader::substitutionEnabled) {
      for (int j = 0; j < objectGraphic.numTiles(); j++) {
        objectGraphic[j].flipHorizontal();
      }
    }
    
    // Get index of the tile
    int tileIndex = vramAddressToTileIndex(subheader.vdpWriteAddress());
    
    // Render object graphic.
    // Use palette 1 (sprite palette) for objects.
    // Technically we "should" use transparency here, but it's possible
    // to overwrite one graphic with another and we don't want to leave
    // scraps of the previous graphic visible when that happens.
    // TODO: add some concept of background color (maybe change color 0
    // in palette?)
    renderTiles(g_,
                tileIndex,
                objectGraphic,
                palette1,
                Graphic::noTileTrans);
    
    // Draw full graphic selection box if enabled and needed
    // (this will be scaled with the graphic, negating the benefits of vector-
    // based drawing!)
    if ((i == fullSelectionBoxGraphicIndex_)
        && fullSelectionBoxEnabled_) {
        
/*      // Draw line on left side of first tile
      int firstXPos = tileIndexToXPos(tileIndex);
      int firstYPos = tileIndexToYPos(tileIndex);
      g.drawLine(firstXPos, firstYPos,
                 firstXPos, firstYPos + GGTile::height,
                 Color(255, 255, 255, Color::fullAlphaOpacity),
                 2,
                 Graphic::noTransUpdate);
        
      // Draw line on right side of last tile
      int lastXPos = tileIndexToXPos(tileIndex + objectGraphic.numTiles());
      int lastYPos = tileIndexToYPos(tileIndex + objectGraphic.numTiles());
      g.drawLine(lastXPos + GGTile::width, lastYPos,
                 lastXPos + GGTile::width, lastYPos + GGTile::height,
                 Color(255, 255, 255, Color::fullAlphaOpacity),
                 2,
                 Graphic::noTransUpdate);
      
      // Box each tile in the graphic
      for (int j = 0; j < objectGraphic.numTiles(); j++) {
        // Calculate position in Graphic
        int xPos = tileIndexToXPos(tileIndex);
        int yPos = tileIndexToYPos(tileIndex);
        
        // Draw lines above and below tile
        g.drawLine(xPos, yPos,
                   xPos + GGTile::width, yPos,
                   Color(255, 255, 255, Color::fullAlphaOpacity),
                   2,
                   Graphic::noTransUpdate);
        g.drawLine(xPos, yPos + GGTile::height,
                   xPos + GGTile::width, yPos + GGTile::height,
                   Color(255, 255, 255, Color::fullAlphaOpacity),
                   2,
                   Graphic::noTransUpdate);
        
        // Move to next tile position
        ++tileIndex;
      } */
      
/*      for (int j = 0; j < objectGraphic.numTiles(); j++) {
        // Calculate position in Graphic
        int xPos = tileIndexToXPos(tileIndex + j);
        int yPos = tileIndexToYPos(tileIndex + j);
        BoxGraphicSceneObject box(Color(255, 0, 255, Color::fullAlphaOpacity),
                                  2,
                                  GGTile::width,
                                  GGTile::height,
                                  xPos,
                                  yPos,
                                  true);
        
        box.render(g,
                   Box(0, 0, dst.w(), dst.h()),
                   1.00);
      } */
    }
  }
    
/*  GenericGraphicSceneLayer graphics;
  Graphic testG(nativeWidth(), nativeHeight());
  renderTiles(testG,
              0,
              mapGraphic,
              palette0,
              Graphic::noTileTrans);
  BitmapGraphicSceneObject* testBitmap
    = new BitmapGraphicSceneObject(testG,
                           0,
                           0,
                           true);
  graphics.addObject(testBitmap);
  graphics.render(g,
                  Box(0, 0, nativeWidth(), nativeHeight()),
                  1.00,
                  1.00); */
                  
/*  GenericGraphicSceneLayer graphics;
  BoxGraphicSceneObject* testBox
    = new BoxGraphicSceneObject(Color(255, 0, 0, 0),
                                3,
                                45,
                                45,
                                20,
                                20,
                                true);
  graphics.addObject(testBox);
  graphics.render(g,
                  Box(0, 0, nativeWidth(), nativeHeight()),
                  3.00,
                  1.00); */
              
  int width = srcbox.w();
  int height = srcbox.h();
  
  // If width or height parameter is zero, replace with maximum
  if (width == 0) {
    width = nativeWidth();
  }
  
  if (height == 0) {
    height = nativeHeight();
  }
              
  // Crop if necessary
  if ((srcbox.x() != 0) || (srcbox.y() != 0)) {
    Graphic tmp(width, height);
    
    // Copy desired portion to temp graphic
    tmp.copy(g_,
             Box(0, 0, width, height),
             Box(srcbox.x(),
                 srcbox.y(),
                 width,
                 height),
             Graphic::noTransUpdate);
             
    // Copy temp graphic to primary
    g_ = tmp;
  }
  
  // Scale graphic if necessary
  if (scale == 1.00) {
    dst = g_;
  }
  else {
//    dst = Graphic(width * scale, height * scale);
    g_.scale(dst,
             Box(0, 0, width * scale, height * scale),
             Graphic::noTransUpdate);
  }
    
  // Draw grid if enabled
  if (gridEnabled_) {
    grid_.render(dst,
                 Box(srcbox.x(),
                     srcbox.y(),
                     width * scale,
                     height * scale),
                 scale);
  }
  
  if (EditorMetadata::areaNumHasVRAMIndices(areaNum_)) {
//    std::cerr << areaNum_ << " " << mapNum_ << std::endl;
    // Draw leaf box if enabled
    if (showLeaf_) {
      boxGenericLength(dst,
                       leafGraphicsTable_.entry(areaNum_),
                       EditableLeafGraphicsTable::numGraphicTiles,
                       leafBoxColor,
                       2,
                       scale);
    }
    
    // Draw water splash box if enabled
    if (showWaterSplash_) {
      boxGenericLength(dst,
                       waterSplashGraphicTable_.entry(areaNum_, mapNum_)
                        .leftTileIndex(),
                       EditableWaterSplashGraphicTable::numGraphicTiles,
                       waterSplashBoxColor,
                       2,
                       scale);
    }
    
    // Draw smoke puff box if enabled
    if (showSmokePuff_) {
      boxGenericLength(dst,
                       smokePuffGraphicTable_.entry(areaNum_, mapNum_)
                        .leftTileIndex(),
                       EditableSmokePuffGraphicTable::numGraphicTiles,
                       smokePuffBoxColor,
                       2,
                       scale);
    }
  }
  
  // Draw full graphic selection box if enabled
  if (fullSelectionBoxEnabled_) {
    ObjectGraphicSubheader& subheader
      = objectGraphicsHeader.subheader(fullSelectionBoxGraphicIndex_);
    
    int tileIndex = vramAddressToTileIndex(subheader.vdpWriteAddress());
    GGTileSet objectGraphic
      = levelGraphicsData_.compressedGraphic(
          subheader.objectGraphicIndex());
    
    // Box each tile in the graphic
    for (int i = 0; i < objectGraphic.numTiles(); i++) {
      // Calculate position in Graphic
      int xPos = tileIndexToXPos(tileIndex);
      int yPos = tileIndexToYPos(tileIndex);
    
      BoxGraphicSceneObject box(fullGraphicSelectionBoxColor,
                                2,
                                GGTile::width * scale,
                                GGTile::height * scale,
                                xPos * scale,
                                yPos * scale,
                                true);
      
      box.render(dst,
                 Box(0, 0, dst.w(), dst.h()),
                 1.00);
      
      // Move to next tile position
      ++tileIndex;
    }
  }
  
  // Draw selection box if enabled
  if (selectionBoxEnabled_) {
    BoxGraphicSceneObject box(selectionBoxColor,
                              3,
                              GGTile::width * scale,
                              GGTile::height * scale,
                              (selectionBoxX_ - srcbox.x())
                                * GGTile::width * scale,
                              (selectionBoxY_ - srcbox.y())
                                * GGTile::height * scale,
                              true);
    
    box.render(dst,
               Box(0, 0, dst.w(), dst.h()),
               1.00);
  }
  
  // Draw tile picker selection box if enabled
  if (tilePickerPreviewEnabled_) {
      boxGenericLength(dst,
                       tilePickerPreviewIndex_,
                       tilePickerPreviewLength_,
                       tilePickerPreviewColor_,
                       2,
                       scale);
  }
}