Commit para seguir en otro ordenador

This commit is contained in:
2021-09-14 22:52:25 +02:00
parent 8c919abc9d
commit 778672a6f5
4 changed files with 50 additions and 46 deletions

View File

@@ -11,16 +11,16 @@
#define HALF_BLOCK BLOCK / 2
// Tamaño de la pantalla que contendrá la pantalla de juego
#define REAL_SCREEN_WIDTH 320
#define REAL_SCREEN_HEIGHT 240
//#define REAL_SCREEN_WIDTH 256
//#define REAL_SCREEN_HEIGHT 192
// Tamaño de la pantalla de juego
#define SCREEN_WIDTH 256
#define SCREEN_HEIGHT 192
// Tamaño de la pantalla que se muestra
const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3;
const int VIEW_HEIGHT = REAL_SCREEN_HEIGHT * 3;
//const int VIEW_WIDTH = REAL_SCREEN_WIDTH * 3;
//const int VIEW_HEIGHT = REAL_SCREEN_HEIGHT * 3;
// Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK);

View File

@@ -27,20 +27,21 @@ Director::Director(std::string path)
// Crea el puntero a la estructura y carga el fichero de configuración
mOptions = new options_t;
if (!loadConfigFile())
{
mOptions->fullScreenMode = 0;
mOptions->windowSize = 3;
mOptions->language = en_UK;
mOptions->difficulty = DIFFICULTY_NORMAL;
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
mOptions->filter = FILTER_NEAREST;
mOptions->vSync = true;
mOptions->screenHeight = SCREEN_HEIGHT;
mOptions->screenWidth = SCREEN_WIDTH;
mOptions->integerScale = true;
}
loadConfigFile();
//if (!loadConfigFile())
//{
// mOptions->fullScreenMode = 0;
// mOptions->windowSize = 3;
// mOptions->language = en_UK;
// mOptions->difficulty = DIFFICULTY_NORMAL;
// mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
// mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
// mOptions->filter = FILTER_NEAREST;
// mOptions->vSync = true;
// mOptions->screenHeight = SCREEN_HEIGHT;
// mOptions->screenWidth = SCREEN_WIDTH;
// mOptions->integerScale = true;
//}
// Crea los objetos
mInput = new Input(mFileList[53]);
@@ -171,7 +172,7 @@ bool Director::initSDL()
}
// Crea la ventana
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, VIEW_WIDTH, VIEW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
mWindow = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, mOptions->screenWidth * mOptions->windowSize, mOptions->screenHeight * mOptions->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
if (mWindow == NULL)
{
printf("Window could not be created!\nSDL Error: %s\n", SDL_GetError());
@@ -367,9 +368,9 @@ bool Director::loadConfigFile()
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
mOptions->filter = FILTER_NEAREST;
mOptions->vSync = true;
mOptions->screenHeight = 480;
mOptions->screenWidth = 640;
mOptions->integerScale = true;
mOptions->screenWidth = 544;
mOptions->screenHeight = 834;
mOptions->integerScale = false;
// Indicador de éxito en la carga
bool success = true;
@@ -398,8 +399,8 @@ bool Director::loadConfigFile()
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
// Cierra el fichero
@@ -424,8 +425,8 @@ bool Director::loadConfigFile()
SDL_RWread(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
SDL_RWread(file, &mOptions->filter, sizeof(mOptions->filter), 1);
SDL_RWread(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
SDL_RWread(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
SDL_RWread(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
SDL_RWread(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
// Normaliza los valores
@@ -463,8 +464,8 @@ bool Director::saveConfigFile()
SDL_RWwrite(file, &mOptions->input[1].deviceType, sizeof(mOptions->input[1].deviceType), 1);
SDL_RWwrite(file, &mOptions->filter, sizeof(mOptions->filter), 1);
SDL_RWwrite(file, &mOptions->vSync, sizeof(mOptions->vSync), 1);
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
SDL_RWwrite(file, &mOptions->screenWidth, sizeof(mOptions->screenWidth), 1);
SDL_RWwrite(file, &mOptions->screenHeight, sizeof(mOptions->screenHeight), 1);
SDL_RWwrite(file, &mOptions->integerScale, sizeof(mOptions->integerScale), 1);
printf("Writing file %s\n", filename.c_str());

View File

@@ -10,25 +10,34 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, int screenWidth, int
mScreenWidth = screenWidth;
mScreenHeight = screenHeight;
mGameCanvasWidth = SCREEN_WIDTH;
mGameCanvasWidth = SCREEN_WIDTH;
mGameCanvasHeight = SCREEN_HEIGHT;
mGameCanvasPosX = (mScreenWidth - mGameCanvasWidth) / 2;
mGameCanvasPosY = (mScreenHeight - mGameCanvasHeight) / 2;
mDest.x = (mScreenWidth - mGameCanvasWidth) / 2;
mDest.y = (mScreenHeight - mGameCanvasHeight) / 2;
mIntegerScale = integerScale;
//mIntegerScale = true;
// Calcula el tamaño de la escala máxima
mScale = 0;
int width = mGameCanvasWidth;
int height = mGameCanvasHeight;
while (((width * (mScale + 1)) < mScreenWidth) && ((height * (mScale + 1)) < mScreenHeight))
int scale = 0;
while (((mGameCanvasWidth * (scale + 1)) <= mScreenWidth) && ((mGameCanvasHeight * (scale + 1)) <= mScreenHeight))
{
mScale++;
scale++;
}
width = width * mScale;
height = height * mScale;
mGameCanvasPosX = (mScreenWidth - width) / 2;
mGameCanvasPosY = (mScreenHeight - height) / 2;
if (mIntegerScale)
{
mDest.w = mGameCanvasWidth * scale;
mDest.h = mGameCanvasHeight * scale;
mDest.x = (mScreenWidth - mGameCanvasWidth) / 2;
mDest.y = (mScreenHeight - mGameCanvasHeight) / 2;
}
else
{
mDest.w = mScreenWidth;
mDest.h = mScreenHeight;
mDest.x = mDest.y = 0;
}
mBorderColor = {0x27, 0x27, 0x36};
mBorderColor = {0x00, 0x00, 0x00};
@@ -68,11 +77,8 @@ void Screen::blit()
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
SDL_RenderClear(mRenderer);
// Rectangulo de destino donde se dibujarà la textura con el juego
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth*mScale, mGameCanvasHeight*mScale};
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &mDest);
// Muestra por pantalla el renderizador
SDL_RenderPresent(mRenderer);

View File

@@ -17,12 +17,9 @@ private:
int mScreenHeight; // Alto de la pantalla
int mGameCanvasWidth; // Ancho de la textura donde se dibuja el juego
int mGameCanvasHeight; // Alto de la textura donde se dibuja el juego
int mGameCanvasPosX; // Posicion en el eje X donde se dibujará la textura del juego dentro de la pantalla
int mGameCanvasPosY; // Posicion en el eje Y donde se dibujará la textura del juego dentro de la pantalla
bool mIntegerScale; // Indica si la textura se escala en multiplos enteros
Uint8 mScale; // Contiene el valor por el cual se multiplica el GameCanvas para aprovechar el maximo de pantalla
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
SDL_Rect mDest; // Coordenadas donde se va a dibujar la textura del juego
color_t mBorderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
public:
// Constructor