mirror of
https://github.com/espressif/esp32-doom.git
synced 2026-02-20 01:51:20 +01:00
250 lines
5.7 KiB
C
250 lines
5.7 KiB
C
/* Emacs style mode select -*- C++ -*-
|
|
*-----------------------------------------------------------------------------
|
|
*
|
|
*
|
|
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
|
|
* based on BOOM, a modified and improved DOOM engine
|
|
* Copyright (C) 1999 by
|
|
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
|
|
* Copyright (C) 1999-2006 by
|
|
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
|
|
* Copyright 2005, 2006 by
|
|
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
* 02111-1307, USA.
|
|
*
|
|
* DESCRIPTION:
|
|
* DOOM graphics stuff for SDL
|
|
*
|
|
*-----------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "config.h"
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include "m_argv.h"
|
|
#include "doomstat.h"
|
|
#include "doomdef.h"
|
|
#include "doomtype.h"
|
|
#include "v_video.h"
|
|
#include "r_draw.h"
|
|
#include "d_main.h"
|
|
#include "d_event.h"
|
|
#include "i_joy.h"
|
|
#include "i_video.h"
|
|
#include "z_zone.h"
|
|
#include "s_sound.h"
|
|
#include "sounds.h"
|
|
#include "w_wad.h"
|
|
#include "st_stuff.h"
|
|
#include "lprintf.h"
|
|
|
|
int use_fullscreen=0;
|
|
int use_doublebuffer=0;
|
|
|
|
|
|
void I_StartTic (void)
|
|
{
|
|
}
|
|
|
|
void I_StartFrame (void)
|
|
{
|
|
}
|
|
|
|
static void I_InitInputs(void)
|
|
{
|
|
}
|
|
|
|
|
|
static void I_UploadNewPalette(int pal)
|
|
{
|
|
#if 0
|
|
// This is used to replace the current 256 colour cmap with a new one
|
|
// Used by 256 colour PseudoColor modes
|
|
|
|
// Array of SDL_Color structs used for setting the 256-colour palette
|
|
static SDL_Color* colours;
|
|
static int cachedgamma;
|
|
static size_t num_pals;
|
|
|
|
if (V_GetMode() == VID_MODEGL)
|
|
return;
|
|
|
|
if ((colours == NULL) || (cachedgamma != usegamma)) {
|
|
int pplump = W_GetNumForName("PLAYPAL");
|
|
int gtlump = (W_CheckNumForName)("GAMMATBL",ns_prboom);
|
|
register const byte * palette = W_CacheLumpNum(pplump);
|
|
register const byte * const gtable = (const byte *)W_CacheLumpNum(gtlump) + 256*(cachedgamma = usegamma);
|
|
register int i;
|
|
|
|
num_pals = W_LumpLength(pplump) / (3*256);
|
|
num_pals *= 256;
|
|
|
|
if (!colours) {
|
|
// First call - allocate and prepare colour array
|
|
colours = malloc(sizeof(*colours)*num_pals);
|
|
}
|
|
|
|
// set the colormap entries
|
|
for (i=0 ; (size_t)i<num_pals ; i++) {
|
|
colours[i].r = gtable[palette[0]];
|
|
colours[i].g = gtable[palette[1]];
|
|
colours[i].b = gtable[palette[2]];
|
|
palette += 3;
|
|
}
|
|
|
|
W_UnlockLumpNum(pplump);
|
|
W_UnlockLumpNum(gtlump);
|
|
num_pals/=256;
|
|
}
|
|
|
|
#endif
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
// Graphics API
|
|
|
|
void I_ShutdownGraphics(void)
|
|
{
|
|
}
|
|
|
|
//
|
|
// I_UpdateNoBlit
|
|
//
|
|
void I_UpdateNoBlit (void)
|
|
{
|
|
}
|
|
|
|
//
|
|
// I_FinishUpdate
|
|
//
|
|
static int newpal = 0;
|
|
|
|
void I_FinishUpdate (void)
|
|
{
|
|
#if 0
|
|
if (SDL_MUSTLOCK(screen)) {
|
|
int h;
|
|
byte *src;
|
|
byte *dest;
|
|
|
|
if (SDL_LockSurface(screen) < 0) {
|
|
lprintf(LO_INFO,"I_FinishUpdate: %s\n", SDL_GetError());
|
|
return;
|
|
}
|
|
dest=screen->pixels;
|
|
src=screens[0].data;
|
|
h=screen->h;
|
|
for (; h>0; h--)
|
|
{
|
|
memcpy(dest,src,SCREENWIDTH*V_GetPixelDepth());
|
|
dest+=screen->pitch;
|
|
src+=screens[0].byte_pitch;
|
|
}
|
|
SDL_UnlockSurface(screen);
|
|
}
|
|
/* Update the display buffer (flipping video pages if supported)
|
|
* If we need to change palette, that implicitely does a flip */
|
|
if (newpal != NO_PALETTE_CHANGE) {
|
|
I_UploadNewPalette(newpal);
|
|
newpal = NO_PALETTE_CHANGE;
|
|
}
|
|
SDL_Flip(screen);
|
|
#endif
|
|
}
|
|
|
|
void I_SetPalette (int pal)
|
|
{
|
|
newpal = pal;
|
|
}
|
|
|
|
void I_PreInitGraphics(void)
|
|
{
|
|
}
|
|
|
|
|
|
// CPhipps -
|
|
// I_SetRes
|
|
// Sets the screen resolution
|
|
void I_SetRes(void)
|
|
{
|
|
int i;
|
|
|
|
I_CalculateRes(SCREENWIDTH, SCREENHEIGHT);
|
|
|
|
// set first three to standard values
|
|
for (i=0; i<3; i++) {
|
|
screens[i].width = SCREENWIDTH;
|
|
screens[i].height = SCREENHEIGHT;
|
|
screens[i].byte_pitch = SCREENPITCH;
|
|
screens[i].short_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE16);
|
|
screens[i].int_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE32);
|
|
}
|
|
|
|
// statusbar
|
|
screens[4].width = SCREENWIDTH;
|
|
screens[4].height = (ST_SCALED_HEIGHT+1);
|
|
screens[4].byte_pitch = SCREENPITCH;
|
|
screens[4].short_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE16);
|
|
screens[4].int_pitch = SCREENPITCH / V_GetModePixelDepth(VID_MODE32);
|
|
|
|
lprintf(LO_INFO,"I_SetRes: Using resolution %dx%d\n", SCREENWIDTH, SCREENHEIGHT);
|
|
}
|
|
|
|
void I_InitGraphics(void)
|
|
{
|
|
char titlebuffer[2048];
|
|
static int firsttime=1;
|
|
|
|
if (firsttime)
|
|
{
|
|
firsttime = 0;
|
|
|
|
atexit(I_ShutdownGraphics);
|
|
lprintf(LO_INFO, "I_InitGraphics: %dx%d\n", SCREENWIDTH, SCREENHEIGHT);
|
|
|
|
/* Set the video mode */
|
|
I_UpdateVideoMode();
|
|
|
|
/* Initialize the input system */
|
|
I_InitInputs();
|
|
}
|
|
}
|
|
|
|
|
|
void I_UpdateVideoMode(void)
|
|
{
|
|
int init_flags;
|
|
int i;
|
|
video_mode_t mode;
|
|
|
|
lprintf(LO_INFO, "I_UpdateVideoMode: %dx%d (%s)\n", SCREENWIDTH, SCREENHEIGHT, desired_fullscreen ? "fullscreen" : "nofullscreen");
|
|
|
|
mode = VID_MODE16;
|
|
// mode = VID_MODE8;
|
|
|
|
V_InitMode(mode);
|
|
V_DestroyUnusedTrueColorPalettes();
|
|
V_FreeScreens();
|
|
|
|
I_SetRes();
|
|
|
|
V_AllocScreens();
|
|
|
|
R_InitBuffer(SCREENWIDTH, SCREENHEIGHT);
|
|
|
|
}
|