Using a clean flow for closing game data at the end of main() instead of using atexit; Now only use atexit for SDL stuff, error, mem, console (and editor which we do later); Small Cleanup

This commit is contained in:
zicodxx 2008-11-14 16:56:40 +00:00
parent 30f85fd3f9
commit 1de53497b2
48 changed files with 118 additions and 1099 deletions

View file

@ -1,657 +0,0 @@
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* "PC" Version:
* Rountines to copy a bitmap on top of another bitmap, but
* only copying to pixels that are transparent.
* "Mac" Version:
* Routines to to inverse bitblitting -- well not really.
* We don't inverse bitblt like in the PC, but this code
* does set up a structure that blits around the cockpit
*
* d2x uses the "Mac" version for everything except __MSDOS__
*
*/
#ifdef HAVE_CONFIG_H
#include <conf.h>
#endif
#ifdef __MSDOS__ //ndef MACINTOSH
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "gr.h"
#include "mem.h"
#include "error.h"
#include "ibitblt.h"
#include "grdef.h"
#define MODE_NONE 0
#define MODE_SKIP 1
#define MODE_DRAW 2
#define OPCODE_ADD 0x81
#define OPCODE_ESI 0xC6 // Followed by a dword (add esi, ????)
#define OPCODE_EDI 0xC7 // Followed by a dword (add edi, ????)
#define OPCODE_MOV_ECX 0xB9 // Followed by a dword (mov ecx,????)
#define OPCODE_MOVSB 0xA4 // movsb
#define OPCODE_16BIT 0x66 // movsw
#define OPCODE_MOVSD 0xA5 // movsd
#define OPCODE_REP 0xF3 // rep
#define OPCODE_RET 0xC3 // ret
#define OPCODE_MOV_EAX 0xB8 // mov eax, im dword
#define OPCODE_MOV_EBX 0xBB // mov ebx, im dword
#define OPCODE_CALL_EBX1 0xFF // call
#define OPCODE_CALL_EBX2 0xD3 // ebx
#define OPCODE_MOV_EDI 0xBF // mov edi, im dword
ubyte *Code_pointer = NULL;
int Code_counter = 0;
int ibitblt_svga_page = 0;
int is_svga = 0;
uint linear_address;
void count_block( int ecx )
{
int blocks;
while ( ecx > 0 ) {
switch(ecx) {
case 1: Code_counter++; ecx = 0; break; // MOVSB
case 2: Code_counter+=2; ecx = 0; break; // MOVSW
case 3: Code_counter+=3; ecx = 0; break; // MOVSW, MOVSB
case 4: Code_counter++; ecx = 0; break; // MOVSD
default:
blocks = ecx / 4;
if ( blocks == 1 )
Code_counter++; // MOVSD
else
Code_counter+=7;
ecx -= blocks*4;
}
}
}
void move_and_count( int dsource, int ddest, int ecx )
{
if ( ecx <= 0 )
return;
if ( dsource > 0 ) {
// ADD ESI, dsource
Code_counter += 6;
}
if ( !is_svga ) {
if ( ddest > 0 ) {
// ADD EDI, ddest
Code_counter += 6;
}
count_block( ecx );
} else {
int p1, p2, o1;
linear_address += ddest; // Skip to next block
p1 = linear_address >> 16; o1 = linear_address & 0xFFFF;
p2 = (linear_address+ecx) >> 16;
if ( p1 != ibitblt_svga_page ) {
// Set page
// MOV EAX, ?, CALL EBX
Code_counter += 7;
ibitblt_svga_page = p1;
}
Code_counter += 5; // mov edi, ????
if ( p1 == p2 ) {
count_block( ecx );
} else {
int nbytes;
nbytes = 0xFFFF-o1+1;
count_block( nbytes );
// set page
// MOV EAX, 0
Code_counter += 7; // mov eax,???? call ebx
ibitblt_svga_page = p2;
Code_counter += 5; // mov edi, ????
nbytes = ecx - nbytes;
if (nbytes > 0 )
count_block( nbytes );
}
linear_address += ecx;
}
}
void draw_block( int ecx )
{
int blocks;
int * iptr;
while ( ecx > 0 ) {
switch( ecx ) {
case 1:
// MOVSB
*Code_pointer++ = OPCODE_MOVSB;
ecx = 0;
break;
case 2:
// MOVSW
*Code_pointer++ = OPCODE_16BIT;
*Code_pointer++ = OPCODE_MOVSD;
ecx = 0;
break;
case 3:
// MOVSW, MOVSB
*Code_pointer++ = OPCODE_16BIT;
*Code_pointer++ = OPCODE_MOVSD;
*Code_pointer++ = OPCODE_MOVSB;
ecx = 0;
break;
case 4:
// MOVSD
*Code_pointer++ = OPCODE_MOVSD;
ecx = 0;
break;
default:
blocks = ecx / 4;
if ( blocks == 1 ) {
// MOVSD
*Code_pointer++ = OPCODE_MOVSD;
} else {
// MOV ECX, blocks
*Code_pointer++ = OPCODE_MOV_ECX;
iptr = (int *)Code_pointer;
*iptr++ = blocks;
Code_pointer = (ubyte *)iptr;
// REP MOVSD
*Code_pointer++ = OPCODE_REP;
*Code_pointer++ = OPCODE_MOVSD;
}
ecx -= blocks*4;
}
}
}
void move_and_draw( int dsource, int ddest, int ecx )
{
int * iptr;
if ( ecx <= 0 )
return;
if ( dsource > 0 ) {
// ADD ESI, dsource
*Code_pointer++ = OPCODE_ADD;
*Code_pointer++ = OPCODE_ESI;
iptr = (int *)Code_pointer;
*iptr++ = dsource;
Code_pointer = (ubyte *)iptr;
}
if ( !is_svga ) {
if ( ddest > 0 ) {
// ADD EDI, ddest
*Code_pointer++ = OPCODE_ADD;
*Code_pointer++ = OPCODE_EDI;
iptr = (int *)Code_pointer;
*iptr++ = ddest;
Code_pointer = (ubyte *)iptr;
}
draw_block( ecx );
} else {
unsigned int temp;
int temp_offset;
int p1, p2, o1;
linear_address += ddest; // Skip to next block
p1 = linear_address >> 16; o1 = linear_address & 0xFFFF;
p2 = (linear_address+ecx) >> 16;
if ( p1 != ibitblt_svga_page ) {
// Set page
// MOV EAX, 0
*Code_pointer++ = OPCODE_MOV_EAX;
temp = p1;
memcpy( Code_pointer, &temp, sizeof(int) );
Code_pointer += sizeof(int);
// CALL EBX
*Code_pointer++ = OPCODE_CALL_EBX1;
*Code_pointer++ = OPCODE_CALL_EBX2;
ibitblt_svga_page = p1;
}
temp_offset = 0xA0000 + o1;
*Code_pointer++ = OPCODE_MOV_EDI;
iptr = (int *)Code_pointer;
*iptr++ = temp_offset;
Code_pointer = (ubyte *)iptr;
if ( p1 == p2 ) {
draw_block( ecx );
} else {
int nbytes;
nbytes = 0xFFFF-o1+1;
draw_block( nbytes );
// set page
// MOV EAX, 0
*Code_pointer++ = OPCODE_MOV_EAX;
temp = p2;
memcpy( Code_pointer, &temp, sizeof(int) );
Code_pointer += sizeof(int);
// CALL EBX
*Code_pointer++ = OPCODE_CALL_EBX1;
*Code_pointer++ = OPCODE_CALL_EBX2;
ibitblt_svga_page = p2;
temp_offset = 0xA0000;
*Code_pointer++ = OPCODE_MOV_EDI;
iptr = (int *)Code_pointer;
*iptr++ = temp_offset;
Code_pointer = (ubyte *)iptr;
nbytes = ecx - nbytes;
if (nbytes > 0 )
draw_block( nbytes );
}
linear_address += ecx;
}
}
//-----------------------------------------------------------------------------------------
// Given bitmap, bmp, finds the size of the code
int gr_ibitblt_find_code_size_sub( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize, int dest_type )
{
int x,y;
ubyte pixel;
int draw_mode = MODE_NONE;
int source_offset = 0;
int dest_offset = 0;
int num_to_draw, draw_start_source, draw_start_dest;
int esi, edi;
Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
Code_counter = 0;
if ( dest_type == BM_SVGA ) {
Code_counter += 1+4; // move ebx, gr_vesa_set_page
Code_counter += 1+4; // move eax, 0
Code_counter += 2; // call ebx
ibitblt_svga_page = 0;
linear_address = 0;
is_svga = 1;
} else {
is_svga = 0;
}
esi = source_offset = 0;
edi = dest_offset = 0;
draw_start_source = draw_start_dest = 0;
for ( y=sy; y<sy+sh; y++ ) {
for ( x=sx; x<sx+sw; x++ ) {
dest_offset = y*mask_bmp->bm_rowsize+x;
pixel = mask_bmp->bm_data[dest_offset];
if ( pixel!=255 ) {
switch ( draw_mode) {
case MODE_DRAW:
move_and_count( draw_start_source-esi, draw_start_dest-edi, num_to_draw );
esi = draw_start_source + num_to_draw;
edi = draw_start_dest + num_to_draw;
// fall through!!!
case MODE_NONE:
case MODE_SKIP:
break;
}
draw_mode = MODE_SKIP;
} else {
switch ( draw_mode) {
case MODE_SKIP:
case MODE_NONE:
draw_start_source = source_offset;
draw_start_dest = dest_offset;
num_to_draw = 0;
// fall through
case MODE_DRAW:
num_to_draw++;
break;
}
draw_mode = MODE_DRAW;
}
source_offset++;
}
if ( draw_mode == MODE_DRAW ) {
move_and_count( draw_start_source-esi, draw_start_dest-edi, num_to_draw );
esi = draw_start_source + num_to_draw;
edi = draw_start_dest + num_to_draw;
}
draw_mode = MODE_NONE;
source_offset += (srowsize - sw);
}
Code_counter++; // for return
Code_counter += 16; // for safety was 16
return Code_counter;
}
int gr_ibitblt_find_code_size( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize )
{
return gr_ibitblt_find_code_size_sub( mask_bmp, sx, sy, sw, sh, srowsize, BM_LINEAR );
}
int gr_ibitblt_find_code_size_svga( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize )
{
return gr_ibitblt_find_code_size_sub( mask_bmp, sx, sy, sw, sh, srowsize, BM_SVGA );
}
//-----------------------------------------------------------------------------------------
// Given bitmap, bmp, create code that transfers a bitmap of size sw*sh to position
// (sx,sy) on top of bmp, only overwritting transparent pixels of the bitmap.
ubyte *gr_ibitblt_create_mask_sub( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize, int dest_type )
{
int x,y;
ubyte pixel;
int draw_mode = MODE_NONE;
int source_offset = 0;
int dest_offset = 0;
int num_to_draw, draw_start_source, draw_start_dest;
int esi, edi;
int code_size;
ubyte *code;
uint temp;
Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
if ( dest_type == BM_SVGA )
code_size = gr_ibitblt_find_code_size_svga( mask_bmp, sx, sy, sw, sh, srowsize );
else
code_size = gr_ibitblt_find_code_size( mask_bmp, sx, sy, sw, sh, srowsize );
code = d_malloc( code_size );
if ( code == NULL )
return NULL;
Code_pointer = code;
if ( dest_type == BM_SVGA ) {
// MOV EBX, gr_vesa_setpage
*Code_pointer++ = OPCODE_MOV_EBX;
temp = (uint)gr_vesa_setpage;
memcpy( Code_pointer, &temp, sizeof(int) );
Code_pointer += sizeof(int);
// MOV EAX, 0
*Code_pointer++ = OPCODE_MOV_EAX;
temp = 0;
memcpy( Code_pointer, &temp, sizeof(int) );
Code_pointer += sizeof(int);
// CALL EBX
*Code_pointer++ = OPCODE_CALL_EBX1;
*Code_pointer++ = OPCODE_CALL_EBX2;
ibitblt_svga_page = 0;
is_svga = 1;
linear_address = 0;
} else {
is_svga = 0;
}
esi = source_offset = 0;
edi = dest_offset = 0;
draw_start_source = draw_start_dest = 0;
for ( y=sy; y<sy+sh; y++ ) {
for ( x=sx; x<sx+sw; x++ ) {
dest_offset = y*mask_bmp->bm_rowsize+x;
pixel = mask_bmp->bm_data[dest_offset];
if ( pixel!=255 ) {
switch ( draw_mode) {
case MODE_DRAW:
move_and_draw( draw_start_source-esi, draw_start_dest-edi, num_to_draw );
esi = draw_start_source + num_to_draw;
edi = draw_start_dest + num_to_draw;
// fall through!!!
case MODE_NONE:
case MODE_SKIP:
break;
}
draw_mode = MODE_SKIP;
} else {
switch ( draw_mode) {
case MODE_SKIP:
case MODE_NONE:
draw_start_source = source_offset;
draw_start_dest = dest_offset;
num_to_draw = 0;
// fall through
case MODE_DRAW:
num_to_draw++;
break;
}
draw_mode = MODE_DRAW;
}
source_offset++;
}
if ( draw_mode == MODE_DRAW ) {
move_and_draw( draw_start_source-esi, draw_start_dest-edi, num_to_draw );
esi = draw_start_source + num_to_draw;
edi = draw_start_dest + num_to_draw;
}
draw_mode = MODE_NONE;
source_offset += (srowsize - sw);
}
*Code_pointer++ = OPCODE_RET;
if ( Code_pointer >= &code[code_size-1] )
Error( "ibitblt overwrote allocated code block\n" );
return code;
}
ubyte *gr_ibitblt_create_mask( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize )
{
return gr_ibitblt_create_mask_sub( mask_bmp, sx, sy, sw, sh, srowsize, BM_LINEAR );
}
ubyte *gr_ibitblt_create_mask_svga( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize )
{
return gr_ibitblt_create_mask_sub( mask_bmp, sx, sy, sw, sh, srowsize, BM_SVGA );
}
void gr_ibitblt_do_asm(char *start_si, char *start_di, ubyte * code);
#pragma aux gr_ibitblt_do_asm parm [esi] [edi] [eax] modify [ecx edi esi eax] = \
"pusha" \
"cld" \
"call eax" \
"popa"
void gr_ibitblt(grs_bitmap * source_bmp, grs_bitmap * dest_bmp, ubyte * mask )
{
if (mask != NULL )
gr_ibitblt_do_asm( source_bmp->bm_data, dest_bmp->bm_data, mask );
}
void gr_ibitblt_find_hole_size( grs_bitmap * mask_bmp, int *minx, int *miny, int *maxx, int *maxy )
{
int x, y, count=0;
ubyte c;
Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
*minx = mask_bmp->bm_w-1;
*maxx = 0;
*miny = mask_bmp->bm_h-1;
*maxy = 0;
for ( y=0; y<mask_bmp->bm_h; y++ )
for ( x=0; x<mask_bmp->bm_w; x++ ) {
c = mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x];
if (c == 255 ) {
if ( x < *minx ) *minx = x;
if ( y < *miny ) *miny = y;
if ( x > *maxx ) *maxx = x;
if ( y > *maxy ) *maxy = y;
count++;
}
}
if ( count == 0 ) {
Error( "Bitmap for ibitblt doesn't have transparency!\n" );
}
}
#else /* __MSDOS__ */ // was: /* !MACINTOSH */
#include "pstypes.h"
#include "gr.h"
#include "ibitblt.h"
#include "error.h"
#include "u_mem.h"
#include "grdef.h"
#define FIND_START 1
#define FIND_STOP 2
#define MAX_WIDTH 640
#define MAX_SCANLINES 480
#define MAX_HOLES 5
static short start_points[MAX_SCANLINES][MAX_HOLES];
static short hole_length[MAX_SCANLINES][MAX_HOLES];
static double *scanline = NULL;
void gr_ibitblt(grs_bitmap *src_bmp, grs_bitmap *dest_bmp)
{
int x, y, sw, sh, srowsize, drowsize, dstart, sy;
ubyte *src, *dest;
// variable setup
sw = src_bmp->bm_w;
sh = src_bmp->bm_h;
srowsize = src_bmp->bm_rowsize;
drowsize = dest_bmp->bm_rowsize;
src = src_bmp->bm_data;
dest = dest_bmp->bm_data;
sy = 0;
while (start_points[sy][0] == -1) {
sy++;
dest += drowsize;
}
Assert(sw <= MAX_WIDTH);
Assert(sh <= MAX_SCANLINES);
for (y = sy; y < sy + sh; y++) {
for (x = 0; x < MAX_HOLES; x++) {
if (start_points[y][x] == -1)
break;
dstart = start_points[y][x];
gr_linear_movsd(&(src[dstart]), &(dest[dstart]), hole_length[y][x]);
}
dest += drowsize;
src += srowsize;
}
}
void gr_ibitblt_create_mask(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize)
{
int x, y;
ubyte mode;
int count = 0;
Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
for (y = 0; y < MAX_SCANLINES; y++) {
for (x = 0; x < MAX_HOLES; x++) {
start_points[y][x] = -1;
hole_length[y][x] = -1;
}
}
for (y = sy; y < sy+sh; y++) {
count = 0;
mode = FIND_START;
for (x = sx; x < sx + sw; x++) {
if ((mode == FIND_START) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] == TRANSPARENCY_COLOR)) {
start_points[y][count] = x;
mode = FIND_STOP;
} else if ((mode == FIND_STOP) && (mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x] != TRANSPARENCY_COLOR)) {
hole_length[y][count] = x - start_points[y][count];
count++;
mode = FIND_START;
}
}
if (mode == FIND_STOP) {
hole_length[y][count] = x - start_points[y][count];
count++;
}
Assert(count <= MAX_HOLES);
}
}
void gr_ibitblt_find_hole_size(grs_bitmap *mask_bmp, int *minx, int *miny, int *maxx, int *maxy)
{
ubyte c;
int x, y, count = 0;
Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
Assert( mask_bmp->bm_flags&BM_FLAG_TRANSPARENT );
*minx = mask_bmp->bm_w - 1;
*maxx = 0;
*miny = mask_bmp->bm_h - 1;
*maxy = 0;
if (scanline == NULL)
scanline = (double *)d_malloc(sizeof(double) * (MAX_WIDTH / sizeof(double)));
for (y = 0; y < mask_bmp->bm_h; y++) {
for (x = 0; x < mask_bmp->bm_w; x++) {
c = mask_bmp->bm_data[mask_bmp->bm_rowsize*y+x];
if (c == TRANSPARENCY_COLOR) { // don't look for transparancy color here.
count++;
if (x < *minx) *minx = x;
if (y < *miny) *miny = y;
if (x > *maxx) *maxx = x;
if (y > *maxy) *maxy = y;
}
}
}
Assert (count);
}
#endif /* __MSDOS__ */ // was: /* !MACINTOSH */

View file

@ -528,7 +528,6 @@ void rle_cache_init()
Assert( rle_cache[i].expanded_bitmap != NULL );
}
rle_cache_initialized = 1;
atexit( rle_cache_close );
}
void rle_cache_flush()

View file

@ -40,16 +40,6 @@ static char rcsid[] = "$Id: setup.c,v 1.1.1.1 2006/03/17 19:52:10 zicodxx Exp $"
#include "texmap.h" // for init_interface_vars_to_assembler()
#endif
//initialize the 3d system
void g3_init(void)
{
// div0_init(DM_ERROR);
atexit(g3_close);
}
//close down the 3d system
void g3_close(void) {}
//start the frame
void g3_start_frame(void)
{

View file

@ -1,5 +1,9 @@
D2X-Rebirth Changelog
20081114
--------
include/args.h, include/3d.h, include/rle.h, include/rbaudio.h, main/text.c, main/text.h, main/bm.c, main/gamefont.c, main/inferno.c, main/bm.c, main/bmread.c, main/piggy.c, main/render.c, main/render.h, main/songs.c, main/gameseq.c, main/gamerend.c, main/netdrv.c, main/endlevel.c, main/endlevel.h, main/terrain.c, main/terrain.h, main/polyobj.c, main/polyobj.h, main/game.c, main/gauges.c, main/texmerge.c, main/mission.c, main/mission.h, main/gamecntl.c, misc/args.c, 2d/rle.c, 3d/setup.c, SConstruct, D2X.make, arch/linux/alsadigi.c, arch/ogl/gr.c, arch/sdl/digi_mixer.c, arch/sdl/joy.c, arch/sdl/init.c, arch/sdl/rbaudio.c, arch/sdl/gr.c, arch/sdl/key.c, arch/sdl/digi_audio.c, arch/include/mouse.h: Using a clean flow for closing game data at the end of main() instead of using atexit; Now only use atexit for SDL stuff, error, mem, console (and editor which we do later); Small Cleanup
20081110
--------
main/credits.c, main/inferno.c, main/menu.c, main/newmenu.c: Small Cleanup: Using timer_delay for credits timer as timer_delay2 would respect VSync and change speed of the Credits scrolling; Cleaned that Start/Join Netgame cases up a bit; Removed the excessive use of atexit in newmenu... more to come

View file

@ -35,7 +35,6 @@ SrcFiles =
:2d:disc.c ¶
:2d:font.c ¶
:2d:gpixel.c ¶
:2d:ibitblt.c カ
:2d:line.c ¶
:2d:palette.c ¶
:2d:pcx.c ¶
@ -184,7 +183,6 @@ GeneralObjects =
"{ObjDir}disc.c.x" ¶
"{ObjDir}font.c.x" ¶
"{ObjDir}gpixel.c.x" ¶
"{ObjDir}ibitblt.c.x" カ
"{ObjDir}line.c.x" ¶
"{ObjDir}palette.c.x" ¶
"{ObjDir}pcx.c.x" ¶
@ -377,7 +375,6 @@ directories
"{ObjDir}disc.c.x" Ä :2d:disc.c
"{ObjDir}font.c.x" Ä :2d:font.c
"{ObjDir}gpixel.c.x" Ä :2d:gpixel.c
"{ObjDir}ibitblt.c.x" ト :2d:ibitblt.c
"{ObjDir}line.c.x" Ä :2d:line.c
"{ObjDir}palette.c.x" Ä :2d:palette.c
"{ObjDir}pcx.c.x" Ä :2d:pcx.c

View file

@ -54,7 +54,6 @@ common_sources = [
'2d/disc.c',
'2d/font.c',
'2d/gpixel.c',
'2d/ibitblt.c',
'2d/line.c',
'2d/palette.c',
'2d/pcx.c',
@ -74,6 +73,7 @@ common_sources = [
'3d/rod.c',
'3d/setup.c',
'arch/sdl/event.c',
'arch/sdl/init.c',
'arch/sdl/joy.c',
'arch/sdl/key.c',
'arch/sdl/mouse.c',

View file

@ -34,7 +34,7 @@
#define MOUSE_MBTN 4
extern void mouse_flush(); // clears all mice events...
extern void mouse_close();
extern void d_mouse_init(void);
extern void mouse_get_pos( int *x, int *y, int *z );
extern void mouse_get_delta( int *dx, int *dy, int *dz );
extern int mouse_get_btns();

View file

@ -308,7 +308,6 @@ int digi_init()
pthread_create(&thread_id,&attr,mixer_thread,NULL);
pthread_attr_destroy(&attr);
atexit(digi_close);
digi_initialised = 1;
return 0;
}

View file

@ -385,8 +385,6 @@ int gr_init(int mode)
gr_installed = 1;
atexit(gr_close);
return 0;
}

View file

@ -212,7 +212,6 @@ int digi_audio_init()
}
SDL_PauseAudio(0);
atexit(digi_close);
digi_initialised = 1;
return 0;
}

View file

@ -87,8 +87,6 @@ int digi_mixer_init() {
jukebox_load();
//jukebox_list();
atexit(jukebox_unload);
atexit(digi_close);
digi_initialised = 1;
return 0;

View file

@ -150,7 +150,6 @@ int gr_init(int mode)
gr_set_current_canvas( &grd_curscreen->sc_canvas );
gr_installed = 1;
atexit(gr_close);
return 0;
}

62
arch/sdl/init.c Normal file
View file

@ -0,0 +1,62 @@
// Holds the main init and de-init functions for arch-related program parts
#include <SDL/SDL.h>
#include "rbaudio.h"
#include "key.h"
#include "digi.h"
#include "jukebox.h"
#include "mouse.h"
#include "joy.h"
#include "gr.h"
#include "error.h"
#include "text.h"
#include "args.h"
void arch_close(void)
{
RBAStop();
RBAExit();
gr_close();
if (!GameArg.CtlNoJoystick)
joy_close();
if (!GameArg.SndNoSound)
{
digi_close();
#ifdef USE_SDLMIXER
jukebox_unload();
#endif
}
key_close();
SDL_Quit();
}
void arch_init(void)
{
int t;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
Error("SDL library initialisation failed: %s.",SDL_GetError());
key_init();
digi_select_system( GameArg.SndDisableSdlMixer ? SDLAUDIO_SYSTEM : SDLMIXER_SYSTEM );
if (!GameArg.SndNoSound)
digi_init();
if (!GameArg.CtlNoMouse)
d_mouse_init();
if (!GameArg.CtlNoJoystick)
joy_init();
if ((t = gr_init(0)) != 0)
Error(TXT_CANT_INIT_GFX,t);
atexit(arch_close);
}

View file

@ -218,7 +218,6 @@ int joy_init()
}
joy_num_axes = Joystick.n_axes;
atexit(joy_close);
return joy_present;
}

View file

@ -466,7 +466,6 @@ void key_init()
// Clear the keyboard array
key_flush();
atexit(key_close);
}
void key_flush()

View file

@ -96,7 +96,6 @@ void RBAInit()
return;
}
atexit(RBAExit);
initialised = 1;
}

View file

@ -89,15 +89,6 @@ typedef struct g3s_object {
//Functions in library
//3d system startup and shutdown:
//initialize the 3d system
void g3_init(void);
//close down the 3d system
void g3_close(void);
//Frame setup functions:
//start the frame

View file

@ -27,6 +27,7 @@ extern int Num_args;
extern char *Args[];
extern void AppendIniArgs(void);
extern void InitArgs(int argc, char **argv);
extern void args_exit();
extern int Inferno_verbose;
// Struct that keeps all variables used by FindArg

View file

@ -1,50 +0,0 @@
/* $Id: ibitblt.h,v 1.1.1.1 2006/03/17 20:01:28 zicodxx Exp $ */
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* Prototypes for the ibitblt functions.
*
*/
#ifndef _IBITBLT_H
#define _IBITBLT_H
// Finds location/size of the largest "hole" in bitmap mask_bmp
void gr_ibitblt_find_hole_size ( grs_bitmap * mask_bmp, int *minx, int *miny, int *maxx, int *maxy );
// Creates a code mask that will copy data from a bitmap that is sw by
// sh starting from location sx, sy with a rowsize of srowsize onto
// another bitmap but only copies into pixel locations that are
// defined as transparent in bitmap bmp.
#ifdef __MSDOS__
ubyte * gr_ibitblt_create_mask(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize);
ubyte * gr_ibitblt_create_mask_svga(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize);
ubyte * gr_ibitblt_create_mask_pa( grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize);
#else
void gr_ibitblt_create_mask_pa(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize);
void gr_ibitblt_create_mask(grs_bitmap *mask_bmp, int sx, int sy, int sw, int sh, int srowsize);
#endif
// Copy source bitmap onto destination bitmap, not copying pixels that
// are defined transparent by the mask
#ifdef __MSDOS__
void gr_ibitblt(grs_bitmap *source_bmp, grs_bitmap *dest_bmp, ubyte *mask);
#else
void gr_ibitblt(grs_bitmap *source_bmp, grs_bitmap *dest_bmp);
#endif
#endif

View file

@ -25,11 +25,8 @@ typedef struct _RBACHANNELCTL {
unsigned int out3in, out3vol;
} RBACHANNELCTL;
#ifndef __MSDOS__ //defined(__NT__)
extern void RBAInit(void); //drive a == 0, drive b == 1
#else
extern void RBAInit(ubyte cd_drive_num); //drive a == 0, drive b == 1
#endif
extern void RBAInit(void);
extern void RBAExit();
extern long RBAGetDeviceStatus(void);
extern int RBAPlayTrack(int track);
extern int RBAPlayTracks(int first, int last); //plays tracks first through last, inclusive

View file

@ -30,6 +30,7 @@ int gr_bitmap_rle_compress( grs_bitmap * bmp );
void gr_rle_expand_scanline_masked( ubyte *dest, ubyte *src, int x1, int x2 );
void gr_rle_expand_scanline( ubyte *dest, ubyte *src, int x1, int x2 );
grs_bitmap * rle_expand_texture( grs_bitmap * bmp );
void rle_cache_close();
void rle_cache_flush();
void rle_swap_0_255(grs_bitmap *bmp);
void rle_remap(grs_bitmap *bmp, ubyte *colormap);

161
main/bm.c
View file

@ -56,6 +56,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "makesig.h"
#include "interp.h"
#include "console.h"
#include "rle.h"
ubyte Sounds[MAX_SOUNDS];
ubyte AltSounds[MAX_SOUNDS];
@ -127,6 +128,14 @@ int tmap_info_read_n_d1(tmap_info *ti, int n, CFILE *fp)
return i;
}
void gamedata_close()
{
free_polygon_models();
bm_free_extra_objbitmaps();
free_endlevel_data();
rle_cache_close();
piggy_close();
}
//-----------------------------------------------------------------
// Initializes game properties data (including texture caching system) and sound data.
@ -233,156 +242,6 @@ void bm_read_all(CFILE * fp)
exit_modelnum = destroyed_exit_modelnum = N_polygon_models;
}
// the following is old code for reading descent 1 textures.
#if 0
#define D1_MAX_TEXTURES 800
#define D1_MAX_SOUNDS 250
#define D1_MAX_VCLIPS 70
#define D1_MAX_EFFECTS 60
#define D1_MAX_WALL_ANIMS 30
#define D1_MAX_ROBOT_TYPES 30
#define D1_MAX_ROBOT_JOINTS 600
#define D1_MAX_WEAPON_TYPES 30
#define D1_MAX_POWERUP_TYPES 29
#define D1_MAX_GAUGE_BMS 80
#define D1_MAX_OBJ_BITMAPS 210
#define D1_MAX_COCKPIT_BITMAPS 4
#define D1_MAX_OBJTYPE 100
#define D1_MAX_POLYGON_MODELS 85
#define D1_TMAP_INFO_SIZE 26
#define D1_VCLIP_SIZE 66
#define D1_ROBOT_INFO_SIZE 486
#define D1_WEAPON_INFO_SIZE 115
#define D1_LAST_STATIC_TMAP_NUM 324
// store the Textures[] array as read from the descent 2 pig.
short *d2_Textures_backup = NULL;
void undo_bm_read_all_d1() {
if (d2_Textures_backup) {
int i;
for (i = 0; i < D1_LAST_STATIC_TMAP_NUM; i++)
Textures[i].index = d2_Textures_backup[i];
d_free(d2_Textures_backup);
d2_Textures_backup = NULL;
}
}
/*
* used by piggy_d1_init to read in descent 1 pigfile
*/
void bm_read_all_d1(CFILE * fp)
{
int i;
atexit(undo_bm_read_all_d1);
/*NumTextures = */ cfile_read_int(fp);
//bitmap_index_read_n(Textures, D1_MAX_TEXTURES, fp );
//for (i = 0; i < D1_MAX_TEXTURES; i++)
// Textures[i].index = cfile_read_short(fp) + 600;
//cfseek(fp, D1_MAX_TEXTURES * sizeof(short), SEEK_CUR);
MALLOC(d2_Textures_backup, short, D1_LAST_STATIC_TMAP_NUM);
for (i = 0; i < D1_LAST_STATIC_TMAP_NUM; i++) {
d2_Textures_backup[i] = Textures[i].index;
Textures[i].index = cfile_read_short(fp) + 521;
}
cfseek(fp, (D1_MAX_TEXTURES - D1_LAST_STATIC_TMAP_NUM) * sizeof(short), SEEK_CUR);
//tmap_info_read_n_d1(TmapInfo, D1_MAX_TEXTURES, fp);
cfseek(fp, D1_MAX_TEXTURES * D1_TMAP_INFO_SIZE, SEEK_CUR);
/*
cfread( Sounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
cfread( AltSounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
*/cfseek(fp, D1_MAX_SOUNDS * 2, SEEK_CUR);
/*Num_vclips = */ cfile_read_int(fp);
//vclip_read_n(Vclip, D1_MAX_VCLIPS, fp);
cfseek(fp, D1_MAX_VCLIPS * D1_VCLIP_SIZE, SEEK_CUR);
/*
Num_effects = cfile_read_int(fp);
eclip_read_n(Effects, D1_MAX_EFFECTS, fp);
Num_wall_anims = cfile_read_int(fp);
wclip_read_n_d1(WallAnims, D1_MAX_WALL_ANIMS, fp);
*/
/*
N_robot_types = cfile_read_int(fp);
//robot_info_read_n(Robot_info, D1_MAX_ROBOT_TYPES, fp);
cfseek(fp, D1_MAX_ROBOT_TYPES * D1_ROBOT_INFO_SIZE, SEEK_CUR);
N_robot_joints = cfile_read_int(fp);
jointpos_read_n(Robot_joints, D1_MAX_ROBOT_JOINTS, fp);
N_weapon_types = cfile_read_int(fp);
//weapon_info_read_n(Weapon_info, D1_MAX_WEAPON_TYPES, fp, Piggy_hamfile_version);
cfseek(fp, D1_MAX_WEAPON_TYPES * D1_WEAPON_INFO_SIZE, SEEK_CUR);
N_powerup_types = cfile_read_int(fp);
powerup_type_info_read_n(Powerup_info, D1_MAX_POWERUP_TYPES, fp);
*/
/* in the following code are bugs, solved by hack
N_polygon_models = cfile_read_int(fp);
polymodel_read_n(Polygon_models, N_polygon_models, fp);
for (i=0; i<N_polygon_models; i++ )
polygon_model_data_read(&Polygon_models[i], fp);
*/cfseek(fp, 521490-160, SEEK_SET); // OK, I admit, this is a dirty hack
//bitmap_index_read_n(Gauges, D1_MAX_GAUGE_BMS, fp);
cfseek(fp, D1_MAX_GAUGE_BMS * sizeof(bitmap_index), SEEK_CUR);
/*
for (i = 0; i < D1_MAX_POLYGON_MODELS; i++)
Dying_modelnums[i] = cfile_read_int(fp);
for (i = 0; i < D1_MAX_POLYGON_MODELS; i++)
Dead_modelnums[i] = cfile_read_int(fp);
*/ cfseek(fp, D1_MAX_POLYGON_MODELS * 8, SEEK_CUR);
//bitmap_index_read_n(ObjBitmaps, D1_MAX_OBJ_BITMAPS, fp);
cfseek(fp, D1_MAX_OBJ_BITMAPS * sizeof(bitmap_index), SEEK_CUR);
for (i = 0; i < D1_MAX_OBJ_BITMAPS; i++)
cfseek(fp, 2, SEEK_CUR);//ObjBitmapPtrs[i] = cfile_read_short(fp);
//player_ship_read(&only_player_ship, fp);
cfseek(fp, sizeof(player_ship), SEEK_CUR);
/*Num_cockpits = */ cfile_read_int(fp);
//bitmap_index_read_n(cockpit_bitmap, D1_MAX_COCKPIT_BITMAPS, fp);
cfseek(fp, D1_MAX_COCKPIT_BITMAPS * sizeof(bitmap_index), SEEK_CUR);
/*
cfread( Sounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
cfread( AltSounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
*/cfseek(fp, D1_MAX_SOUNDS * 2, SEEK_CUR);
/*Num_total_object_types = */ cfile_read_int( fp );
/*
cfread( ObjType, sizeof(byte), D1_MAX_OBJTYPE, fp );
cfread( ObjId, sizeof(byte), D1_MAX_OBJTYPE, fp );
for (i=0; i<D1_MAX_OBJTYPE; i++ )
ObjStrength[i] = cfile_read_int( fp );
*/ cfseek(fp, D1_MAX_OBJTYPE * 6, SEEK_CUR);
/*First_multi_bitmap_num =*/ cfile_read_int(fp);
/*Reactors[0].n_guns = */ cfile_read_int( fp );
/*for (i=0; i<4; i++)
cfile_read_vector(&(Reactors[0].gun_points[i]), fp);
for (i=0; i<4; i++)
cfile_read_vector(&(Reactors[0].gun_dirs[i]), fp);
*/cfseek(fp, 8 * 12, SEEK_CUR);
/*exit_modelnum = */ cfile_read_int(fp);
/*destroyed_exit_modelnum = */ cfile_read_int(fp);
}
#endif // if 0, old code for reading descent 1 textures
//these values are the number of each item in the release of d2
//extra items added after the release get written in an additional hamfile
#define N_D2_ROBOT_TYPES 66
@ -727,7 +586,5 @@ int load_exit_models()
return 0;
}
atexit(bm_free_extra_objbitmaps);
return 1;
}

View file

@ -1,4 +1,3 @@
/* $Id: bm.h,v 1.1.1.1 2006/03/17 19:54:48 zicodxx Exp $ */
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
@ -71,8 +70,10 @@ extern int Dead_modelnums[];
extern int Marker_model_num;
// Initializes the palette, bitmap system...
void gamedata_close();
int gamedata_init();
void bm_close();
void bm_free_extra_objbitmaps();
// Initializes the Texture[] array of bmd_bitmap structures.
void init_textures();

View file

@ -607,8 +607,6 @@ int gamedata_read_tbl(int pc_shareware)
cfclose( InfoFile );
atexit(bm_close);
Assert(N_robot_types == Num_robot_ais); //should be one ai info per robot
verify_textures();
@ -679,33 +677,6 @@ void bm_read_alias()
Num_aliases++;
}
//--unused-- void dump_all_transparent_textures()
//--unused-- {
//--unused-- FILE * fp;
//--unused-- int i,j,k;
//--unused-- ubyte * p;
//--unused-- fp = fopen( "XPARENT.LST", "wt" );
//--unused-- for (i=0; i<Num_tmaps; i++ ) {
//--unused-- k = 0;
//--unused-- p = Textures[i]->bm_data;
//--unused-- for (j=0; j<64*64; j++ )
//--unused-- if ( (*p++)==255 ) k++;
//--unused-- if ( k ) {
//--unused-- fprintf( fp, "'%s' has %d transparent pixels\n", TmapInfo[i].filename, k );
//--unused-- }
//--unused-- }
//--unused-- fclose(fp);
//--unused-- }
void bm_close()
{
if (Installed)
{
Installed=0;
}
}
void set_lighting_flag(sbyte *bp)
{
if (vlighting < 0)

View file

@ -257,6 +257,9 @@ free_endlevel_data()
if (satellite_bm_instance.bm_data)
d_free(satellite_bm_instance.bm_data);
free_light_table();
free_height_array();
}
void init_endlevel()
@ -282,8 +285,6 @@ void init_endlevel()
generate_starfield();
atexit(free_endlevel_data);
terrain_bm_instance.bm_data = satellite_bm_instance.bm_data = NULL;
}

View file

@ -1,4 +1,3 @@
/* $Id: endlevel.h,v 1.1.1.1 2006/03/17 19:55:20 zicodxx Exp $ */
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
@ -14,7 +13,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
/*
*
* Header for newfile.c
* Header for endlevel.c
*
*/
@ -31,6 +30,7 @@ void render_endlevel_frame(fix eye_offset);
void render_external_scene();
void draw_exit_model();
void free_endlevel_data();
void init_endlevel();
extern grs_bitmap *terrain_bitmap; //*satellite_bitmap,*station_bitmap,

View file

@ -60,7 +60,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "ai.h"
#include "fuelcen.h"
#include "digi.h"
#include "ibitblt.h"
#include "u_mem.h"
#include "palette.h"
#include "morph.h"
@ -210,8 +209,6 @@ extern char Marker_input[];
//this is called once per game
void init_game()
{
atexit(close_game); //for cleanup
init_objects();
init_special_effects();

View file

@ -57,7 +57,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "ai.h"
#include "rbaudio.h"
#include "digi.h"
#include "ibitblt.h"
#include "u_mem.h"
#include "palette.h"
#include "morph.h"

View file

@ -165,8 +165,6 @@ void gamefont_init()
}
gamefont_choose_game_font(grd_curscreen->sc_canvas.cv_bitmap.bm_w,grd_curscreen->sc_canvas.cv_bitmap.bm_h);
atexit( gamefont_close );
}

View file

@ -31,7 +31,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "error.h"
#include "gr.h"
#include "palette.h"
#include "ibitblt.h"
#include "bm.h"
#include "player.h"
#include "render.h"

View file

@ -63,7 +63,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "digi.h"
#include "gamesave.h"
#include "scores.h"
#include "ibitblt.h"
#include "u_mem.h"
#include "palette.h"
#include "morph.h"

View file

@ -2725,7 +2725,7 @@ void draw_hud()
show_time();
#endif
#endif
if (PlayerCfg.ReticleOn && PlayerCfg.CockpitMode != CM_LETTERBOX && (!Use_player_head_angles))
if (PlayerCfg.ReticleOn && PlayerCfg.CockpitMode != CM_LETTERBOX)
show_reticle();
#ifdef NETWORK

View file

@ -131,10 +131,8 @@ unsigned descent_critical_deverror = 0;
unsigned descent_critical_errcode = 0;
extern int Network_allow_socket_changes;
extern void vfx_set_palette_sub(ubyte *);
extern void d_mouse_init(void);
extern void piggy_init_pigfile(char *filename);
extern void arch_init(void);
#define LINE_LEN 100
@ -248,8 +246,6 @@ char Auto_file[128] = "";
int main(int argc, char *argv[])
{
int t;
mem_init();
error_init(NULL, NULL);
PHYSFSX_init(argc, argv);
@ -316,36 +312,17 @@ int main(int argc, char *argv[])
PHYSFS_freeList(list);
}
// following lines are arch-code - but do we have to move it just for that?
if (SDL_Init(SDL_INIT_VIDEO)<0)
Error("SDL library initialisation failed: %s.",SDL_GetError());
arch_init();
#ifdef _WIN32
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
#endif
key_init();
digi_select_system( GameArg.SndDisableSdlMixer ? SDLAUDIO_SYSTEM : SDLMIXER_SYSTEM );
if (!GameArg.SndNoSound)
digi_init();
if (!GameArg.CtlNoMouse)
d_mouse_init();
if (!GameArg.CtlNoJoystick)
joy_init();
select_tmap(GameArg.DbgTexMap);
Lighting_on = 1;
con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
if ((t=gr_init(0))!=0) //doesn't do much
Error(TXT_CANT_INIT_GFX,t);
con_printf(CON_VERBOSE, "Going into graphics mode...\n");
gr_set_mode(Game_screen_mode);
@ -378,9 +355,6 @@ int main(int argc, char *argv[])
error_init(error_messagebox, NULL);
con_printf( CON_DEBUG, "\nInitializing 3d system..." );
g3_init();
con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
texmerge_init( 10 ); // 10 cache bitmaps
@ -468,9 +442,6 @@ int main(int argc, char *argv[])
case FMODE_EDITOR:
keyd_editor_mode = 1;
editor();
#ifdef __WATCOMC__
_harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
#endif
if ( Function_mode == FMODE_GAME ) {
Game_mode = GM_EDITOR;
editor_reset_stuff_on_level();
@ -484,13 +455,18 @@ int main(int argc, char *argv[])
}
WriteConfigFile();
show_order_form();
con_printf( CON_DEBUG, "\nCleanup...\n" );
error_init(NULL, NULL); // clear error func (won't have newmenu stuff loaded)
close_game();
texmerge_close();
gamedata_close();
gamefont_close();
free_text();
args_exit();
newmenu_close();
piggy_close();
SDL_Quit();
free_mission();
return(0); //presumably successful exit
}

View file

@ -578,10 +578,6 @@ mle *build_mission_list(int anarchy_mode)
sizeof(*mission_list),
(int (*)( const void *, const void * ))ml_sort_func);
//load_mission(0); //set built-in mission as default
atexit(free_mission);
return mission_list;
}

View file

@ -117,4 +117,6 @@ int load_mission_by_name (char *mission_name);
//Returns 1 if a mission was loaded.
int select_mission (int anarchy_mode, char *message);
void free_mission(void);
#endif

View file

@ -111,6 +111,8 @@ void NetDrvClose()
// -5 if error with getting internetwork address
int NetDrvInit( int socket_number )
{
static int cleanup = 0;
if (!driver)
return -1;
@ -145,7 +147,9 @@ int NetDrvInit( int socket_number )
NetDrvInstalled = 1;
atexit(NetDrvClose);
if (!cleanup)
atexit(NetDrvClose);
cleanup = 1;
return 0;
}

View file

@ -156,6 +156,9 @@ typedef struct DiskSoundHeader {
int offset;
} __pack__ DiskSoundHeader;
void free_bitmap_replacements();
void free_d1_tmap_nums();
/*
* reads a DiskBitmapHeader structure from a CFILE
*/
@ -1147,8 +1150,6 @@ int properties_init(void)
if (Piggy_hamfile_version >= 3)
snd_ok = read_sndfile();
// atexit(piggy_close);
return (ham_ok && snd_ok); //read ok
}
@ -1643,6 +1644,8 @@ void piggy_close()
hashtable_free( &AllBitmapsNames );
hashtable_free( &AllDigiSndNames );
free_bitmap_replacements();
free_d1_tmap_nums();
}
int piggy_does_bitmap_exist_slow( char * name )
@ -1799,8 +1802,6 @@ void load_bitmap_replacements(char *level_name)
texmerge_flush(); //for re-merging with new textures
}
atexit(free_bitmap_replacements);
}
/* calculate table to translate d1 bitmaps to current palette,
@ -1914,7 +1915,6 @@ void bm_read_d1_tmap_nums(CFILE *d1pig)
if (PHYSFS_eof(d1pig))
break;
}
atexit(free_d1_tmap_nums);
}
void remove_char( char * s, char c )
@ -1974,7 +1974,6 @@ void read_d1_tmap_nums_from_hog(CFILE *d1_pig)
MALLOC(d1_tmap_nums, short, D1_MAX_TMAP_NUM);
for (i = 0; i < D1_MAX_TMAP_NUM; i++)
d1_tmap_nums[i] = -1;
atexit(free_d1_tmap_nums);
while (cfgets (inputline, LINEBUF_SIZE, bitmaps)) {
char *arg;
@ -2110,7 +2109,6 @@ void load_d1_bitmap_replacements()
Warning(D1_PIG_LOAD_FAILED);
return;
}
atexit(free_bitmap_replacements);
next_bitmap = Bitmap_replacement_data;

View file

@ -735,9 +735,6 @@ int load_polygon_model(char *filename,int n_textures,grs_bitmap ***textures)
void init_polygon_models()
{
N_polygon_models = 0;
atexit((void (*)())free_polygon_models);
}
//compare against this size when figuring how far to place eye for picture

View file

@ -62,6 +62,7 @@ extern int N_polygon_models;
// array of names of currently-loaded models
extern char Pof_names[MAX_POLYGON_MODELS][13];
void free_polygon_models();
void init_polygon_models();
#ifndef DRIVE

View file

@ -147,82 +147,6 @@ void draw_outline(int nverts,g3s_point **pointlist)
}
#endif
grs_canvas * reticle_canvas = NULL;
void free_reticle_canvas()
{
if (reticle_canvas) {
d_free( reticle_canvas->cv_bitmap.bm_data );
d_free( reticle_canvas );
reticle_canvas = NULL;
}
}
extern void show_reticle(int force_big);
// Draw the reticle in 3D for head tracking
void draw_3d_reticle(fix eye_offset)
{
g3s_point reticle_points[4];
g3s_uvl uvl[4];
g3s_point *pointlist[4];
int i;
vms_vector v1, v2;
grs_canvas *saved_canvas;
int saved_interp_method;
// if (!Use_player_head_angles) return;
for (i=0; i<4; i++ ) {
pointlist[i] = &reticle_points[i];
uvl[i].l = MAX_LIGHT;
}
uvl[0].u = 0; uvl[0].v = 0;
uvl[1].u = F1_0; uvl[1].v = 0;
uvl[2].u = F1_0; uvl[2].v = F1_0;
uvl[3].u = 0; uvl[3].v = F1_0;
vm_vec_scale_add( &v1, &Viewer->pos, &Viewer->orient.fvec, F1_0*4 );
vm_vec_scale_add2(&v1,&Viewer->orient.rvec,eye_offset);
vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, -F1_0*1 );
vm_vec_scale_add2( &v2, &Viewer->orient.uvec, F1_0*1 );
g3_rotate_point(&reticle_points[0],&v2);
vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, +F1_0*1 );
vm_vec_scale_add2( &v2, &Viewer->orient.uvec, F1_0*1 );
g3_rotate_point(&reticle_points[1],&v2);
vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, +F1_0*1 );
vm_vec_scale_add2( &v2, &Viewer->orient.uvec, -F1_0*1 );
g3_rotate_point(&reticle_points[2],&v2);
vm_vec_scale_add( &v2, &v1, &Viewer->orient.rvec, -F1_0*1 );
vm_vec_scale_add2( &v2, &Viewer->orient.uvec, -F1_0*1 );
g3_rotate_point(&reticle_points[3],&v2);
if ( reticle_canvas == NULL ) {
reticle_canvas = gr_create_canvas(64,64);
if ( !reticle_canvas )
Error( "Couldn't malloc reticle_canvas" );
atexit( free_reticle_canvas );
reticle_canvas->cv_bitmap.bm_handle = 0;
reticle_canvas->cv_bitmap.bm_flags = BM_FLAG_TRANSPARENT;
}
saved_canvas = grd_curcanv;
gr_set_current_canvas(reticle_canvas);
gr_clear_canvas( TRANSPARENCY_COLOR ); // Clear to Xparent
show_reticle(1);
gr_set_current_canvas(saved_canvas);
saved_interp_method=Interpolation_method;
Interpolation_method = 3; // The best, albiet slowest.
g3_draw_tmap(4,pointlist,uvl,&reticle_canvas->cv_bitmap);
Interpolation_method = saved_interp_method;
}
extern fix Seismic_tremor_magnitude;
fix flash_scale;
@ -1627,7 +1551,6 @@ void build_object_lists(int n_segs)
}
}
int Use_player_head_angles = 0;
vms_angvec Player_head_angles;
extern int Num_tmaps_drawn;
@ -1686,13 +1609,7 @@ void render_frame(fix eye_offset, int window_num)
if (start_seg_num==-1)
start_seg_num = Viewer->segnum;
if (Viewer==ConsoleObject && Use_player_head_angles) {
vms_matrix headm,viewm;
vm_angles_2_matrix(&headm,&Player_head_angles);
vm_matrix_x_matrix(&viewm,&Viewer->orient,&headm);
g3_set_view_matrix(&Viewer_eye,&viewm,Render_zoom);
//@@} else if ((Cockpit_mode==CM_REAR_VIEW) && (Viewer==ConsoleObject)) {
} else if (Rear_view && (Viewer==ConsoleObject)) {
if (Rear_view && (Viewer==ConsoleObject)) {
vms_matrix headm,viewm;
Player_head_angles.p = Player_head_angles.b = 0;
Player_head_angles.h = 0x7fff;
@ -1726,9 +1643,6 @@ void render_frame(fix eye_offset, int window_num)
render_mine(start_seg_num, eye_offset, window_num);
if (Use_player_head_angles )
draw_3d_reticle(eye_offset);
g3_end_frame();
//RenderingType=0;

View file

@ -84,13 +84,6 @@ extern short Render_list[MAX_RENDER_SEGS];
extern int Render_only_bottom;
#endif
// Set the following to turn on player head turning
extern int Use_player_head_angles;
// If the above flag is set, these angles specify the orientation of the head
extern vms_angvec Player_head_angles;
//
// Routines for conditionally rotating & projecting points
//

View file

@ -117,7 +117,6 @@ void songs_init()
RBAInit();
set_redbook_volume(GameCfg.MusicVolume);
}
atexit(RBAStop); // stop song on exit
#endif // endof ifndef SHAREWARE, ie ifdef SHAREWARE
}

View file

@ -333,7 +333,8 @@ void render_terrain(vms_vector *org_point,int org_2dx,int org_2dy)
void free_height_array()
{
d_free(height_array);
if (height_array)
d_free(height_array);
}
void load_terrain(char *filename)
@ -350,8 +351,6 @@ void load_terrain(char *filename)
if (height_array)
d_free(height_array);
else
atexit(free_height_array); //first time
grid_w = height_bitmap.bm_w;
grid_h = height_bitmap.bm_h;
@ -442,8 +441,6 @@ void build_light_table()
if (light_array)
d_free(light_array);
else
atexit(free_light_table); //first time
MALLOC(light_array,ubyte,grid_w*grid_h);

View file

@ -1,4 +1,3 @@
/* $Id: terrain.h,v 1.1.1.1 2006/03/17 19:56:48 zicodxx Exp $ */
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
@ -22,6 +21,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#ifndef _TERRAIN_H
#define _TERRAIN_H
void free_light_table();
void free_height_array();
void load_terrain(char *filename);
void render_terrain(vms_vector *org, int org_i, int org_j);

View file

@ -83,7 +83,6 @@ int texmerge_init(int num_cached_textures)
Cache[i].bottom_bmp = NULL;
Cache[i].orient = -1;
}
atexit( texmerge_close );
return 1;
}

View file

@ -120,8 +120,6 @@ void load_text()
MALLOC(text,char,len);
atexit(free_text);
cfread(text,1,len,ifile);
cfclose(ifile);
@ -134,8 +132,6 @@ void load_text()
MALLOC(text,char,len);
atexit(free_text);
//fread(text,1,len,tfile);
p = text;
do {

View file

@ -685,5 +685,6 @@ extern char *Text_string[];
void decode_text_line(char *text_line); // decryption for bitmaps.tbl
void decode_text(char *text, int len); // decryption for briefings, etc.
void load_text(void);
void free_text();
#endif /* _TEXT_H */

View file

@ -256,6 +256,4 @@ void InitArgs( int argc,char **argv )
AppendIniArgs();
ReadCmdArgs();
atexit(args_exit);
}