Implemented another approach of storing of line numbers.

Good news: one can load old savegame.
Bad news: the code takes twice the space then before.

I had change it to this way because:
1.Opcodes could be interpreted as pointers.
2.Some CON command aren’t compiled in the code and cause problems too.
3.Ideal method would be converting pointers to offsets related to the script(as TerminX suggested). But it’s quite difficult to do and the next snapshot might be unstable(crashy).


git-svn-id: https://svn.eduke32.com/eduke32@975 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hnt_ts 2008-08-14 17:18:16 +00:00
parent 1ce5d73762
commit 92b3e13d3d
3 changed files with 13 additions and 7 deletions

View file

@ -954,7 +954,7 @@ static int increasescriptsize(int size)
//initprintf("offset: %d\n",(unsigned)(scriptptr-script));
g_ScriptSize = size;
initprintf("Increasing script buffer size to %d bytes...\n",g_ScriptSize);
newscript = (intptr_t *)Brealloc(script, g_ScriptSize * sizeof(intptr_t));
newscript = (intptr_t *)Brealloc(script, g_ScriptSize * sizeof(intptr_t) * 2);
if (newscript == NULL)
{
@ -1419,7 +1419,8 @@ static int transword(void) //Returns its code #
{
if (Bstrcmp(tempbuf,keyw[i]) == 0)
{
*scriptptr = i + (line_number<<12);
*scriptptr = i;
script[scriptptr-script+g_ScriptSize] = line_number;
textptr += l;
scriptptr++;
if (!(error || warning) && g_ScriptDebug)
@ -5273,7 +5274,8 @@ void loadefs(const char *filenam)
// clearbufbyte(script,sizeof(script),0l); // JBF 20040531: yes? no?
if (script != NULL)
Bfree(script);
script = Bcalloc(1,g_ScriptSize * sizeof(intptr_t));
script = Bcalloc(1,g_ScriptSize * sizeof(intptr_t) * 2);
clearbufbyte(&script[g_ScriptSize],g_ScriptSize * sizeof(intptr_t),0L);
labelcnt = defaultlabelcnt = 0;
scriptptr = script+1;

View file

@ -4504,8 +4504,8 @@ static int parse(void)
// Bsprintf(g_szBuf,"Parsing: %d",*insptr);
// AddLog(g_szBuf);
line_num = tw>>12;
g_tw = tw &= 0xFFF;
line_num = insptr[g_ScriptSize];
g_tw = tw;
switch (tw)
{

View file

@ -127,6 +127,7 @@ int loadplayer(int spot)
int fil, bv, i, x;
intptr_t j;
int32 nump;
int codeextra=0;
strcpy(fn, "egam0.sav");
strcpy(mpfn, "egamA_00.sav");
@ -275,8 +276,9 @@ int loadplayer(int spot)
if (kdfread(&scriptptrs[0],sizeof(scriptptrs),g_ScriptSize,fil) != g_ScriptSize) goto corrupt;
if (script != NULL)
Bfree(script);
if (bv>=183)codeextra=g_ScriptSize;
script = Bcalloc(1,g_ScriptSize * sizeof(intptr_t));
if (kdfread(&script[0],sizeof(script),g_ScriptSize,fil) != g_ScriptSize) goto corrupt;
if (kdfread(&script[0],sizeof(script),g_ScriptSize+codeextra,fil) != g_ScriptSize) goto corrupt;
for (i=0;i<g_ScriptSize;i++)
if (scriptptrs[i])
{
@ -530,6 +532,7 @@ int saveplayer(int spot)
char *fnptr, *scriptptrs;
FILE *fil;
int bv = BYTEVERSION;
int codeextra=0;
strcpy(fn, "egam0.sav");
strcpy(mpfn, "egamA_00.sav");
@ -637,6 +640,7 @@ int saveplayer(int spot)
dfwrite(&g_ScriptSize,sizeof(g_ScriptSize),1,fil);
scriptptrs = Bcalloc(1, g_ScriptSize * sizeof(scriptptrs));
if (bv>=183)codeextra=g_ScriptSize;
for (i=0;i<g_ScriptSize;i++)
{
if ((intptr_t)script[i] >= (intptr_t)(&script[0]) && (intptr_t)script[i] < (intptr_t)(&script[g_ScriptSize]))
@ -649,7 +653,7 @@ int saveplayer(int spot)
}
dfwrite(&scriptptrs[0],sizeof(scriptptrs),g_ScriptSize,fil);
dfwrite(&script[0],sizeof(script),g_ScriptSize,fil);
dfwrite(&script[0],sizeof(script),g_ScriptSize+codeextra,fil);
for (i=0;i<g_ScriptSize;i++)
if (scriptptrs[i])