diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 6ef4dfea7..4a4d9dd18 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,11 @@ +October 28, 2006 (Changes by Graf Zahl) +- Changed parameter storage for states to use a separate member variable + instead of forcing it into misc1/misc2. Although this increases the EXE's + size by 30k it has several advantages: + * State parameters are no longer limited to 65535 for all states combined. + * State parameters can be used with long durations. + * Some special handling in the weapon state set functions can be removed. + October 26, 2006 - Removed A_JumpSet and merged its functionality with A_Jump by turning A_Jump into a varargs function. diff --git a/src/info.h b/src/info.h index 341247515..4a5b2b0eb 100644 --- a/src/info.h +++ b/src/info.h @@ -78,7 +78,6 @@ #include "doomdef.h" #include "name.h" -const BYTE SF_STATEPARAM = 0x20; const BYTE SF_FULLBRIGHT = 0x40; const BYTE SF_BIGTIC = 0x80; @@ -105,10 +104,11 @@ struct FState BYTE Frame; actionf_p Action; FState *NextState; + int ParameterIndex; inline int GetFrame() const { - return Frame & ~(SF_FULLBRIGHT|SF_BIGTIC|SF_STATEPARAM); + return Frame & ~(SF_FULLBRIGHT|SF_BIGTIC); } inline int GetFullbright() const { @@ -138,17 +138,6 @@ struct FState { return Misc2; } - inline int GetMisc1_2() const - { - return ((*(DWORD *)&Tics) >> 8) & 0xFFFF; - } - inline void SetMisc1_2 (WORD val) - { - DWORD x = *(DWORD *)&Tics; - x &= 0xFF0000FF; - x |= (DWORD)val << 8; - *(DWORD *)&Tics = x; - } inline FState *GetNextState() const { return NextState; diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 58517aa3f..b976be436 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -91,33 +91,15 @@ void P_SetPsprite (player_t *player, int position, FState *state) else psp->tics = state->GetTics(); // could be 0 - if (!(state->Frame & SF_STATEPARAM)) - { - if (state->GetMisc1()) - { // Set coordinates. - psp->sx = state->GetMisc1()<GetMisc2()) - { - psp->sy = state->GetMisc2()<GetMisc1()) + { // Set coordinates. + psp->sx = state->GetMisc1()<GetMisc2()) { - unsigned int index = state->GetMisc1_2(); + psp->sy = state->GetMisc2()< 0 && index < StateParameters.Size() - 2) - { - if (StateParameters[index]) - { // Set coordinates. - psp->sx = (fixed_t)StateParameters[index] << FRACBITS; - } - if (StateParameters[index+1]) - { - psp->sy = (fixed_t)StateParameters[index+1] << FRACBITS; - } - } - } if (state->GetAction()) { // The parameterized action functions need access to the current state and @@ -163,31 +145,13 @@ void P_SetPspriteNF (player_t *player, int position, FState *state) psp->state = state; psp->tics = state->GetTics(); // could be 0 - if (!(state->Frame & SF_STATEPARAM)) - { - if (state->GetMisc1()) - { // Set coordinates. - psp->sx = state->GetMisc1()<GetMisc2()) - { - psp->sy = state->GetMisc2()<GetMisc1()) + { // Set coordinates. + psp->sx = state->GetMisc1()<GetMisc2()) { - unsigned int index = state->GetMisc1_2(); - if (index > 0 && index < StateParameters.Size()-2) - { - if (StateParameters[index]) - { // Set coordinates. - psp->sx = (fixed_t)StateParameters[index] << FRACBITS; - } - if (StateParameters[index+1]) - { - psp->sy = (fixed_t)StateParameters[index+1] << FRACBITS; - } - } + psp->sy = state->GetMisc2()<state->GetNextState(); } while (!psp->tics); // An initial state of 0 could cycle through. diff --git a/src/thingdef.cpp b/src/thingdef.cpp index c98205f56..a7fb51876 100644 --- a/src/thingdef.cpp +++ b/src/thingdef.cpp @@ -1300,21 +1300,10 @@ int PrepareStateParameters(FState * state, int numparams) int paramindex=StateParameters.Size(); int i, v; - if (state->Frame&SF_BIGTIC) - { - SC_ScriptError("You cannot use a parameterized code pointer with a state duration larger than 254!"); - } - - v=state->Misc1; - StateParameters.Push(v); - v=state->Misc2; - StateParameters.Push(v); v=0; for(i=0;iSetMisc1_2(paramindex); - state->Frame|=SF_STATEPARAM; - - return paramindex+2; // return the index of the first actual state parameter + state->ParameterIndex = paramindex+1; + return paramindex; } //========================================================================== @@ -1452,13 +1441,30 @@ static void RetargetStates (intptr_t count, const char *target, const PClass *cl } } +//========================================================================== +// +// Reads a state label that may contain '.'s. +// processes a state block +// +//========================================================================== +static void ParseStateString(char * statestring) +{ + SC_MustGetString(); + strncpy (statestring, sc_String, 255); + while (SC_CheckString (".")) + { + SC_MustGetString (); + strcat (statestring, "."); + strcat (statestring, sc_String); + } +} + //========================================================================== // // ProcessStates // processes a state block // //========================================================================== - static int ProcessStates(FActorInfo * actor, AActor * defaults, Baggage &bag) { char statestring[256]; @@ -1472,20 +1478,15 @@ static int ProcessStates(FActorInfo * actor, AActor * defaults, Baggage &bag) statestring[255] = 0; ChkBraceOpn(); + SC_SetEscape(false); // disable escape sequences in the state parser while (!TestBraceCls() && !sc_End) { memset(&state,0,sizeof(state)); - SC_MustGetString(); - if (SC_Compare("GOTO")) + ParseStateString(statestring); + if (!stricmp(statestring, "GOTO")) { -do_goto: SC_MustGetString(); - strncpy (statestring, sc_String, 255); - if (SC_CheckString (".")) - { - SC_MustGetString (); - strcat (statestring, "."); - strcat (statestring, sc_String); - } +do_goto: + ParseStateString(statestring); if (SC_CheckString ("+")) { SC_MustGetNumber (); @@ -1506,7 +1507,7 @@ do_goto: SC_MustGetString(); SC_ScriptError("GOTO before first state"); } } - else if (SC_Compare("STOP")) + else if (!stricmp(statestring, "STOP")) { do_stop: if (laststate!=NULL) @@ -1523,7 +1524,7 @@ do_stop: continue; } } - else if (SC_Compare("WAIT") || SC_Compare("FAIL")) + else if (!stricmp(statestring, "WAIT") || !stricmp(statestring, "FAIL")) { if (!laststate) { @@ -1532,7 +1533,7 @@ do_stop: } laststate->NextState=(FState*)-2; } - else if (SC_Compare("LOOP")) + else if (!stricmp(statestring, "LOOP")) { if (!laststate) { @@ -1545,11 +1546,7 @@ do_stop: { char * statestrp; - strncpy(statestring, sc_String, 255); - SC_SetEscape(false); - SC_MustGetString(); // this can read the frame string so escape characters have to be disabled - SC_SetEscape(true); - + SC_MustGetString(); if (SC_Compare (":")) { laststate = NULL; @@ -1560,16 +1557,16 @@ do_stop: if (stp) *stp=(FState *) (count+1); else SC_ScriptError("Unknown state label %s", statestring); - SC_MustGetString (); - if (SC_Compare ("Goto")) + + ParseStateString(statestring); + if (!stricmp(statestring, "GOTO")) { goto do_goto; } - else if (SC_Compare("Stop")) + else if (!stricmp(statestring, "STOP")) { goto do_stop; } - strncpy(statestring, sc_String, 255); SC_MustGetString (); } while (SC_Compare (":")); // continue; @@ -1584,9 +1581,8 @@ do_stop: memcpy(state.sprite.name, statestring, 4); state.Misc1=state.Misc2=0; - SC_SetEscape(false); - SC_MustGetString(); // This reads the frame string so escape characters have to be disabled - SC_SetEscape(true); + state.ParameterIndex=0; + SC_MustGetString(); strncpy(statestring, sc_String + 1, 255); statestrp = statestring; state.Frame=(*sc_String&223)-'A'; @@ -1716,7 +1712,9 @@ do_stop: case 'm': // Actor name case 'T': case 't': // String + SC_SetEscape(true); SC_MustGetString(); + SC_SetEscape(false); v = (int)(sc_String[0] ? FName(sc_String) : NAME_None); break; @@ -1825,7 +1823,7 @@ endofstate: frame=0; } - state.Frame=(state.Frame&(SF_FULLBRIGHT|SF_BIGTIC|SF_STATEPARAM))|frame; + state.Frame=(state.Frame&(SF_FULLBRIGHT|SF_BIGTIC))|frame; StateArray.Push(state); count++; } @@ -1837,6 +1835,7 @@ endofstate: { SC_ScriptError("A_Jump offset out of range in %s", actor->Class->TypeName.GetChars()); } + SC_SetEscape(true); // re-enable escape sequences return count; } diff --git a/src/thingdef_codeptr.cpp b/src/thingdef_codeptr.cpp index 4bb52351c..2be39b187 100644 --- a/src/thingdef_codeptr.cpp +++ b/src/thingdef_codeptr.cpp @@ -156,12 +156,12 @@ bool ACustomInventory::CallStateChain (AActor *actor, FState * State) //========================================================================== int CheckIndex(int paramsize, FState ** pcallstate) { - if (!(CallingState->Frame&SF_STATEPARAM)) return -1; + if (CallingState->ParameterIndex == 0) return -1; - unsigned int index = CallingState->GetMisc1_2(); - if (index > StateParameters.Size()-paramsize-2) return -1; + unsigned int index = (unsigned int) CallingState->ParameterIndex-1; + if (index > StateParameters.Size()-paramsize) return -1; if (pcallstate) *pcallstate=CallingState; - return index+2; // skip the misc parameters + return index; }