summaryrefslogtreecommitdiff
path: root/src/main-sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main-sdl.c')
-rw-r--r--src/main-sdl.c238
1 files changed, 49 insertions, 189 deletions
diff --git a/src/main-sdl.c b/src/main-sdl.c
index 1b53cfc7..e9aec927 100644
--- a/src/main-sdl.c
+++ b/src/main-sdl.c
@@ -23,25 +23,34 @@
// in this Software without prior written authorization from the author(s).
*/
-#ifdef USE_SDL
+#include "loadsave.h"
+#include "main.h"
+#include "util.h"
+#include "variable.h"
-#include "angband.h"
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
+#include <assert.h>
#include <math.h>
/*************************************************
GLOBAL SDL-ToME PROPERTIES
*************************************************/
+
+/* Default window properties - used if none are available
+from other places*/
+#define DEF_SCREEN_WIDTH 800
+#define DEF_SCREEN_HEIGHT 600
+#define DEF_SCREEN_BPP 16
/*Main window properties that may be loaded at runtime from
a preference file or environmental variables. However,
default values (defined above) can be used. */
-static int arg_width = 0;
-static int arg_height = 0;
-static int arg_bpp = 16;
+static int arg_width = DEF_SCREEN_WIDTH;
+static int arg_height = DEF_SCREEN_HEIGHT;
+static int arg_bpp = DEF_SCREEN_BPP;
/**************/
@@ -58,21 +67,6 @@ static char arg_font_name[64] = DEF_FONT_FILE;
/**************/
-/* Graphics setting - signifies what graphics to use. Valid ints
-are available with given defines */
-
-/* No graphics - use only colored text */
-#define NO_GRAPHICS 0
-/* "Old" graphics - use 8x8.bmp to extract graphics tiles */
-#define GRAPHICS_8x8 8
-/* "New" graphics - use 16x16.bmp as tiles and apply mask.bmp for transparency*/
-#define GRAPHICS_16x16 16
-
-static int arg_graphics_type = NO_GRAPHICS;
-
-
-/**************/
-
/* The number of term_data structures to set aside mem for */
#define MAX_CONSOLE_COUNT 8
@@ -89,10 +83,6 @@ border */
/**************/
-/* some miscellaneous settings which have not been dealt
-with yet */
-static bool_ arg_double_width = FALSE;
-
/* flag signifying whether the game is in full screen */
static bool_ arg_full_screen = FALSE;
@@ -109,7 +99,7 @@ static bool_ window_properties_set = FALSE;
static SDL_Surface *screen;
/* the video settings for the system */
-static SDL_VideoInfo *videoInfo;
+static const SDL_VideoInfo *videoInfo;
/* a flag to suspend updating of the screen;
this is in place so that when a large area is being
@@ -502,9 +492,7 @@ void handleEvent(SDL_Event *event)
/* handle quit requests */
DB("Emergency Blit");
redrawAllTerminals();
- save_player();
- save_dungeon();
- sdl_quit("Quitting!\n");
+ /*sdl_quit("Quitting!\n");*/
break;
}
default:
@@ -577,23 +565,6 @@ static errr Term_xtra_sdl(int n, int v)
return (0);
}
- case TERM_XTRA_FROSH:
- {
- /*
- * Flush a row of output XXX XXX XXX
- *
- * This action should make sure that row "v" of the "output"
- * to the window will actually appear on the window.
- *
- * This action is optional, assuming that "Term_text_xxx()"
- * (and similar functions) draw directly to the screen, or
- * that the "TERM_XTRA_FRESH" entry below takes care of any
- * necessary flushing issues.
- */
-
- return (1);
- }
-
case TERM_XTRA_FRESH:
{
/*
@@ -603,9 +574,7 @@ static errr Term_xtra_sdl(int n, int v)
* window will actually appear on the window.
*
* This action is optional, assuming that "Term_text_xxx()"
- * (and similar functions) draw directly to the screen, or
- * that the "TERM_XTRA_FROSH" entry above takes care of any
- * necessary flushing issues.
+ * (and similar functions) draw directly to the screen.
*/
/* If terminal display has been held for any reason,
@@ -634,21 +603,6 @@ static errr Term_xtra_sdl(int n, int v)
return (1);
}
- case TERM_XTRA_SOUND:
- {
- /*
- * Make a sound XXX XXX XXX
- *
- * This action should produce sound number "v", where the
- * "name" of that sound is "sound_names[v]". This method
- * is still under construction.
- *
- * This action is optional, and not very important.
- */
-
- return (1);
- }
-
case TERM_XTRA_BORED:
{
/* Perform event checking without blocking */
@@ -714,40 +668,6 @@ static errr Term_xtra_sdl(int n, int v)
return (1);
}
- case TERM_XTRA_DELAY:
- {
- /*
- * Delay for some milliseconds XXX XXX XXX
- *
- * This action is useful for proper "timing" of certain
- * visual effects, such as breath attacks.
- *
- * This action is optional, but may be required by this file,
- * especially if special "macro sequences" must be supported.
- */
-
- /* I think that this command is system independent... */
- /*sleep(v/1000);*/
- /* main-x11 uses usleep(1000*v); */
- /* main-win uses Sleep(v); */
- return (1);
- }
-
- case TERM_XTRA_GET_DELAY:
- {
- /*
- * Get Delay of some milliseconds XXX XXX XXX
- * place the result in Term_xtra_long
- *
- * This action is useful for proper "timing" of certain
- * visual effects, such as recording cmovies.
- *
- * This action is optional, but cmovies wont perform
- * good without it
- */
-
- return (1);
- }
}
/* Unknown or Unhandled action */
@@ -1049,33 +969,6 @@ static errr Term_curs_sdl(int x, int y)
return (0);
}
-/* routine for wiping terminal locations - simply draws
-a black rectangle over the offending spots! */
-static errr Term_wipe_sdl(int x, int y, int n)
-{
- static SDL_Rect base;
- term_data *td = (term_data*)(Term->data);
-
- /* calculate boundaries of the area to clear */
- base.x = td->surf->clip_rect.x + x*t_width;
- base.y = td->surf->clip_rect.y + y*t_height;
- base.w = n*t_width;
- base.h = t_height;
-
- SDL_LOCK(td->surf);
-
- /* blank the screen area */
- SDL_FillRect(td->surf, &base, td->black);
-
- SDL_UNLOCK(td->surf);
-
- /* And... UPDATE the rectangle we just wrote to! */
- drawTermStuff(td,&base);
-
- /* Success */
- return (0);
-}
-
/* Perform a full clear of active terminal; redraw the borders.*/
void eraseTerminal(void)
{
@@ -1140,9 +1033,6 @@ void eraseTerminal(void)
* which is not black, then this function must be able to draw
* the resulting "blank" correctly.
*
- * Note that this function must correctly handle "black" text if
- * the "always_text" flag is set, if this flag is not set, all the
- * "black" text will be handled by the "Term_wipe_xxx()" hook.
*/
static errr Term_text_sdl(int x, int y, int n, byte a, const char *cp)
{
@@ -1186,7 +1076,8 @@ static errr Term_text_sdl(int x, int y, int n, byte a, const char *cp)
SDL_BlitSurface(worksurf,NULL,td->surf,&base);
} else {
/* copy the desired character onto working surface */
- SDL_BlitSurface(text[*cp],NULL,worksurf,NULL);
+ assert(*cp >= 0); // Make sure cast is valid
+ SDL_BlitSurface(text[(size_t)(*cp)],NULL,worksurf,NULL);
/* color our crayon surface with the desired color */
SDL_FillRect(crayon,NULL,color_data[a&0x0f]);
/* apply the color to the character on the working surface */
@@ -1376,7 +1267,6 @@ void moveTerminal(int x, int y)
void bringToTop(int current)
{
term_data *td;
- term_data *tc;
int n = 0;
int i;
@@ -1551,8 +1441,7 @@ void manipulationMode(void)
int mouse_x, mouse_y;
int value = 0, delta_x = 0, delta_y = 0;
int current_term;
- SDL_Surface backup;
-
+
/* Begin by redrawing the main terminal with its
purple border to signify that it is being edited*/
@@ -1844,19 +1733,9 @@ static errr term_data_init(term_data *td, int i)
/* Use a "soft" cursor */
t->soft_cursor = TRUE;
- /* Picture routine flags */
- t->always_pict = FALSE;
- t->higher_pict = FALSE;
- t->always_text = FALSE;
-
- /* Erase with "white space" */
- t->attr_blank = TERM_WHITE;
- t->char_blank = ' ';
-
/* Hooks */
t->xtra_hook = Term_xtra_sdl;
t->curs_hook = Term_curs_sdl;
- t->wipe_hook = Term_wipe_sdl;
t->text_hook = Term_text_sdl;
/* Save the data */
@@ -1944,9 +1823,9 @@ void dumpWindowSettings(void)
/* The main-sdl initialization routine!
This routine processes arguments, opens the SDL
window, loads fonts, etc. */
-errr init_sdl(int argc, char **argv)
+int init_sdl(int argc, char **argv)
{
- int i, surface_type;
+ int i;
char filename[PATH_MAX + 1];
const char file_sep = '.';
/* Flags to pass to SDL_SetVideoMode */
@@ -2049,25 +1928,6 @@ errr init_sdl(int argc, char **argv)
return -1;
}
}
- /* see if new graphics are requested...*/
- else if (0 == strcmp(argv[i], "-g"))
- {
- printf("New graphics (16x16) enabled!\n");
- arg_graphics_type = GRAPHICS_16x16;
- }
- /* see if old graphics are requested...*/
- else if (0 == strcmp(argv[i], "-o"))
- {
- printf("Old graphics (8x8) enabled!\n");
- arg_graphics_type = GRAPHICS_8x8;
- }
-
- /* see if double width tiles are requested */
- else if (0 == strcmp(argv[i], "-b"))
- {
- /* do nothing for now */
- /* arg_double_width = TRUE; */
- }
/* switch into full-screen at startup */
else if (0 == strcmp(argv[i], "-fs"))
{
@@ -2133,26 +1993,6 @@ errr init_sdl(int argc, char **argv)
else
videoFlags = SDL_SWSURFACE;
- /* Now ready the fonts! */
-
- DB("initializing SDL_ttf");
- if(TTF_Init()==-1) {
- printf("TTF_Init: %s\n", TTF_GetError());
- sdl_quit("Bah");
- }
-
- DB("loading font...");
-
- /* load and render the font */
- loadAndRenderFont(arg_font_name,arg_font_size);
-
- /* Make the window a nice default size if none is specified */
- if (arg_width < 1 || arg_height < 1)
- {
- arg_width = 80 * t_width;
- arg_height = 24 * t_height;
- }
-
/* now set the video mode that has been configured */
screen = SDL_SetVideoMode( arg_width, arg_height, arg_bpp, videoFlags );
@@ -2171,13 +2011,19 @@ errr init_sdl(int argc, char **argv)
DB("SDL Window Created!");
- /* Graphics! ----
- If graphics are selected, then load graphical tiles! */
- if (arg_graphics_type != NO_GRAPHICS)
- {
- /* load graphics tiles */
+ /* Now ready the fonts! */
+
+ DB("initializing SDL_ttf");
+ if(TTF_Init()==-1) {
+ printf("TTF_Init: %s\n", TTF_GetError());
+ sdl_quit("Bah");
}
-
+
+ DB("loading font...");
+
+ /* load and render the font */
+ loadAndRenderFont(arg_font_name,arg_font_size);
+
/* Initialize the working surface and crayon surface used for rendering
text in different colors. */
@@ -2250,4 +2096,18 @@ errr init_sdl(int argc, char **argv)
return 0;
}
-#endif
+int main(int argc, char *argv[])
+{
+ return main_real(
+ argc,
+ argv,
+ "sdl",
+ init_sdl,
+ " -- -n # Number of virtual consoles to use\n"
+ " -- -w # Request screen width in pixels\n"
+ " -- -h # Request screen height in pixels\n"
+ " -- -bpp # Request screen color depth in bits\n"
+ " -- -fs Start with full-screen display\n"
+ " -- -s # Request font size\n"
+ " -- -f <font> Request true-type font by name\n");
+}