
|
|
Author |
Message |
insurrectionman
DieHard Mutant


Joined: 07 May 2005
Last Visit: 04 Feb 2019
Topics: 87
Posts: 759
Location: Wisconsin

|
Posted: Wed May 03, 2006 6:23 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

 
|
|
Thanks for that, Dugtrio17 |
_________________ I'm back! I missed this community!
Youtube Channel: TreeSapThief
New Site: http://www.treesapthief.com
Twitter: @treesapthief
|
|
 |
lwmxynedtodth
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017
Topics: 38
Posts: 570
Location: Neverland

|
|
 |
Zombie_Plan
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 0:55 ago.
Topics: 103
Posts: 1640
Location: A hole in the wall

|
|
 |
lwmxynedtodth
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017
Topics: 38
Posts: 570
Location: Neverland

|
Posted: Tue Jul 11, 2006 3:48 am
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
Thanks! I add that soon, maybe with a debug-code or so.
Besides, great topic. As you know, i started over again - and now I'm first freeing memory.
And I ask Chris for the spotvis thing.
- lwmxynedtodth |
_________________ lwmxynedtodth (portfolio, blog and more)
Killer-suit: Masterminds
On a MMORPG trip.
|
|
 |
lwmxynedtodth
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017
Topics: 38
Posts: 570
Location: Neverland

|
Posted: Tue Jul 11, 2006 7:02 am
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
Huh! There is a difference between the code shown in the game, and calculated the F000-... way.
Calculated with F000-C922 = 9950 bytes, and the game says almost 12000.
The last way I got from the "merging statetypes" tutorial by BT.
I've read about it in this post, the last one by the game is the most right one.
But why the difference? And can it be solved?
Just a thought:
F000 = 61440 (total mem)
C922 = 51490 (mem by _bufferwidth)
2E80 = 11904 (mem by game)
Considering this, either F000 or C922 is wrong.
Wrong F000:
Unable to achieve
Wrong C922:
F000 minus ... = 2E80 (total minus used = free)
... = C180 = 49536 (mem used)
Maybe somebody can tell me that I am stupid, or maybe someone can tell me why
there is a difference. Or just don't
Greetz,
- lwmxynedtodth |
_________________ lwmxynedtodth (portfolio, blog and more)
Killer-suit: Masterminds
On a MMORPG trip.
|
|
 |
Adam Biser
Utility Developer


Joined: 06 Jun 2003
Last Visit: 06 Feb 2019
Topics: 46
Posts: 2318
Location: USA

|
|
 |
lwmxynedtodth
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017
Topics: 38
Posts: 570
Location: Neverland

|
Posted: Tue Jul 11, 2006 12:44 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
[quote=areyep_website]
The "EFAD" in there is the magic hexadecimal representation of the last used byte-address in the Data Group.
Now fire up Windows' calculator (CALC.EXE), put it in hexadecimal mode by checking the "HEX" checkbox, and perform the following subtraction:
F000 - EFAD
The calculator will show 53 as a result. Now check the "DEC" checkbox, and the result will change into 83. This means that there are 83 data bytes left.
[/quote]
Got this from the website of MCS and AReyeP, it is F000.
Very strange.
- lwmxynedtodth |
_________________ lwmxynedtodth (portfolio, blog and more)
Killer-suit: Masterminds
On a MMORPG trip.
Last edited by lwmxynedtodth on Tue Jul 11, 2006 1:23 pm; edited 1 time in total
|
|
 |
Adam Biser
Utility Developer


Joined: 06 Jun 2003
Last Visit: 06 Feb 2019
Topics: 46
Posts: 2318
Location: USA

|
|
 |
lwmxynedtodth
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017
Topics: 38
Posts: 570
Location: Neverland

|
Posted: Tue Jul 11, 2006 1:24 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
O rly?
I started over again with my source, just to make it better (and it had a weird bug).
It is like a challenge to me, freeing databytes.
- lwmxynedtodth |
_________________ lwmxynedtodth (portfolio, blog and more)
Killer-suit: Masterminds
On a MMORPG trip.
|
|
 |
Chris
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 14 Feb 2019
Topics: 55
Posts: 2169
Location: Canada

|
Posted: Tue Jul 11, 2006 6:45 pm
Subject: Re: [Help] Freeing Up More Memory
[ IP : Logged ]
|

  
|
|
lwmxynedtodth wrote:
Chris wrote:
Heh. Not sure if you'll find this interesting, but I managed to get 8192 more near bytes by combining spotvis with tilemap, and by compressing actorat into a byte.
Can someone post how to do this? I'm really interested. 'm now at 8286 databytes free.
Heh. Well, here's the way I used to get 4096 of that from changing actorat into a byte.
Just search the files below for "actorat" and change these 47 occurances in red... whee... get it? pizza cake!
In WL_ACT1.C:
::: CODE :::
switch (statinfo[type].type)
{
case block:
actorat[tilex][tiley] = 1; // consider it a blocking tile
::: CODE :::
lastdoorobj->vertical = vertical;
lastdoorobj->lock = lock;
lastdoorobj->action = dr_closed;
actorat[tilex][tiley] = 3; // consider it a solid wall
::: CODE :::
check = ACTLINK(actorat[tilex-1][tiley]);
if (check && ((check->x+MINDIST) >> TILESHIFT) == tilex )
return;
check = ACTLINK(actorat[tilex+1][tiley]);
if (check && ((check->x-MINDIST) >> TILESHIFT) == tilex )
return;
::: CODE :::
check = ACTLINK(actorat[tilex][tiley-1]);
if (check && ((check->y+MINDIST) >> TILESHIFT) == tiley )
return;
check = ACTLINK(actorat[tilex][tiley+1]);
if (check && ((check->y-MINDIST) >> TILESHIFT) == tiley )
return;
::: CODE :::
//
// make the door space solid
//
actorat[tilex][tiley]
= 3;
}
::: CODE :::
tilex = doorobjlist[door].tilex;
tiley = doorobjlist[door].tiley;
if ((actorat[tilex][tiley] > 3)
|| (player->tilex == tilex && player->tiley == tiley) )
::: CODE :::
case di_north:
if (actorat[checkx][checky-1])
{
SD_PlaySound (NOWAYSND);
return;
}
actorat[checkx][checky-1] = 2;
tilemap[checkx][checky-1] = oldtile;
break;
case di_east:
if (actorat[checkx+1][checky])
{
SD_PlaySound (NOWAYSND);
return;
}
actorat[checkx+1][checky] = 2;
tilemap[checkx+1][checky] = oldtile;
break;
case di_south:
if (actorat[checkx][checky+1])
{
SD_PlaySound (NOWAYSND);
return;
}
actorat[checkx][checky+1] = 2;
tilemap[checkx][checky+1] = oldtile;
break;
case di_west:
if (actorat[checkx-1][checky])
{
SD_PlaySound (NOWAYSND);
return;
}
actorat[checkx-1][checky] = 2;
tilemap[checkx-1][checky] = oldtile;
break;[/color]
::: CODE :::
//
// the tile can now be walked into
//
tilemap[pwallx][pwally] = 0;
actorat[pwallx][pwally] = 0;
*(mapsegs[0]+farmapylookup[pwally]+pwallx) = player->areanumber+AREATILE;
::: CODE :::
case di_north:
pwally--;
if (actorat[pwallx][pwally-1])
{
pwallstate = 0;
return;
}
actorat[pwallx][pwally-1] = 2;
tilemap[pwallx][pwally-1] = oldtile;
break;
case di_east:
pwallx++;
if (actorat[pwallx+1][pwally])
{
pwallstate = 0;
return;
}
actorat[pwallx+1][pwally] = 2;
tilemap[pwallx+1][pwally] = oldtile;
break;
case di_south:
pwally++;
if (actorat[pwallx][pwally+1])
{
pwallstate = 0;
return;
}
actorat[pwallx][pwally+1] = 2;
tilemap[pwallx][pwally+1] = oldtile;
break;
case di_west:
pwallx--;
if (actorat[pwallx-1][pwally])
{
pwallstate = 0;
return;
}
actorat[pwallx-1][pwally] = 2;
tilemap[pwallx-1][pwally] = oldtile;
break;
In WL_ACT2.C:
::: CODE :::
boolean ProjectileTryMove (objtype *ob)
{
int xl,yl,xh,yh,x,y;
//objtype *check;
long deltax,deltay;
::: CODE :::
//
// check for solid walls
//
for (y=yl;y<=yh;y++)
for (x=xl;x<=xh;x++)
{
if (actorat[x][y] && actorat[x][y] < 4)
return false;
}
::: CODE :::
new->flags |= FL_SHOOTABLE;
new->active = true;
actorat[new->tilex][new->tiley] = 0; // don't use original spot
::: CODE :::
case 3:
new->tiley++;
break;
}
actorat[new->tilex][new->tiley] = ACTNUM(new);
::: CODE :::
moveok:
xl = (ob->x-MINDIST) >> TILESHIFT;
xh = (ob->x+MINDIST) >> TILESHIFT;
yl = (ob->y-MINDIST) >> TILESHIFT;
yh = (ob->y+MINDIST) >> TILESHIFT;
for (y=yl ; y<=yh ; y++)
for (x=xl ; x<=xh ; x++)
{
tile = ACTLINK(actorat[x][y]);
if (!actorat[x][y])
continue;
if (actorat[x][y]<4)
return;
if (((objtype *)tile)->flags&FL_SHOOTABLE)
return;
::: CODE :::
boolean CheckPosition (objtype *ob)
{
int x,y,xl,yl,xh,yh;
//objtype *check;
::: CODE :::
//
// check for solid walls
//
for (y=yl;y<=yh;y++)
for (x=xl;x<=xh;x++)
{
if (actorat[x][y] && actorat[x][y] < 4)
return false;
}
In WL_AGENT.C:
::: CODE :::
//
// check for solid walls
//
for (y=yl;y<=yh;y++)
for (x=xl;x<=xh;x++)
{
if (actorat[x][y] && actorat[x][y] < 4)
return false;
}
//
// check for actors
//
if (yl>0)
yl--;
if (yh<MAPSIZE-1)
yh++;
if (xl>0)
xl--;
if (xh<MAPSTRETCH-1)
xh++;
for (y=yl;y<=yh;y++)
for (x=xl;x<=xh;x++)
{
check = ACTLINK(actorat[x][y]);
if (actorat[x][y] > 3
&& (check->flags & FL_SHOOTABLE) )
{
deltax = ob->x - check->x;
In WL_DEF.H:
::: CODE :::
#define SIGN(x) ((x)>0?1:-1)
#define ABS(x) ((int)(x)>0?(x):-(x))
#define LABS(x) ((long)(x)>0?(x):-(x))
#define ACTNUM(x) (((unsigned)x-obstart)/obsize)
#define ACTLINK(x) ((objtype *)((unsigned)x*obsize+obstart))
::: CODE :::
typedef enum {
ex_stillplaying,
ex_completed,
ex_died,
ex_warped,
ex_resetgame,
ex_loadedgame,
ex_victorious,
ex_abort,
ex_demodone,
ex_secretlevel
} exit_t;
#define obsize (sizeof(objtype))
#define obstart ((unsigned)objlist - obsize*3)
::: CODE :::
extern byte tilemap[MAPSIZE][MAPSIZE]; // wall values only
extern byte spotvis[MAPSIZE][MAPSIZE];
extern byte actorat[MAPSIZE][MAPSIZE];
In WL_GAME.C:
::: CODE :::
//
// copy the wall data to a data segment array
//
memset (tilemap,0,sizeof(tilemap));
memset (actorat,0,sizeof(actorat));
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile<AREATILE)
{
// solid wall
tilemap[x][y] = tile;
actorat[x][y] = 2;
}
else
{
// area floor
tilemap[x][y] = 0;
actorat[x][y] = 0;
}
}
::: CODE :::
//
// take out the ambush markers
//
map = mapsegs[0];
for (y=0;y<mapheight;y++)
for (x=0;x<mapwidth;x++)
{
tile = *map++;
if (tile == AMBUSHTILE)
{
tilemap[x][y] = 0;
actorat[x][y] = 0;
if (*map >= AREATILE)
tile = *map;
if (*(map-1-mapwidth) >= AREATILE)
tile = *(map-1-mapwidth);
if (*(map-1+mapwidth) >= AREATILE)
tile = *(map-1+mapwidth);
if ( *(map-2) >= AREATILE)
tile = *(map-2);
*(map-1) = tile;
}
}
In WL_PLAY.C:
::: CODE :::
byte tilemap[MAPSIZE][MAPSIZE]; // wall values only
byte spotvis[MAPSIZE][MAPSIZE];
byte actorat[MAPSIZE][MAPSIZE];
::: CODE :::
void DoActor (objtype *ob)
{
void (*think)(objtype *);
if (!ob->active && !areabyplayer[ob->areanumber])
return;
if (!(ob->flags&(FL_NONMARK|FL_NEVERMARK)) )
actorat[ob->tilex][ob->tiley] = 0;
::: CODE :::
if ( (ob->flags&FL_NONMARK) && actorat[ob->tilex][ob->tiley])
return;
actorat[ob->tilex][ob->tiley] = ACTNUM(ob);
return;
}
::: CODE :::
if ( (ob->flags&FL_NONMARK) && actorat[ob->tilex][ob->tiley])
return;
actorat[ob->tilex][ob->tiley] = ACTNUM(ob);
}
In WL_STATE.C:
::: CODE :::
new->x = ((long)tilex<<TILESHIFT)+TILEGLOBAL/2;
new->y = ((long)tiley<<TILESHIFT)+TILEGLOBAL/2;
new->dir = nodir;
actorat[tilex][tiley] = ACTNUM(new);
new->areanumber =
*(mapsegs[0] + farmapylookup[new->tiley]+new->tilex) - AREATILE;
::: CODE :::
#define CHECKDIAG(x,y) \
{ \
temp=actorat[x][y]; \
if (temp) \
{ \
if (temp<4) \
return false; \
if (ACTLINK(temp)->flags&FL_SHOOTABLE) \
return false; \
} \
}
#define CHECKSIDE(x,y) \
{ \
temp=actorat[x][y]; \
if (temp) \
{ \
if (temp<3) \
return false; \
if (temp == 3) \
doornum = (tilemap[x][y])&63; \
else if (ACTLINK(temp)->flags&FL_SHOOTABLE) \
return false; \
} \
}
::: CODE :::
gamestate.killcount++;
ob->flags &= ~FL_SHOOTABLE;
actorat[ob->tilex][ob->tiley] = 0;
ob->flags |= FL_NONMARK;
It looks complicating, but it really isn't in concept. Since tilemap and actorat uses alot of the same defines for textures/doors, you don't really need them in actorat. I just made 0 walk-through, 1 solid objects, 2 solid walls, 3 solid doors, and 4-255 guards (so technically, you can still have 250 actors in a level if you increase MAXACTORS). The ACTNUM and ACTLINK defines just link the guard number to their memory location and back, to avoid needing the pointer information directly on the actorat.
For the spotvis question, each tile takes 8-bits, but it really only needs one (true or false). What I did was just make both byte 0 and 254 walk-throughable on the tilemap (254 being the one used to keep track of where you can see to replace spotvis). You can probably just look at the memboost code for some ideas on how to do that if you really want (most of the tricky stuff was in WL_DRAW.C, from what I remember, but there is some asm and special things for opening doors involved). Eh, fun times.
lwmxynedtodth wrote:
I've read about it in this post, the last one by the game is the most right one.
But why the difference? And can it be solved?
Interesting. All I know for sure is that the way MCS describes is how much memory you have left before hitting the "Abnormal Program Termination" message, which is the only near memory related error I think I've ever encountered, so I always look at the end of the MAP file when I'm curious. I did get a "Program too big to fit in memory" message once when adding a ton of large functions into WL_MAIN.C, but haven't looked into why it did that yet, and if there's a certain number you can't go over before that message comes up. Maybe there's a third number we should be watching too?
wolf3dbreaker wrote:
aside from C0.ASM, WHACK_A.asm and WOLFHACK.C, I am using the spear version, What else can I delete? for memory conservation?
Quoting stuff from page 1 for the win. I'm pretty sure you can delete WL_TEXT.C if you're using Spear. |
Last edited by Chris on Wed Jul 12, 2006 3:26 am; edited 1 time in total
|
|
 |
Zombie_Plan
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 0:55 ago.
Topics: 103
Posts: 1640
Location: A hole in the wall

|
Posted: Wed Jul 12, 2006 3:25 am
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
The numbers pumped out by the code are the memory available upon loading the game while the numbers in the map file are produced by the compiler. The code is more reliable. BT said this somewhere in response to Haasboy. |
_________________ WolfSource - Your news source since the beginning of time (2019)
|
|
 |
Chris
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 14 Feb 2019
Topics: 55
Posts: 2169
Location: Canada

|
|
 |
lwmxynedtodth
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017
Topics: 38
Posts: 570
Location: Neverland

|
|
 |
Dugtrio17
Code Master

Joined: 11 Mar 2003
Last Visit: 03 Oct 2013
Topics: 49
Posts: 903
Location: Seattle

|
Posted: Thu Jul 13, 2006 5:04 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
EDIT: Scratch this whole post, I'm an idiot. I've really gotta test these things more... I got a "Priority without a sound" error message using this bit of brilliance... here's the post in quote form:
Some guy wrote:
Okay, I've tested this out and haven't found any problems, but if anybody finds any then let me know.
I'm using MCS' priority system, and I scored a good bit of free memory (about 128 bytes and half of the soundpriority[] array) by changing the soundpriority array to a character array (char soundpriority instead of int soundpriority). Then I made necessary changes to ID_SD.H...
::: CODE :::
typedef struct
{
longword length;
word priority;
} SoundCommon;
to
::: CODE :::
typedef struct
{
longword length;
char priority;
} SoundCommon;
...and ID_SD.C...
::: CODE :::
static void (*SoundUserHook)(void);
soundnames SoundNumber,DigiNumber;
word SoundPriority,DigiPriority;
int LeftPosition,RightPosition;
void interrupt (*t0OldService)(void);
long LocalTime;
word TimerRate;
to
::: CODE :::
static void (*SoundUserHook)(void);
soundnames SoundNumber,DigiNumber;
char SoundPriority,DigiPriority;
int LeftPosition,RightPosition;
void interrupt (*t0OldService)(void);
long LocalTime;
word TimerRate;
Though now that I think about it... I guess it'd be easier to replace all calls to a sound's priority from the file with a direct call to the soundpriorities array. Then again, that'd probably make a few headaches once going far enough to remove the s->priority variable... I dunno, I'm not at my thinking best at the moment.
|
_________________
|
|
 |
Guest

Last Visit:
|
Posted: Fri Sep 25, 2009 3:18 am
Subject: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
I've been trudging through a tougher level of mine, with many guards who emerge from more rooms with the same floor code. But sometimes the game crashes without clearing the screen, still on 320x200, printing garbled Divide Error, followed by the command prompt. DOSBox locks up, but probably it's DOSBox. Is Divide Error caused by memory overflow? Notably I only added a function called by Playloop (or PlayLoop?), that checks if a global tag variable is on, so it can push properly tagged walls (via PushWall)... |
|
|
 |
Tricob
Moderator


Joined: 14 Mar 2005
Last Visit: 16:48 ago.
Topics: 165
Posts: 8330
Location: Neo-traditions, Inc.

|
Posted: Fri Sep 25, 2009 9:25 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
No, a Divide Error has nothing to do with memory overflow. AFAIK, the only way you get an error when dividing is if you're dividing a number by Zero. |
|
|
 |
Guest

Last Visit:
|
Posted: Sat Sep 26, 2009 1:59 am
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
Which I didn't. The error appeared randomly. But I didn't add myself any division myself. I could investigate, if it continues to appear. But it annoys the hell out of me that it crashes on /0. W/e. I posted this here because searches of it showed posts with APT issues too... |
|
|
 |
Codetech84
Code Master

Joined: 12 Mar 2003
Last Visit: 27 Aug 2018
Topics: 22
Posts: 1284
Location: Rauma - Finland

|
Posted: Sat Sep 26, 2009 3:03 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
Tricob wrote:
No, a Divide Error has nothing to do with memory overflow. AFAIK, the only way you get an error when dividing is if you're dividing a number by Zero.
So you know that when memory leak occurs it will overflow the write to the next address, or something along those lines. So basically if you're unlucky enough, the variable you're dividing some other variable with, might get an arbitrary value from memory leak which could cause a divide by zero error randomly.
What causes weird, unpredictable and random glitches even more, are uninitialized variables. Something like this for example where "c" is unitialized:
::: CODE :::
int a,b=1,c;
a = b/c;
|
_________________ Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
|
|
 |
Tricob
Moderator


Joined: 14 Mar 2005
Last Visit: 16:48 ago.
Topics: 165
Posts: 8330
Location: Neo-traditions, Inc.

|
Posted: Sat Sep 26, 2009 6:10 pm
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

  
|
|
True enough, Codetech. And if you misspell a variable just once, you could end up with the Divide By Zero scenario as well, for the reasons you've just posted.  |
|
|
 |
bitshifter
Can I Play Daddy

Joined: 16 Dec 2009
Last Visit: 01 Jul 2015
Topics: 7
Posts: 33
Location: Massachusetts

|
|
 |
lemm
Registered User


Joined: 04 Feb 2012
Last Visit: 13 Oct 2012
Topics: None
Posts: 2

|
Posted: Mon Feb 06, 2012 7:52 am
Subject: Re: [Info] Freeing Up Memory - A Must Read!
[ IP : Logged ]
|

 
|
|
Thanks for memboost.zip. This was extraordinarily useful. I would like to know if anyone has kept this up to date and added any more bug fixes / memory savers. |
|
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum
|
|
You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group
|