diff --git a/src/sdl/main.c b/src/sdl/main.c
index 3aaad80c00583e818a1401faae5c9793107c6f4a..2cc83f6409b848e56fc3d92ee72ed87142dbc610 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <SDL.h>
-#include <stdlib.h> // srand
+#include "SDL.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h> // srand exit
#include <string.h> // strcasecmp
#include <string.h> // strcasecmp
+#include <assert.h>
+#include "system.h"
#include "input.h"
#include "my.h" // fexists
#include "player.h" // pl1 pl2
#include "input.h"
#include "my.h" // fexists
#include "player.h" // pl1 pl2
-#include "menu.h" // GM_init G_keyf
+#include "menu.h" // G_keyf
#include "error.h" // logo
#include "files.h" // F_startup F_addwad F_initwads F_allocres
#include "error.h" // logo
#include "files.h" // F_startup F_addwad F_initwads F_allocres
-#include "config.h" // CFG_args CFG_load
+#include "config.h" // CFG_args CFG_load CFG_save
#include "memory.h" // M_startup
#include "memory.h" // M_startup
-#include "game.h" // G_Init G_act
+#include "game.h" // G_init G_act
#include "sound.h" // S_init S_done
#include "music.h" // S_initmusic S_updatemusic S_donemusic
#include "render.h" // R_init R_draw R_done
#include "sound.h" // S_init S_done
#include "music.h" // S_initmusic S_updatemusic S_donemusic
#include "render.h" // R_init R_draw R_done
+#define MODE_NONE 0
+#define MODE_OPENGL 1
+#define MODE_SOFTWARE 2
+
static int quit = 0;
static int quit = 0;
+static SDL_Surface *surf = NULL;
+static int mode = MODE_NONE;
+
+/* --- error.h --- */
+
+void logo (const char *s, ...) {
+ va_list ap;
+ va_start(ap, s);
+ vprintf(s, ap);
+ va_end(ap);
+ fflush(stdout);
+}
+
+void logo_gas (int cur, int all) {
+ // stub
+}
+
+void ERR_failinit (char *s, ...) {
+ va_list ap;
+ va_start(ap, s);
+ vprintf(s, ap);
+ va_end(ap);
+ puts("");
+ exit(1);
+}
+
+void ERR_fatal (char *s, ...) {
+ va_list ap;
+ R_done();
+ S_done();
+ S_donemusic();
+ M_shutdown();
+ SDL_Quit();
+ puts("\nКРИТИЧЕСКАЯ ОШИБКА:");
+ va_start(ap, s);
+ vprintf(s, ap);
+ va_end(ap);
+ puts("");
+ exit(1);
+}
+
+void ERR_quit (void) {
+ puts("Спасибо за то, что вы играли в Операцию \"Смятка\"!");
+ //F_loadres(F_getresid("ENDOOM"),p,0,4000);
+ quit = 1;
+}
+
+/* --- system.h --- */
+
+int Y_set_videomode_opengl (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ Uint32 flags;
+ SDL_Surface *s;
+ if (mode == MODE_OPENGL && surf->w == w && surf->h == h && Y_get_fullscreen() == fullscreen) {
+ s = surf;
+ } else {
+ flags = SDL_DOUBLEBUF | SDL_OPENGL;
+ if (fullscreen) {
+ flags = flags | SDL_FULLSCREEN;
+ }
+# ifdef WIN32
+ flags = flags | SDL_RESIZABLE;
+# endif
+ s = SDL_SetVideoMode(w, h, 0, flags);
+ if (s != NULL) {
+ mode = MODE_OPENGL;
+ surf = s;
+ }
+ }
+ return s != NULL;
+}
+
+int Y_set_videomode_software (int w, int h, int fullscreen) {
+ assert(w > 0);
+ assert(h > 0);
+ Uint32 flags;
+ SDL_Surface *s;
+ if (mode == MODE_OPENGL && surf->w == w && surf->h == h && Y_get_fullscreen() == fullscreen) {
+ s = surf;
+ } else {
+ flags = SDL_DOUBLEBUF | SDL_SWSURFACE | SDL_HWPALETTE;
+ if (fullscreen) {
+ flags = flags | SDL_FULLSCREEN;
+ }
+# ifdef WIN32
+ flags = flags | SDL_RESIZABLE;
+# endif
+ s = SDL_SetVideoMode(w, h, 8, flags);
+ if (s != NULL) {
+ mode = MODE_SOFTWARE;
+ surf = s;
+ }
+ }
+ return s != NULL;
+}
+
+void Y_get_videomode (int *w, int *h) {
+ if (mode != MODE_NONE) {
+ *w = surf->w;
+ *h = surf->h;
+ } else {
+ *w = 0;
+ *h = 0;
+ }
+}
+
+int Y_videomode_setted (void) {
+ return mode != MODE_NONE;
+}
+
+void Y_unset_videomode (void) {
+ surf = NULL;
+ mode = MODE_NONE;
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ SDL_InitSubSystem(SDL_INIT_VIDEO);
+}
+
+void Y_set_fullscreen (int fullscreen) {
+ int fs = Y_get_fullscreen();
+ if (mode != MODE_NONE && fs != fullscreen) {
+ if (SDL_WM_ToggleFullScreen(surf) == 0) {
+ switch (mode) {
+ case MODE_OPENGL:
+ Y_set_videomode_opengl(surf->w, surf->h, fullscreen);
+ break;
+ case MODE_SOFTWARE:
+ Y_set_videomode_software(surf->w, surf->h, fullscreen);
+ break;
+ }
+ }
+ }
+}
+
+int Y_get_fullscreen (void) {
+ return (mode != MODE_NONE) && ((surf->flags & SDL_FULLSCREEN) != 0);
+}
+
+void Y_swap_buffers (void) {
+ assert(mode == MODE_OPENGL);
+ SDL_GL_SwapBuffers();
+}
+
+void Y_get_buffer (byte **buf, int *w, int *h, int *pitch) {
+ assert(mode == MODE_SOFTWARE);
+ *buf = surf->pixels;
+ *w = surf->w;
+ *h = surf->h;
+ *pitch = surf->pitch;
+}
+
+void Y_set_vga_palette (byte *vgapal) {
+ int i;
+ byte *p = vgapal;
+ assert(vgapal != NULL);
+ assert(mode == MODE_SOFTWARE);
+ SDL_Color colors[256];
+ for (i = 0; i < 256; i++) {
+ colors[i] = (SDL_Color) {
+ .r = p[0] * 255 / 63,
+ .g = p[1] * 255 / 63,
+ .b = p[2] * 255 / 63
+ };
+ p += 3;
+ }
+ SDL_SetColors(surf, colors, 0, 256);
+}
+
+void Y_repaint_rect (int x, int y, int w, int h) {
+ assert(mode == MODE_SOFTWARE);
+ SDL_UpdateRect(surf, x, y, w, h);
+}
+
+void Y_repaint (void) {
+ assert(mode == MODE_SOFTWARE);
+ SDL_Flip(surf);
+}
+
+/* --- main --- */
static int sdl_to_key (int code) {
switch (code) {
static int sdl_to_key (int code) {
switch (code) {
case SDL_QUIT:
ERR_quit();
break;
case SDL_QUIT:
ERR_quit();
break;
+ case SDL_VIDEORESIZE:
+ R_set_videomode(ev.resize.w, ev.resize.h, Y_get_fullscreen());
+ break;
case SDL_KEYDOWN:
case SDL_KEYUP:
key = sdl_to_key(ev.key.keysym.sym);
case SDL_KEYDOWN:
case SDL_KEYUP:
key = sdl_to_key(ev.key.keysym.sym);
}
}
}
}
-int SDL_main (int argc, char *argv[]) {
+int main (int argc, char *argv[]) {
char *pw;
Uint32 t, ticks;
logo("main: initialize SDL\n");
char *pw;
Uint32 t, ticks;
logo("main: initialize SDL\n");
return 1;
}
SDL_WM_SetCaption("Doom 2D v1.351", "Doom 2D");
return 1;
}
SDL_WM_SetCaption("Doom 2D v1.351", "Doom 2D");
- pl1.id = -1; // TODO move to generic code
- pl2.id = -2; // TODO move to generic code
// Player 1 defaults
pl1.ku = KEY_KP_8;
pl1.kd = KEY_KP_5;
// Player 1 defaults
pl1.ku = KEY_KP_8;
pl1.kd = KEY_KP_5;
F_initwads();
M_startup();
F_allocres();
F_initwads();
M_startup();
F_allocres();
- G_init();
S_init();
S_initmusic();
R_init();
S_init();
S_initmusic();
R_init();
- GM_init(); // TODO move to game
- F_loadmus("MENU"); // TODO move to menu
- S_startmusic(0); // TODO move to menu
+ G_init();
ticks = SDL_GetTicks();
while (!quit) {
poll_events(&G_keyf);
ticks = SDL_GetTicks();
while (!quit) {
poll_events(&G_keyf);
}
R_draw();
}
}
R_draw();
}
+ CFG_save();
R_done();
S_donemusic();
S_done();
R_done();
S_donemusic();
S_done();