Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions prboom2/src/SDL/i_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ static void I_Quit (void)
{
M_SaveDefaults ();
dsda_DumpEndoom();
dsda_Shutdown();
}

//
Expand Down Expand Up @@ -318,7 +317,7 @@ int main(int argc, char **argv)
*/

I_AtExit(I_EssentialQuit, true, "I_EssentialQuit", exit_priority_first);
I_AtExit(I_Quit, false, "I_Quit", exit_priority_last);
I_AtExit(I_Quit, false, "I_Quit", exit_priority_quit);
#ifndef PRBOOM_DEBUG
if (!dsda_Flag(dsda_arg_sigsegv))
{
Expand Down
10 changes: 4 additions & 6 deletions prboom2/src/SDL/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,10 @@ static void I_ShutdownSDL(void)
return;
}

void dsda_Shutdown(void)
{
I_AtExit(I_ShutdownSDL, true, "I_ShutdownSDL", exit_priority_normal);
}

void I_PreInitGraphics(void)
{
int p;
dboolean endoom_export;

// Initialize SDL
unsigned int flags = 0;
Expand All @@ -717,7 +713,9 @@ void I_PreInitGraphics(void)
I_Error("Could not initialize SDL [%s]", SDL_GetError());
}

// No longer call `I_ShutdownSDL()` here cuz we need window/renderer info for ENDOOM later on
endoom_export = dsda_IntConfig(dsda_config_export_endoom);

I_AtExit(I_ShutdownSDL, true, "I_ShutdownSDL", endoom_export ? exit_priority_normal : exit_priority_last);
}

// e6y: resolution limitation is removed
Expand Down
1 change: 1 addition & 0 deletions prboom2/src/i_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ typedef enum
{
exit_priority_first,
exit_priority_normal,
exit_priority_quit,
exit_priority_last,
exit_priority_max,
} exit_priority_t;
Expand Down
1 change: 0 additions & 1 deletion prboom2/src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void I_ShutdownGraphics(void);

void *I_GetSDLWindow(void);
void *I_GetSDLRenderer(void);
void dsda_Shutdown(void);

/* Takes full 8 bit values. */
void I_SetPalette(int pal); /* CPhipps - pass down palette number */
Expand Down
60 changes: 50 additions & 10 deletions prboom2/src/textscreen/txt_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static int is_opengl = false;
#define SCREEN_ROWS 25

static GLuint gl_texture = 0;
static GLubyte *gl_texture_data;
static int glwindow_w = 0;
static int glwindow_h = 0;

Expand Down Expand Up @@ -206,12 +207,23 @@ int TXT_Init(void)
void TXT_Shutdown(void)
{
if (is_opengl)
{
if (gl_texture != 0)
{
glDeleteTextures(1, &gl_texture);
gl_texture = 0;
}

free(gl_texture_data);
gl_texture_data = NULL;
}

if (texture_upscaled != NULL)
{
SDL_DestroyTexture(texture_upscaled);
texture_upscaled = NULL;
}

free(screendata);
screendata = NULL;
SDL_FreeSurface(screenbuffer);
Expand Down Expand Up @@ -341,6 +353,12 @@ void TXT_UpdateScreenArea(int x, int y, int w, int h)
// the screen; find a more efficient way to do it.
screentx = SDL_CreateTextureFromSurface(renderer, screenbuffer);

if (screentx == NULL)
{
lprintf(LO_ERROR, "Failed to create text screen texture: %s\n", SDL_GetError());
return;
}

SDL_RenderClear(renderer);
GetDestRect(&rect);

Expand Down Expand Up @@ -450,15 +468,13 @@ int GL_TXT_Init(void)

void GL_TXT_UpdateScreen(void)
{
static GLubyte *texture_data;
int tex_w, tex_h, tex_w2, tex_h2;

glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);

SDL_LockSurface(screenbuffer);

texture_data = NULL;
tex_w = TXT_SCREEN_W * FONT_CHAR_W;
tex_h = TXT_SCREEN_H * FONT_CHAR_H;

Expand All @@ -467,8 +483,8 @@ void GL_TXT_UpdateScreen(void)
tex_w2 = tex_w * 2;
tex_h2 = tex_h * 2;

if (!texture_data)
texture_data = malloc(tex_w2 * tex_h2 * 4);
if (!gl_texture_data)
gl_texture_data = malloc(tex_w2 * tex_h2 * 4);

for (int y = 0; y < TXT_SCREEN_H; y++) {
for (int x = 0; x < TXT_SCREEN_W; x++) {
Expand Down Expand Up @@ -513,10 +529,10 @@ void GL_TXT_UpdateScreen(void)
for (int dx = 0; dx < 2; dx++)
{
int idx = ((dst_y + dy) * tex_w2 + (dst_x + dx)) * 4;
texture_data[idx + 0] = r;
texture_data[idx + 1] = g;
texture_data[idx + 2] = b;
texture_data[idx + 3] = 255;
gl_texture_data[idx + 0] = r;
gl_texture_data[idx + 1] = g;
gl_texture_data[idx + 2] = b;
gl_texture_data[idx + 3] = 255;
}
}
}
Expand All @@ -532,12 +548,12 @@ void GL_TXT_UpdateScreen(void)
glBindTexture(GL_TEXTURE_2D, gl_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_w2, tex_h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_w2, tex_h2, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl_texture_data);
}
else
{
glBindTexture(GL_TEXTURE_2D, gl_texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex_w2, tex_h2, GL_RGBA, GL_UNSIGNED_BYTE, texture_data);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex_w2, tex_h2, GL_RGBA, GL_UNSIGNED_BYTE, gl_texture_data);
}

// Draw 2x texture (image) normal size in window
Expand Down Expand Up @@ -775,6 +791,30 @@ signed int TXT_GetChar(void)
}
break;

case SDL_CONTROLLERBUTTONDOWN:
switch (ev.cbutton.button)
{
case SDL_CONTROLLER_BUTTON_A:
case SDL_CONTROLLER_BUTTON_START:
return KEY_ENTER;

case SDL_CONTROLLER_BUTTON_B:
return 27;

case SDL_CONTROLLER_BUTTON_DPAD_UP:
return KEY_UPARROW;

case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
return KEY_DOWNARROW;

case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
return KEY_LEFTARROW;

case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
return KEY_RIGHTARROW;
}
break;

case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
SDL_PushEvent(&ev);
Expand Down
Loading