X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fsdl%2Fmain.c;h=df880c432e3a2b9cf8e447faf0adfd02e6872082;hb=fcf91b33fd6968628c8f22b1c9af378985ab69a8;hp=3aaad80c00583e818a1401faae5c9793107c6f4a;hpb=de05b18ef2a99168b0a1a8a921a4b18ec7023833;p=flatwaifu.git diff --git a/src/sdl/main.c b/src/sdl/main.c index 3aaad80..df880c4 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -21,24 +21,182 @@ */ #include -#include // srand +#include +#include +#include // srand exit #include // strcasecmp +#include +#include "system.h" #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 "config.h" // CFG_args CFG_load +#include "config.h" // CFG_args CFG_load CFG_save #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 static int quit = 0; +static SDL_Surface *surf = NULL; + +/* --- 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 (int w, int h, int flags) { + SDL_Surface *s; + int colors; + Uint32 f; + assert(w > 0); + assert(h > 0); + f = SDL_DOUBLEBUF; + if (flags & SYSTEM_USE_FULLSCREEN) { + f = flags | SDL_FULLSCREEN; + } + if (flags & SYSTEM_USE_OPENGL) { + f = flags | SDL_OPENGL; + colors = 0; + } else { + f = flags | SDL_SWSURFACE | SDL_HWPALETTE; + colors = 8; + } + s = SDL_SetVideoMode(w, h, colors, f); + if (s != NULL) { + surf = s; + } + return s != NULL; +} + +void Y_get_videomode (int *w, int *h) { + if (surf != NULL) { + *w = surf->w; + *h = surf->h; + } else { + *w = 0; + *h = 0; + } +} + +int Y_videomode_setted (void) { + return surf != NULL; +} + +void Y_unset_videomode (void) { + surf = NULL; + SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_InitSubSystem(SDL_INIT_VIDEO); +} + +void Y_set_fullscreen (int yes) { + assert(surf != NULL); + int flags = 0; + if ((surf->flags & SDL_FULLSCREEN) == 0) { + flags |= SYSTEM_USE_FULLSCREEN; + } + if (surf->flags & SDL_OPENGL) { + flags |= SDL_OPENGL; + } + Y_set_videomode(surf->w, surf->h, flags); +} + +int Y_get_fullscreen (void) { + return (surf != NULL) && ((surf->flags & SDL_FULLSCREEN) != 0); +} + +void Y_swap_buffers (void) { + assert(surf != NULL); + assert(surf->flags & SDL_OPENGL); + SDL_GL_SwapBuffers(); +} + +void Y_get_buffer (byte **buf, int *w, int *h, int *pitch) { + assert(surf != NULL); + assert((surf->flags & SDL_OPENGL) == 0); + *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(surf != NULL); + assert((surf->flags & SDL_OPENGL) == 0); + 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(surf != NULL); + assert((surf->flags & SDL_OPENGL) == 0); + SDL_UpdateRect(surf, x, y, w, h); +} + +void Y_repaint (void) { + assert(surf != NULL); + assert((surf->flags & SDL_OPENGL) == 0); + SDL_Flip(surf); +} + +/* --- main --- */ static int sdl_to_key (int code) { switch (code) { @@ -170,7 +328,7 @@ static void poll_events (void (*h)(int key, int down)) { } } -int SDL_main (int argc, char *argv[]) { +int main (int argc, char *argv[]) { char *pw; Uint32 t, ticks; logo("main: initialize SDL\n"); @@ -179,8 +337,6 @@ int SDL_main (int argc, char *argv[]) { 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; @@ -218,13 +374,10 @@ int SDL_main (int argc, char *argv[]) { F_initwads(); M_startup(); F_allocres(); - G_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); @@ -236,6 +389,7 @@ int SDL_main (int argc, char *argv[]) { } R_draw(); } + CFG_save(); R_done(); S_donemusic(); S_done();