summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e059193)
raw | patch | inline | side by side (parent: e059193)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 30 Mar 2020 18:03:45 +0000 (22:03 +0400) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 30 Mar 2020 18:03:45 +0000 (22:03 +0400) |
src/gl/render.c | patch | blob | history | |
src/sdl/main.c | patch | blob | history | |
src/soft/render.c | patch | blob | history | |
src/soft/vga.c | patch | blob | history | |
src/soft/vga.h | patch | blob | history |
diff --git a/src/gl/render.c b/src/gl/render.c
index 91707ef5d32d2e7af2209a0a61d8c34d44672bb9..fe0ec3c74e3eb8622d634b8820da497719e65c76 100644 (file)
--- a/src/gl/render.c
+++ b/src/gl/render.c
#include "glob.h"
#include "render.h"
+#include "system.h"
#include "files.h"
#include "memory.h"
#include "misc.h"
#else
# include <GL/gl.h>
#endif
-#include <stdlib.h> // malloc free abs
-#include <assert.h> // assert
-#include <SDL.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
#define VGA_TRANSPARENT_COLOR 0
#define DEFAULT_SKY_COLOR 0x97
int SCRH = 200; // public
static int gamma;
static int fullscreen;
-static SDL_Surface *surf;
static rgb playpal[256];
static byte bright[256];
static GLuint lastTexture;
break;
}
GM_draw();
- SDL_GL_SwapBuffers();
+ Y_swap_buffers();
}
void R_alloc (void) {
}
void R_init (void) {
- Uint32 flags = SDL_OPENGL;
+ int res = 0;
+ int flags = SYSTEM_USE_OPENGL;
if (fullscreen) {
- flags = flags | SDL_FULLSCREEN;
+ flags |= SYSTEM_USE_FULLSCREEN;
}
+ logo("R_init: intialize opengl render\n");
+ int was = Y_videomode_setted();
if (SCRW <= 0 || SCRH <= 0) {
ERR_failinit("Invalid screen size %ix%i\n", SCRW, SCRH);
}
- if (surf == NULL) {
+ if (was == 0) {
R_init_playpal(); // only onece
}
- surf = SDL_SetVideoMode(SCRW, SCRH, 0, flags);
- if (surf == NULL) {
- ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
+ res = Y_set_videomode(SCRW, SCRH, flags);
+ if (res == 0) {
+ ERR_failinit("Unable to set video mode\n");
}
root = R_cache_new();
assert(root);
void R_done (void) {
R_cache_free(root, 1);
+ Y_unset_videomode();
}
void R_setgamma (int g) {
void R_toggle_fullscreen (void) {
fullscreen = !fullscreen;
- if (surf) {
- R_init(); // recreate window
- }
+// if (surf) {
+// R_init(); // recreate window
+// }
}
void R_get_name (int n, char s[8]) {
diff --git a/src/sdl/main.c b/src/sdl/main.c
index 15ce855d35c515b2190655c2d843d170632f1706..5706cc75c95c5d490414e2673a56725522e724e7 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
#include <stdarg.h>
#include <stdlib.h> // srand exit
#include <string.h> // strcasecmp
+#include <assert.h>
+#include "system.h"
#include "input.h"
#include "my.h" // fexists
#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;
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;
+}
+
+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);
+}
+
+int Y_set_fullscreen (int yes) {
+ //SDL_WM_ToggleFullScreen();
+ return 0;
+}
+
+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) {
case SDLK_0: return KEY_0;
diff --git a/src/soft/render.c b/src/soft/render.c
index 2036b083631be16bf6ea778ffd75718b039d7851..224d926f679b30e7ea15c2b331914f6a49f3cff2 100644 (file)
--- a/src/soft/render.c
+++ b/src/soft/render.c
std_pal[t][1]=gamcor[gammaa][main_pal[t][1]];
std_pal[t][2]=gamcor[gammaa][main_pal[t][2]];
}
- VP_setall(std_pal);
+ Y_set_vga_palette(std_pal);
}
int R_getgamma (void) {
diff --git a/src/soft/vga.c b/src/soft/vga.c
index 8347b3ae55c0400becdbd67cb796e6d6b8ad60fe..ef97ca7afa9103bae141e77173ba343e3c84290d 100644 (file)
--- a/src/soft/vga.c
+++ b/src/soft/vga.c
#include "glob.h"
#include "vga.h"
-#include <SDL.h>
#include "error.h"
#include "view.h"
#include "memory.h"
#include "misc.h"
#include "files.h"
+#include "system.h"
+#include <string.h>
#include <assert.h>
-
-// адрес экранного буфера
-//unsigned char *scra;
-
-// виртуальный экран
-//unsigned char scrbuf[64000];
-
int SCRW = 800;
int SCRH = 600;
char fullscreen = OFF;
byte mixmap[256][256];
byte clrmap[256*12];
-static SDL_Surface* screen = NULL;
-static int cx1,cx2,cy1,cy2;
+static byte *buffer;
+static int buf_w, buf_h, pitch;
+static int offx, offy;
+static int cx1, cx2, cy1, cy2;
static byte flametab[16] = {
0xBC,0xBA,0xB8,0xB6,0xB4,0xB2,0xB0,0xD5,0xD6,0xD7,0xA1,0xA0,0xE3,0xE2,0xE1,0xE0
};
-static int offx = 0;
-static int offy = 0;
-
-#define HQ 2
vgaimg *V_getvgaimg (int id) {
int loaded = M_was_locked(id);
}
short V_init (void) {
- Uint32 flags = SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_HWPALETTE;
- if (fullscreen) flags = flags | SDL_FULLSCREEN;
- screen = SDL_SetVideoMode(SCRW, SCRH, 8, flags);
- if (!screen) ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
- SCRW /= HQ;
- SCRH /= HQ;
- return 0;
+ int flags = fullscreen ? SYSTEM_USE_FULLSCREEN : 0;
+ int res = Y_set_videomode(SCRW, SCRH, flags);
+ if (res == 0) {
+ ERR_failinit("Unable to set video mode");
+ }
+ Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch);
+ return 0;
}
-// переключение в текстовый режим
void V_done (void) {
- SDL_Quit();
+ buffer = NULL;
+ buf_w = 0;
+ buf_h = 0;
+ pitch = 0;
+ Y_unset_videomode();
}
static void draw_rect (int x, int y, int w, int h, int c) {
- SDL_Rect dstrect;
- dstrect.x = x*HQ;
- dstrect.y = y*HQ;
- dstrect.w = w*HQ;
- dstrect.h = h*HQ;
- SDL_FillRect(screen, &dstrect, c);
+ int i;
+ int x0 = max(x, cx1);
+ int y0 = max(y, cy1);
+ int x1 = min(x + w - 1, cx2);
+ int y1 = min(y + h - 1, cy2);
+ int len = x1 - x0;
+ for (i = y0; i <= y1; i++) {
+ memset(&buffer[i * pitch + x0], c, len);
+ }
}
-// установить область вывода
-void V_setrect (short x,short w,short y,short h) {
- SDL_Rect r;
- r.x=x*HQ;
- r.y=y*HQ;
- r.w=w*HQ;
- r.h=h*HQ;
- SDL_SetClipRect(screen, &r);
- SDL_GetClipRect(screen, &r);
- cx1 = x;
- cx2 = x+w-1;
- cy1 = y;
- cy2 = y+h-1;
- if (cx1<0) cx1=0;
- if (cx2>=SCRW) cx2=SCRW-1;
- if (cy1<0) cy1=0;
- if (cy2>=SCRH) cy2=SCRH-1;
+void V_setrect (short x, short w, short y, short h) {
+ cx1 = max(x, 0);
+ cx2 = min(x + w - 1, SCRW - 1);
+ cy1 = max(y, 0);
+ cy2 = min(y + h - 1, SCRH - 1);
}
-static void putpixel (int x, int y, Uint8 color) {
- if(x>=cx1 && x<=cx2 && y>=cy1 && y<=cy2) {
- x*=HQ;
- y*=HQ;
- Uint8 *p = (Uint8 *)screen->pixels + y*screen->pitch + x;
- *p = color;
- *(p+1) = color;
- p += screen->pitch;
- *p = color;
- *(p+1) = color;
- }
+static void putpixel (int x, int y, byte color) {
+ if (x >= cx1 && x <= cx2 && y >= cy1 && y <= cy2) {
+ buffer[y * pitch + x] = color;
+ }
}
static byte getpixel (int x, int y) {
- if(x>=cx1 && x<=cx2 && y>=cy1 && y<=cy2) {
- x*=HQ;
- y*=HQ;
- return *((Uint8 *)screen->pixels + y*screen->pitch + x);
- }
- return 0;
+ return x >= cx1 && x <= cx2 && y >= cy1 && y <= cy2 ? buffer[y * pitch + x] : 0;
}
-static void mappixel (int x, int y, byte* cmap) {
- byte c = getpixel(x,y);
- putpixel(x,y,cmap[c]);
+static void mappixel (int x, int y, byte *cmap) {
+ byte c = getpixel(x, y);
+ putpixel(x, y, cmap[c]);
}
void V_center (int f) {
- if (f) V_offset(SCRW/2-320/2, SCRH/2-200/2);
- else V_offset(0, 0);
+ if (f) {
+ V_offset(SCRW / 2 - 320 / 2, SCRH / 2 - 200 / 2);
+ } else {
+ V_offset(0, 0);
+ }
}
void V_offset (int ox, int oy) {
- offx=ox;
- offy=oy;
+ offx = ox;
+ offy = oy;
}
static void draw_spr (short x, short y, vgaimg *i, int d, int c) {
for (ly=0; ly<i->h; ly++) {
for(lx=0; lx<i->w; lx++) {
int rx,ry;
- rx = (d & 1) ? (i->w-lx-1) : (rx=lx);
- ry = (d & 2) ? (i->h-ly-1) : (ry=ly);
+ rx = (d & 1) ? (i->w-lx-1) : (lx);
+ ry = (d & 2) ? (i->h-ly-1) : (ly);
if (*p) {
byte t = *p;
if (c) if (t>=0x70 && t<=0x7F) t=t-0x70+c;
draw_spr(x, y, p, 1, c);
}
-// вывести точку цвета c в координатах (x,y)
-void V_dot (short x,short y, unsigned char c) {
- putpixel(x,y,c);
+void V_dot (short x, short y, unsigned char c) {
+ putpixel(x, y, c);
}
void smoke_sprf (int x, int y, byte c) {
draw_rect(x, y, w, h, c);
}
-// установить n цветов, начиная с f, из массива p
-static void VP_set (void *p, short f, short n) {
- byte *ptr = (byte*)p;
- SDL_Color colors[256];
- int i;
- for(i=f;i<f+n;i++)
- {
- colors[i].r=ptr[0]*4;
- colors[i].g=ptr[1]*4;
- colors[i].b=ptr[2]*4;
- ptr+=3;
- }
- SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, f, n);
-}
-
-// установить палитру из массива p
-void VP_setall (void *p) {
- VP_set(p, 0, 256);
-}
-
-// установить адрес экранного буфера
-// NULL - реальный экран
void V_setscr (void *p) {
- if (screen) SDL_Flip(screen);
+ Y_repaint();
}
-// скопировать прямоугольник на экран
void V_copytoscr (short x, short w, short y, short h) {
- x*=HQ; y*=HQ; w*=HQ; h*=HQ;
- SDL_UpdateRect(screen, x, y, w, h);
+ Y_repaint_rect(x, y, w, h);
}
void V_maptoscr (int x, int w, int y, int h, void *cmap) {
}
void V_toggle (void) {
- if (!SDL_WM_ToggleFullScreen(screen)) {
- int ncolors = screen->format->palette->ncolors;
- SDL_Color colors[256];
- int i;
- for (i=0; i<ncolors; i++) {
- colors[i].r = screen->format->palette->colors[i].r;
- colors[i].g = screen->format->palette->colors[i].g;
- colors[i].b = screen->format->palette->colors[i].b;
- }
-
- Uint32 flags = screen->flags;
-
- SDL_FreeSurface(screen);
-
- screen = SDL_SetVideoMode(0, 0, 0, flags ^ SDL_FULLSCREEN);
- if(screen == NULL) {
- ERR_fatal("Unable to set video mode\n");
- exit(1);
- }
-
- SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, ncolors);
- }
+ fullscreen = Y_set_fullscreen(!Y_get_fullscreen());
}
diff --git a/src/soft/vga.h b/src/soft/vga.h
index 44f1d485b0b749cc3bc09206b84f0eb1970277c3..ecc633446b0660bf48a3613823100cea22b0e533 100644 (file)
--- a/src/soft/vga.h
+++ b/src/soft/vga.h
// x-левая сторона,w-ширина,y-верх,h-высота
void V_clr (short x, short w, short y, short h, unsigned char c);
-// установить палитру из массива p
-void VP_setall (void *p);
-
// установить область вывода
void V_setrect (short x, short w, short y, short h);