set_mode, SDL en la graphics, y tal y cual

This commit is contained in:
Gabriel Lorenzo 2003-05-30 03:18:56 +00:00
parent eb98f06c3c
commit 5411ad1508
10 changed files with 317 additions and 103 deletions

View file

@ -12,9 +12,10 @@
#include <assert.h>
#include <export.h>
#include "export.h"
#include "graphics.h"
#include "SDL_rotozoom.h"
#include "default_palette.h"
#define ERR_FILENOTFOUND 105
#define ERR_INVALIDFPGHEADER 106
@ -22,6 +23,7 @@
#define Miedzy(x,a,b) (((x) >= (a)) && ((x) <= (b)))
#define PaletteCopy(dst,src) SDL_SetPalette(dst,SDL_LOGPAL|SDL_PHYSPAL,src->format->palette->colors,0,256);
#define MAX_DRAWS 1024
@ -29,7 +31,7 @@
struct _files files[ 0xFF ] ;
SDL_Surface *Mapa[0xFFF] ;
SDL_Surface *fondo ;
struct _file file0[0xFFF] ;
int last_map[0xFF] ;
int color_transparente ;
@ -64,17 +66,7 @@ typedef struct _FPGMAPINFO{
int number_of_points;
}FPGMAPINFO;
typedef struct _MODOVIDEO {
int ancho;
int alto;
int bpp;
int flags;
BOOL cambiado;
} MODOVIDEO;
MODOVIDEO modovideo;
char *graphic; /* wide*height */
//char *graphic; /* wide*height */
struct{
@ -124,6 +116,8 @@ int ExportaFuncs(EXPORTAFUNCS_PARAMS)
CONST("m1600x1200",16001200);
CONST("m1900x1600",19001600);
CONST("_fullscreen",GR_FULLSCREEN);
CONST("partial_dump",0);
CONST("complete_dump",1);
@ -391,7 +385,8 @@ int eDIV_RGB(FUNCTION_PARAMS)
g = getparm() ;
r = getparm() ;
return ( b + g*256 + r*65536 ) ;
//return ( b + g*256 + r*65536 ) ;
return SDL_MapRGB(screen->format,r,g,b);
}
/*****************************************************************/
@ -413,7 +408,7 @@ int eDIV_GET_RGB(FUNCTION_PARAMS)
goff=getparm();
roff=getparm();
color=getparm();
SDL_GetRGB(color,fp->screen->format,&r,&g,&b);
SDL_GetRGB(color,screen->format,&r,&g,&b);
if(roff) fp->mem[roff]=(int)r;
if(goff) fp->mem[goff]=(int)g;
if(boff) fp->mem[boff]=(int)b;
@ -1039,6 +1034,7 @@ int eDIV_LOAD_FPG(FUNCTION_PARAMS)
int tamano;
int cont=0,num,i;
int bpp;
char* graphic;
SDL_Color p[256];
@ -1208,6 +1204,32 @@ int eDIV_FADE(FUNCTION_PARAMS)
FILE * fichero ;
FILE * memo ;
void guarda_pantallazo(char* nombre_program)
{
char capturef[256], num[5];
int c,i;
FILE* f;
strcpy(capturef,nombre_program);
i=strlen(capturef)+3;
strcat(capturef,"0000");
strcat(capturef,".bmp");
while(f=fopen(capturef,"rb")) {
fclose(f);
c=i;
while(1) {
capturef[c]++;
if(capturef[c]>'9') {
capturef[c]='0';
c--;
if(c<i-3) break;
}
else break;
}
}
SDL_SaveBMP(screen,capturef);
}
/*
* Función para usar con qsort() para ordenar los blits por su Z
*/
@ -1224,8 +1246,16 @@ void frame(FUNCTION_PARAMS)
int i , id , f , g , r , z , trans,angle,size,resolution;
SDL_Rect dstrect , srcrect ;
Uint32 rmask , gmask , bmask , amask ;
SDL_Surface* temp;
int noevent;
SDL_Event event;
byte* teclas;
//assert(0);
/* rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
amask = 0x00000000;
*/
if(primer_frame) {
primer_frame=FALSE;
@ -1238,47 +1268,64 @@ void frame(FUNCTION_PARAMS)
return;
}
screen = SDL_SetVideoMode(modovideo.ancho, modovideo.alto, modovideo.bpp, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL);
temp = SDL_SetVideoMode(fp->graphics->ancho,fp->graphics->alto,fp->graphics->bpp,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_HWACCEL|((fp->graphics->flags&GR_FULLSCREEN)?SDL_FULLSCREEN:0)|((fp->graphics->bpp==8)?SDL_HWPALETTE:0));
if(fp->graphics->bpp==8)
PaletteCopy(temp,screen);
rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
amask = 0x00000000;
if(fp->graphics->resflags&GR_CHANGED) {
SDL_FreeSurface(screen);
SDL_FreeSurface(fondo);
screen=temp;
fp->graphics->buffer=screen->pixels;
fondo=SDL_CreateRGBSurface(SDL_HWSURFACE,fp->graphics->ancho,fp->graphics->alto,fp->graphics->bpp,0,0,0,0);
if(fp->graphics->bpp==8)
PaletteCopy(fondo,screen);
fp->graphics->background=fondo->pixels;
fp->graphics->resflags^=GR_CHANGED;
}
else {
SDL_BlitSurface(screen,NULL,temp,NULL);
SDL_FreeSurface(screen);
screen=temp;
fp->graphics->buffer=screen->pixels;
}
if ( screen == NULL ) {
if ( screen == NULL || fondo==NULL) {
fp->Critical_Error(7); /* No se pudo inicializar SDL */
return;
}
fondo = SDL_CreateRGBSurface( SDL_HWSURFACE , modovideo.ancho , modovideo.alto , modovideo.bpp , rmask , gmask , bmask , amask ) ;
SDL_WM_SetCaption(fp->nombre_program, NULL);
SDL_ShowCursor(0);
}
else if(modovideo.cambiado) {
/* TODO: Avisar a las DLLs */
SDL_FreeSurface(fondo);
SDL_FreeSurface(screen);
screen = SDL_SetVideoMode(modovideo.ancho, modovideo.alto, modovideo.bpp, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL);
rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
amask = 0x00000000;
if ( screen == NULL ) {
fp->Critical_Error(7); /* No se pudo inicializar SDL */
return;
}
fondo = SDL_CreateRGBSurface( SDL_HWSURFACE , modovideo.ancho , modovideo.alto , modovideo.bpp , rmask , gmask , bmask , amask ) ;
modovideo.cambiado=FALSE;
else {
if(fp->graphics->resflags&GR_CHANGED)
fp->graphics->resflags^=GR_CHANGED;
}
/* si no gestionamos un poco los eventos la cosa se cuelga :p */
noevent=0;
while ( SDL_PollEvent(&event) && !noevent )
{
switch( event.type )
{
case SDL_QUIT:
//assert(0);
fp->Stub_Quit(0);
break ;
case SDL_NOEVENT:
noevent=1;
break;
}
}
teclas=SDL_GetKeyState(NULL);
if(teclas[SDLK_x] && (teclas[SDLK_RALT] || teclas[SDLK_LALT]))
fp->Stub_Quit(0);
if(teclas[SDLK_p] && (teclas[SDLK_RALT] || teclas[SDLK_LALT]))
guarda_pantallazo(fp->nombre_program);
fichero = fopen( "draw.txt" , "w" ) ;
if ( define_region == 1)
@ -1299,6 +1346,7 @@ void frame(FUNCTION_PARAMS)
/*
* Draws
*/
z = global("draw_z");
smooth = global("smooth");
for ( i = 0 ; i <= last_draw ; i++ )
@ -1430,7 +1478,7 @@ void frame(FUNCTION_PARAMS)
last_blit = -1 ;
SDL_Flip(screen) ;
fp->screen=screen;
fp->graphics->buffer=screen->pixels;
fclose(fichero);
}
@ -1438,6 +1486,7 @@ void frame(FUNCTION_PARAMS)
void first_load(FUNCTION_PARAMS)
{
int i ;
Uint32 rmask , gmask , bmask , amask ;
fp->Dibuja = Dibuja ;
fp->files = files ;
@ -1470,11 +1519,27 @@ void first_load(FUNCTION_PARAMS)
define_region = 1 ;
modovideo.ancho=320;
modovideo.alto=200;
modovideo.bpp=8;
modovideo.flags=0;
modovideo.cambiado=FALSE;
fp->graphics->ancho=320;
fp->graphics->alto=200;
fp->graphics->bpp=8;
fp->graphics->flags=0;
fp->graphics->resflags=GR_ACTIVE;
rmask = 0;
gmask = 0;
bmask = 0;
amask = 0;
screen=SDL_CreateRGBSurface(SDL_HWSURFACE,fp->graphics->ancho,fp->graphics->alto,fp->graphics->bpp,rmask,gmask,bmask,amask);
if(screen==NULL)
fp->Custom_Error(_critical_error,"graphics: Error al crear buffer");
fondo=SDL_CreateRGBSurface(SDL_HWSURFACE,fp->graphics->ancho,fp->graphics->alto,fp->graphics->bpp,rmask,gmask,bmask,amask);
if(fondo==NULL)
fp->Custom_Error(_critical_error,"graphics: Error al crear buffer");
fp->graphics->buffer=screen->pixels;
fp->graphics->background=fondo->pixels;
}
@ -1561,25 +1626,48 @@ int eDIV_SET_MODE(FUNCTION_PARAMS)
switch(fp->num_params) {
case 4:
modovideo.flags=getparm();
fp->graphics->flags=getparm();
case 3:
modovideo.bpp=getparm();
modovideo.alto=getparm();
modovideo.ancho=getparm();
modovideo.cambiado=TRUE;
fp->graphics->bpp=getparm();
fp->graphics->alto=getparm();
fp->graphics->ancho=getparm();
break;
case 1:
modo=getparm();
if(modo>1280960) {
modovideo.ancho=modo/10000;
modovideo.alto=modo%10000;
fp->graphics->ancho=modo/10000;
fp->graphics->alto=modo%10000;
}
else {
modovideo.ancho=modo/1000;
modovideo.alto=modo%1000;
fp->graphics->ancho=modo/1000;
fp->graphics->alto=modo%1000;
}
modovideo.bpp=8;
modovideo.cambiado=TRUE;
fp->graphics->bpp=8;
fp->graphics->flags=0;
}
/* Esto avisa a las DLLs */
fp->graphics->resflags|=GR_CHANGED;
SDL_FreeSurface(fondo);
SDL_FreeSurface(screen);
screen=SDL_SetVideoMode(fp->graphics->ancho,fp->graphics->alto,fp->graphics->bpp,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_HWACCEL|((fp->graphics->flags&GR_FULLSCREEN)?SDL_FULLSCREEN:0)|((fp->graphics->bpp==8)?SDL_HWPALETTE:0));
fp->graphics->buffer=screen->pixels;
if(fp->graphics->bpp==8)
SDL_SetPalette(screen,SDL_LOGPAL|SDL_PHYSPAL,(SDL_Color*)default_palette,0,256);
if ( screen == NULL ) {
fp->Critical_Error(7); /* No se pudo inicializar SDL */
return 0;
}
fondo=SDL_CreateRGBSurface(SDL_HWSURFACE,fp->graphics->ancho,fp->graphics->alto,fp->graphics->bpp,0,0,0,0);
fp->graphics->background=fondo->pixels;
if(fp->graphics->bpp==8)
PaletteCopy(fondo,screen);
return 0;
}

View file

@ -6,7 +6,7 @@
#define PIOVER180 0.017453292519943295769236907684886
SDL_Surface *screen;
SDL_Surface *prueba;
SDL_Surface *fondo;
int eDIV_LOAD_BMP(FUNCTION_PARAMS);
int eDIV_COLLISION(FUNCTION_PARAMS);

View file

@ -21,11 +21,13 @@
Optimization="0"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GRAPHICS_EXPORTS"
GeneratePreprocessedFile="0"
MinimalRebuild="TRUE"
ExceptionHandling="FALSE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
BrowseInformation="1"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"
@ -40,13 +42,17 @@
ModuleDefinitionFile="../graphics.def"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/graphics.pdb"
GenerateMapFile="TRUE"
MapExports="TRUE"
MapLines="TRUE"
SubSystem="2"
ImportLibrary=""
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
Name="VCPostBuildEventTool"
CommandLine="copy ..\..\..\bin\graphics.dll ..\..\..\..\ediv\bin\dll"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
@ -127,6 +133,9 @@
<File
RelativePath="..\SDL_rotozoom.h">
</File>
<File
RelativePath="..\default_palette.h">
</File>
<File
RelativePath="..\graphics.h">
</File>

View file

@ -45,7 +45,6 @@ extern "C" {
#endif
#endif
/* VARINDEX */
typedef enum { v_global, v_reserved, v_local } tipo_t;
@ -206,7 +205,9 @@ struct _existe {
} ;
struct _file
{
SDL_Surface *Surface ;
SDL_Surface *Surface;
int w,h;
int bpp;
int existe ;
struct
{
@ -221,6 +222,16 @@ struct _files
struct _file *mapa ;
} ;
typedef struct {
int ancho;
int alto;
int bpp;
int flags;
int resflags;
byte* buffer;
byte* background;
} _graphics;
struct _fun_params{
int *pila ;
int *sp ;
@ -245,9 +256,15 @@ struct _fun_params{
int imem_max;
int* nullstring;
int* nstring;
SDL_Surface *screen;
_graphics* graphics;
};
/* Flags para graphics */
#define GR_FULLSCREEN 0x01
/* Flags reservados */
#define GR_ACTIVE 0x01
#define GR_CHANGED 0x02
/* Se usa igual que el getparm() de DIV */
#define getparm() fp->pila[(*fp->sp)--]

View file

@ -1,8 +1,15 @@
#include "export.h"
#include "qgraphics.h"
int ExportaFuncs(EXPORTAFUNCS_PARAMS)
{
ENTRYPOINT(first_load);
return TRUE;
}
void first_load(FUNCTION_PARAMS)
{
gr_Init()
}
void frame(FUNCTION_PARAMS)

View file

@ -1,4 +1,21 @@
#ifndef __EDIV_QGRAPHICS_H_
#define __EDIV_QGRAPHICS_H_
#include "export.h"
/* Flags de modos de video */
#define _FULLSCREEN 0x01
typedef struct {
byte* buffer; // invisible buffer
byte* colormap; // 256 * VID_GRADES size
byte* alphamap; // 256 * 256 translucency map
int width;
int height;
int bpp;
int flags;
} viddef_t;
viddef_t vid;
#endif /* __EDIV_QGRAPHICS_H_ */

View file

@ -112,6 +112,9 @@
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="win32\dib.c">
</File>
<File
RelativePath="qgraphics.c">
</File>
@ -129,6 +132,9 @@
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="win32\dib.h">
</File>
<File
RelativePath="win32\gr_win32.h">
</File>

View file

@ -4,9 +4,13 @@
* funciones:
*
* gr_Init
* gr_InitVideoMode
* gr_Shutdown
*/
#include "qgraphics.h"
#include "gr_win32.h"
#include "dib.h"
/*
* Inicializa cosillas de la libreria
@ -20,7 +24,7 @@ int gr_Init( void *hInstance, void *wndProc )
}
/*
** SWimp_InitGraphics
** gr_InitVideoMode
**
** This initializes the software refresh's implementation specific
** graphics subsystem. In the case of Windows it creates DIB or
@ -29,35 +33,107 @@ int gr_Init( void *hInstance, void *wndProc )
** The necessary width and height parameters are grabbed from
** vid.width and vid.height.
*/
static bool SWimp_InitGraphics( int vid_width, int vid_height, bool fullscreen )
static bool gr_InitVideoMode( int vid_width, int vid_height, int bpp, int flags )
{
// free resources in use
gr_Shutdown ();
vid.width=vid_width;
vid.height=vid_height;
vid.bpp=bpp;
vid.flags=flags;
// create a new window
VID_CreateWindow (vid_width, vid_height, WINDOW_STYLE);
Win32_CreateWindow (vid_width, vid_height, WINDOW_STYLE);
// initialize the appropriate subsystem
if ( !fullscreen )
if ( !(flags & _FULLSCREEN) )
{
if ( !DIB_Init( &vid.buffer, &vid.rowbytes ) )
if ( !DIB_Init( &vid.buffer ) )
{
vid.buffer = 0;
vid.rowbytes = 0;
return false;
return FALSE;
}
}
else
{
if ( !DDRAW_Init( &vid.buffer, &vid.rowbytes ) )
/* de momento, solo DIB (sin fullscreen) */
return FALSE;
/*if ( !DDRAW_Init( &vid.buffer, &vid.rowbytes ) )
{
vid.buffer = 0;
vid.rowbytes = 0;
return false;
}
}*/
}
return true;
return FALSE;
}
/*
** Win32_CreateWindow
*/
void Win32_CreateWindow( int width, int height, int stylebits )
{
WNDCLASS wc;
RECT r;
int x, y, w, h;
int exstyle;
if ( vid.flags & _FULLSCREEN )
exstyle = WS_EX_TOPMOST;
else
exstyle = 0;
/* Register the frame class */
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)sww_state.wndproc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = sww_state.hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.hbrBackground = (void *)COLOR_GRAYTEXT;
wc.lpszMenuName = 0;
wc.lpszClassName = WINDOW_CLASS_NAME;
if (!RegisterClass (&wc) )
fp->CustomError(_critical_error,"qgraphics: No puedo registrar clase de ventana");
r.left = 0;
r.top = 0;
r.right = width;
r.bottom = height;
AdjustWindowRect (&r, stylebits, FALSE);
w = r.right - r.left;
h = r.bottom - r.top;
x = 0;
y = 0;
sww_state.hWnd = CreateWindowEx (
exstyle,
WINDOW_CLASS_NAME,
"qgraphics",
stylebits,
x, y, w, h,
NULL,
NULL,
sww_state.hInstance,
NULL);
if (!sww_state.hWnd)
fp->CustomError(_critical_error."qgraphics: No puedo crear ventana");
ShowWindow( sww_state.hWnd, SW_SHOWNORMAL );
UpdateWindow( sww_state.hWnd );
SetForegroundWindow( sww_state.hWnd );
SetFocus( sww_state.hWnd );
// let the sound and input subsystems know about the new window
//ri.Vid_NewWindow (width, height);
}

View file

@ -11,6 +11,7 @@
#include "export.h"
#define WINDOW_STYLE (WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_VISIBLE)
#define WINDOW_CLASS_NAME "qgraphics"
extern HINSTANCE global_hInstance;
@ -52,13 +53,6 @@ typedef struct
extern swwstate_t sww_state;
/*
** DIB
*/
bool DIB_Init( unsigned char **ppbuffer, int *ppitch );
void DIB_Shutdown( void );
void DIB_SetPalette( const unsigned char *palette );
/*
** DirectDraw
*/

View file

@ -5,8 +5,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "edivstd", "..\edivstd\win32
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "file", "..\file\win32\file.vcproj", "{EA869297-5AC6-4603-BB86-9962207DB25F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graphics", "..\graphics\win32\graphics.vcproj", "{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "input", "..\input\win32\input.vcproj", "{92E50294-4312-49E4-848B-5C9FF43AB27D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math", "..\math\win32\math.vcproj", "{56A4746D-5A73-4CA5-BD0C-959F14B503E7}"
@ -15,6 +13,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "strings", "..\strings\win32
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "text", "..\text\win32\text.vcproj", "{71D05C32-B49A-4690-AA4D-1385D4257CDF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graphics", "..\graphics\win32\graphics.vcproj", "{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}"
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
@ -35,10 +35,6 @@ Global
{EA869297-5AC6-4603-BB86-9962207DB25F}.Debug.Build.0 = Debug|Win32
{EA869297-5AC6-4603-BB86-9962207DB25F}.Release.ActiveCfg = Release|Win32
{EA869297-5AC6-4603-BB86-9962207DB25F}.Release.Build.0 = Release|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.ActiveCfg = Debug|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.Build.0 = Debug|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.ActiveCfg = Release|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.Build.0 = Release|Win32
{92E50294-4312-49E4-848B-5C9FF43AB27D}.Debug.ActiveCfg = Debug|Win32
{92E50294-4312-49E4-848B-5C9FF43AB27D}.Debug.Build.0 = Debug|Win32
{92E50294-4312-49E4-848B-5C9FF43AB27D}.Release.ActiveCfg = Release|Win32
@ -55,6 +51,10 @@ Global
{71D05C32-B49A-4690-AA4D-1385D4257CDF}.Debug.Build.0 = Debug|Win32
{71D05C32-B49A-4690-AA4D-1385D4257CDF}.Release.ActiveCfg = Release|Win32
{71D05C32-B49A-4690-AA4D-1385D4257CDF}.Release.Build.0 = Release|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.ActiveCfg = Debug|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Debug.Build.0 = Debug|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.ActiveCfg = Release|Win32
{20CF9907-2F82-4A8C-A5FB-074F5F1BCB32}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection