Skip to content

Commit

Permalink
Shrink mapseg.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://jay/var/svn/wolf/trunk@69 32837ae5-38f0-4cfd-8401-3ff76d8497c4
  • Loading branch information
paul committed Aug 4, 2007
1 parent c08e234 commit 2a90e2c
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 62 deletions.
65 changes: 30 additions & 35 deletions id_ca.c
Expand Up @@ -25,8 +25,8 @@ maptype *mapheaderseg[NUMMAPS];

myint mapon;

word mapseg0[MAPSIZE * MAPSIZE];
word mapseg1[MAPSIZE * MAPSIZE];
ms0 mapseg0[MAPSIZE * MAPSIZE];
ms1 mapseg1[MAPSIZE * MAPSIZE];
#ifdef ENABLE_AUDIO
static byte *audiosegs[NUMSNDCHUNKS];
#endif
Expand Down Expand Up @@ -280,28 +280,28 @@ void CAL_CarmackExpand(const byte *source, word *dest, word length)
======================
=
= CA_RLEWexpand
= length is EXPANDED length
=
======================
*/

void CA_RLEWexpand(const word *source, word *dest, long length, word rlewtag)
void CA_RLEWexpand(const word *source, byte *dest, int offset)
{
word value, count, i;
word *end = dest + length / 2;
word rlewtag = RLEWtag;
byte *end = dest + 64 * 64;

/* expand it */
do {
value = *source++;

if (value != rlewtag) {
/* uncompressed */
*dest++ = value;
*dest++ = value - offset;
} else {
/* compressed string */
count = *source++;

value = *source++;
value = *source++ - offset;
for (i = 0; i < count; i++)
*dest++ = value;
}
Expand Down Expand Up @@ -715,52 +715,47 @@ void CA_CacheGrChunk(myint chunk)
======================
*/

void CA_CacheMap(myint mapnum)
void CA_CacheMap(myint mapnum, myint plane)
{
long pos,compressed;
myint plane;
byte *source;
memptr buffer2seg;
long expanded;

mapon = mapnum;

/* load the planes into the already allocated buffers */
/* load plane into the already allocated buffers */

for (plane = 0; plane < MAPPLANES; plane++)
{
#ifdef ENABLE_PRECOMPILE
pos = mapheaderseg[mapnum].planestart[plane];
compressed = mapheaderseg[mapnum].planelength[plane];
pos = mapheaderseg[mapnum].planestart[plane];
compressed = mapheaderseg[mapnum].planelength[plane];
#else
pos = mapheaderseg[mapnum]->planestart[plane];
compressed = mapheaderseg[mapnum]->planelength[plane];
pos = mapheaderseg[mapnum]->planestart[plane];
compressed = mapheaderseg[mapnum]->planelength[plane];
#endif

ReadSeek(maphandle, pos, SEEK_SET);
MM_GetPtr((void *)&source, compressed);
ReadSeek(maphandle, pos, SEEK_SET);

MM_GetPtr((void *)&source, compressed);

ReadBytes(maphandle, (byte *)source, compressed);
expanded = source[0] | (source[1] << 8);
MM_GetPtr(&buffer2seg, expanded);
ReadBytes(maphandle, (byte *)source, compressed);

expanded = source[0] | (source[1] << 8);
MM_GetPtr(&buffer2seg, expanded);

/* NOTE: CarmackExpand implicitly fixes endianness, a RLEW'd only map
would (likely) need to be swapped in CA_RLEWexpand
Wolfenstein 3D/Spear of Destiny maps are always Carmack'd so this
case is OK. CA_RLEWexpand would need to be adjusted for Blake Stone
and the like.
would (likely) need to be swapped in CA_RLEWexpand
Wolfenstein 3D/Spear of Destiny maps are always Carmack'd so this
case is OK. CA_RLEWexpand would need to be adjusted for Blake Stone
and the like.
*/
CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded);
MM_FreePtr((void *)&source);
CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded);
MM_FreePtr((void *)&source);

expanded = 64*64*2;
CA_RLEWexpand(((word *)buffer2seg)+1,
plane ? mapseg1 : mapseg0, expanded, RLEWtag);
MM_FreePtr(&buffer2seg);
}
CA_RLEWexpand(((word *)buffer2seg)+1, plane ? mapseg1 : mapseg0,
plane ? 16 : 0);
MM_FreePtr(&buffer2seg);
}

/* ======================================================================== */
Expand Down
7 changes: 4 additions & 3 deletions id_ca.h
Expand Up @@ -22,9 +22,10 @@ typedef struct

extern myint mapon;

typedef word ms0;
typedef byte ms0;
typedef byte ms1;
extern ms0 mapseg0[64 * 64];
extern word mapseg1[64 * 64];
extern ms1 mapseg1[64 * 64];
#ifdef ENABLE_PRECOMPILE
extern const maptype mapheaderseg[NUMMAPS];
extern const word RLEWtag;
Expand All @@ -49,7 +50,7 @@ void CA_UnCacheAudioChunk(myint chunk);
#endif
void CA_LoadAllSounds();

void CA_CacheMap(myint mapnum);
void CA_CacheMap(myint mapnum, myint plane);
void CA_CacheGrChunk(myint chunk);
void CA_UnCacheGrChunk(myint chunk);

Expand Down
14 changes: 7 additions & 7 deletions wl_act1.c
Expand Up @@ -322,7 +322,7 @@ void InitDoorList()

void SpawnDoor(myint tilex, myint tiley, boolean vertical, myint lock)
{
word *map;
ms0 *map;

if (doornum == 64)
Quit ("64+ doors on level!");
Expand All @@ -341,7 +341,7 @@ void SpawnDoor(myint tilex, myint tiley, boolean vertical, myint lock)
// for door sides
//
tilemap[tilex][tiley] = doornum | 0x80;
map = (word *)(mapseg0 + farmapylookup(tiley)+tilex);
map = (mapseg0 + farmapylookup(tiley)+tilex);
if (vertical)
{
*map = *(map-1); // set area number
Expand Down Expand Up @@ -537,7 +537,7 @@ void DoorOpen (myint door)
void DoorOpening(myint door)
{
myint area1,area2;
word *map;
ms0 *map;
long position;

position = doorposition[door];
Expand All @@ -546,7 +546,7 @@ void DoorOpening(myint door)
//
// door is just starting to open, so connect the areas
//
map = (word *)(mapseg0 + farmapylookup(doorobjlist[door].tiley)
map = (mapseg0 + farmapylookup(doorobjlist[door].tiley)
+doorobjlist[door].tilex);

if (doorobjlist[door].vertical)
Expand Down Expand Up @@ -600,7 +600,7 @@ void DoorOpening(myint door)
void DoorClosing(myint door)
{
myint area1,area2;
word *map;
ms0 *map;
long position;
myint tilex,tiley;

Expand Down Expand Up @@ -629,7 +629,7 @@ void DoorClosing(myint door)

doorobjlist[door].action = dr_closed;

map = (word *)(mapseg0 + farmapylookup(doorobjlist[door].tiley)
map = (mapseg0 + farmapylookup(doorobjlist[door].tiley)
+doorobjlist[door].tilex);

if (doorobjlist[door].vertical)
Expand Down Expand Up @@ -768,7 +768,7 @@ void PushWall(myint checkx, myint checky, myint dir)
pwallstate = 1;
pwallpos = 0;
tilemap[pwallx][pwally] |= 0xc0;
*(mapseg1+farmapylookup(pwally)+pwallx) = 0; // remove P tile info
setmapspecial(pwallx, pwally, 0);

SD_PlaySound(PUSHWALLSND);
}
Expand Down
10 changes: 5 additions & 5 deletions wl_act2.c
Expand Up @@ -298,7 +298,7 @@ void T_Projectile(objtype *ob)

void SpawnStand (enemy_t which, myint tilex, myint tiley, myint dir)
{
word *map, tile = 0;
ms0 *map, tile = 0;

switch (which)
{
Expand Down Expand Up @@ -592,12 +592,12 @@ void SelectPathDir(objtype *ob)
{
unsigned spot;

spot = *(mapseg1+farmapylookup(ob->tiley)+ob->tilex)-ICONARROWS;

if (spot<8)
spot = getmapspecial(ob->tilex, ob->tiley);
if (spot & ms_arrow)
{
// new direction
ob->dir = spot;
ob->dir = spot & 7;
}

ob->distance = TILEGLOBAL;
Expand Down
6 changes: 3 additions & 3 deletions wl_agent.c
Expand Up @@ -871,7 +871,7 @@ void Thrust(myint angle, long speed)
offset = farmapylookup(player->tiley)+player->tilex;
player->areanumber = *(mapseg0 + offset) -AREATILE;

if (*(mapseg1 + offset) == EXITTILE)
if (getmapspecial(player->tilex, player->tiley) == ms_exit)
VictoryTile();
}

Expand Down Expand Up @@ -956,7 +956,7 @@ void Cmd_Use()
}

doornum = tilemap[checkx][checky];
if (*(mapseg1+farmapylookup(checky)+checkx) == PUSHABLETILE)
if (getmapspecial(checkx, checky) == ms_pushable)
{
//
// pushable wall
Expand Down Expand Up @@ -1015,7 +1015,7 @@ void SpawnPlayer (myint tilex, myint tiley, myint dir)
player->tilex = tilex;
player->tiley = tiley;
player->areanumber =
*(mapseg0 + farmapylookup(player->tiley)+player->tilex);
*(mapseg0 + farmapylookup(player->tiley)+player->tilex) - AREATILE;
player->x = ((long)tilex<<TILESHIFT)+TILEGLOBAL/2;
player->y = ((long)tiley<<TILESHIFT)+TILEGLOBAL/2;
player->state = s_player;
Expand Down
25 changes: 25 additions & 0 deletions wl_def.h
Expand Up @@ -743,6 +743,31 @@ extern long spearx,speary;
extern unsigned spearangle;
extern boolean spearflag;

#define ms_pushable 1
#define ms_exit 2
#define ms_arrow 8

extern byte mapspecial[(MAPSIZE * MAPSIZE) >> 1];
static inline int getmapspecial(int x, int y)
{
int n = (x << 5) + (y >> 1);
if (y & 1)
return mapspecial[n] & 0xf;
else
return mapspecial[n] >> 4;
}

static inline void setmapspecial(int x, int y, int newval)
{
int n = (x << 5) + (y >> 1);
uint8_t val;
val = mapspecial[n];
if (y & 1)
val = (val & 0xf0) | newval;
else
val = (val & 0xf) | (newval << 4);
mapspecial[n] = val;
}

void ScanInfoPlane (void);
void SetupGameLevel (void);
Expand Down
36 changes: 27 additions & 9 deletions wl_game.c
Expand Up @@ -15,6 +15,8 @@ long spearx,speary;
unsigned spearangle;
boolean spearflag;

byte mapspecial[(MAPSIZE * MAPSIZE) >> 1];

/* ELEVATOR BACK MAPS - REMEMBER (-1)!! */
#ifndef SPEAR
static const myint ElevatorBackTo[]={ 1, 1, 7, 3, 5, 3};
Expand Down Expand Up @@ -49,13 +51,13 @@ void ScanInfoPlane()
{
unsigned x,y;
myint tile;
word *start;
ms1 *start;

start = mapseg1;
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *start++;
tile = (word)*(start++) + 16;
if (!tile)
continue;

Expand Down Expand Up @@ -131,12 +133,27 @@ void ScanInfoPlane()
SpawnStatic(x,y,tile-23);
break;

case 90: /* ICONARROWS */
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
setmapspecial(x, y, (tile - 90) | ms_arrow);
break;
//
// P wall
//
case 98:
case 98: /* PUSHABLETILE */
if (!loadedgame)
gamestate.secrettotal++;
setmapspecial(x, y, ms_pushable);
break;

case 99: /* EXITTILE */
setmapspecial(x, y, ms_exit);
break;

//
Expand Down Expand Up @@ -454,7 +471,7 @@ void ScanInfoPlane()
void SetupGameLevel()
{
myint x,y;
word *map,tile;
ms0 *map,tile;

if (!loadedgame) {
gamestate.TimeCount =
Expand All @@ -471,9 +488,6 @@ void SetupGameLevel()
else
US_InitRndT(true);

/* load the level */
CA_CacheMap(gamestate.mapon+10*gamestate.episode);

#ifndef ENABLE_PRECOMPILE
if ((mapheaderseg[mapon]->width != 64) || (mapheaderseg[mapon]->height != 64))
Quit("Map not 64*64!");
Expand All @@ -485,6 +499,11 @@ void SetupGameLevel()
memset(actorat, 0, sizeof(actorat));
memset(objactor, 0, sizeof(objactor));

/* spawn actors */
/* load the level */
CA_CacheMap(gamestate.mapon+10*gamestate.episode, 1);
CA_CacheMap(gamestate.mapon+10*gamestate.episode, 0);

/* copy the wall data to a data segment array */
map = mapseg0;
for (y = 0; y < mapheight; y++)
Expand All @@ -495,7 +514,6 @@ void SetupGameLevel()
set_wall_at(x, y, tile);
} else { /* area floor */
tilemap[x][y] = 0;
clear_actor(x, y);
}
}

Expand Down Expand Up @@ -534,8 +552,8 @@ void SetupGameLevel()
}
}

/* spawn actors */
ScanInfoPlane();


/* take out the ambush markers */
map = mapseg0;
Expand Down

0 comments on commit 2a90e2c

Please sign in to comment.