From 59fa419506d45816fffdf12f683cf5dc0085bd00 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sun, 3 Jun 2012 15:46:08 +0000 Subject: [PATCH] Lunatic: pack actor/move parameters into t_data, which is enlarged to 14 elements. (LUNATIC build only.) Also, a minor problem is identified. sizeof(actor_t) is 124 on 64-bit platforms, while the expected size is 128 bytes. This needs to be corrected whenever the next savegame version bump happens. git-svn-id: https://svn.eduke32.com/eduke32@2724 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/actors.c | 4 +- polymer/eduke32/source/actors.h | 60 ++++++++++++++++++--- polymer/eduke32/source/game.c | 66 ++++++++++++++++++------ polymer/eduke32/source/gameexec.c | 47 ++++++++++++++--- polymer/eduke32/source/lunatic/defs.ilua | 4 +- 5 files changed, 148 insertions(+), 33 deletions(-) diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 5d33a5a8a..4c7309590 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -699,12 +699,12 @@ static void A_MoveSector(int32_t i) } } -#if 1 //ndef LUNATIC +#ifndef LUNATIC # define LIGHTRAD_PICOFS (T5 ? *(script+T5) + (*(script+T5+2))*T4 : 0) #else // SACTION // startframe + viewtype*??? -# define LIGHTRAD_PICOFS (SACTION_STARTFRAME(actor[i].t_data) + SACTION_VIEWTYPE(actor[i].t_data)*T4) +# define LIGHTRAD_PICOFS (ACTION_STARTFRAME(actor[i].t_data) + ACTION_VIEWTYPE(actor[i].t_data)*T4) #endif // this is the same crap as in game.c's tspr manipulation. puke. diff --git a/polymer/eduke32/source/actors.h b/polymer/eduke32/source/actors.h index 59fe2282c..4da8e116b 100644 --- a/polymer/eduke32/source/actors.h +++ b/polymer/eduke32/source/actors.h @@ -45,11 +45,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef LUNATIC // Ai, action, move getters from t_data[] (== tptr) -# define SACTION_STARTFRAME(tptr) ((tptr)[6]&65535) -# define SACTION_NUMFRAMES(tptr) (((tptr)[6]>>16)&65535) -# define SACTION_VIEWTYPE(tptr) ((tptr)[7]&0x7fffffff) -# define SACTION_INCVAL(tptr) ((tptr)[7]>>31) // arithmetic shr expected! -# define SACTION_DELAY(tptr) ((tptr)[8]&65535) +# define ACTION_STARTFRAME(tptr) ((tptr)[10]&0x0000ffff) +# define ACTION_NUMFRAMES(tptr) (((tptr)[10]>>16)&0x0000ffff) +# define ACTION_VIEWTYPE(tptr) ((tptr)[11]&0x0000ffff) +# define ACTION_INCVAL(tptr) ((tptr)[11]>>16) // arithmetic shr expected! +# define ACTION_DELAY(tptr) ((tptr)[12]&0x0000ffff) + +# define ACTION_SET_STARTFRAME(tptr, val) do { (tptr)[10] &= ~0x0000ffff; (tptr)[10] |= (val)&0x0000ffff; } while (0) +# define ACTION_SET_NUMFRAMES(tptr, val) do { (tptr)[10] &= ~0xffff0000; (tptr)[10] |= ((val)<<16); } while (0) +# define ACTION_SET_VIEWTYPE(tptr, val) do { (tptr)[11] &= ~0x0000ffff; (tptr)[11] |= (val)&0x0000ffff; } while (0) +# define ACTION_SET_INCVAL(tptr, val) do { (tptr)[11] &= ~0xffff0000; (tptr)[11] |= (val)<<16; } while (0) +# define ACTION_SET_DELAY(tptr, val) do { (tptr)[12] = (val)&0x0000ffff; } while (0) + +# define MOVE_H(tptr) ((int16_t)((tptr)[13])) +# define MOVE_V(tptr) ((int16_t)((tptr)[13]>>16)) + +# define MOVE_SET_H(tptr, val) do { (tptr)[13] &= ~0x0000ffff; (tptr)[13] |= (val)&0x0000ffff; } while (0) +# define MOVE_SET_V(tptr, val) do { (tptr)[13] &= ~0xffff0000; (tptr)[13] |= (val)<<16; } while (0) + +extern intptr_t *script; + +// tptr[4] expected to be set +static inline void set_action_members(int32_t *tptr) +{ + ACTION_SET_STARTFRAME(tptr, script[tptr[4]]); + ACTION_SET_NUMFRAMES(tptr, script[tptr[4]+1]); + ACTION_SET_VIEWTYPE(tptr, script[tptr[4]+2]); + ACTION_SET_INCVAL(tptr, script[tptr[4]+3]); + ACTION_SET_DELAY(tptr, script[tptr[4]+4]); +} + +// tptr[1] expected to be set +static inline void set_move_members(int32_t *tptr) +{ + MOVE_SET_H(tptr, script[tptr[1]]); + MOVE_SET_V(tptr, script[tptr[1]+1]); +} #endif // Defines the motion characteristics of an actor @@ -93,7 +124,12 @@ typedef struct { // (+ 40 8 6 16 16 4 8 6 4 20) typedef struct { +#ifndef LUNATIC int32_t t_data[10]; // 40b sometimes used to hold offsets to con code +#else + int32_t t_data[14]; // 56b + // TODO: rearrange for better packing when enabling Lunatic +#endif int16_t picnum,ang,extra,owner; //8b int16_t movflag,tempang,timetosleep; //6b @@ -117,16 +153,28 @@ typedef struct { #endif #if UINTPTR_MAX == 0xffffffff /* 32-bit */ +# ifndef LUNATIC const int8_t filler[20]; +# else + const int8_t filler[4]; +# endif #else /* 64-bit */ - const int8_t filler[12]; +# ifndef LUNATIC + const int8_t filler[12]; // XXX: should be 16, schedule with next BYTEVERSION/savegame version bump! +# else + /* no padding */ +#endif #endif } actor_t; // this struct needs to match the beginning of actor_t above typedef struct { +#ifndef LUNATIC int32_t t_data[10]; // 40b sometimes used to hold offsets to con code +#else + int32_t t_data[14]; // 56b +#endif int16_t picnum,ang,extra,owner; //8b int16_t movflag,tempang,timetosleep; // 6b diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index e1debe1a7..a7c4979de 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -3999,6 +3999,10 @@ int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int3 s->extra = *actorscrptr[s_pn]; T5 = *(actorscrptr[s_pn]+1); T2 = *(actorscrptr[s_pn]+2); +#ifdef LUNATIC + set_action_members(actor[i].t_data); + set_move_members(actor[i].t_data); +#endif s->hitag = *(actorscrptr[s_pn]+3); } @@ -4126,6 +4130,10 @@ int32_t A_Spawn(int32_t j, int32_t pn) SH = *(actorscrptr[s]); T5 = *(actorscrptr[s]+1); T2 = *(actorscrptr[s]+2); +#ifdef LUNATIC + set_action_members(actor[i].t_data); + set_move_members(actor[i].t_data); +#endif if (*(actorscrptr[s]+3) && SHT == 0) SHT = *(actorscrptr[s]+3); } @@ -6024,9 +6032,8 @@ static int32_t maybe_take_on_pal_of_floor(spritetype *datspr, int32_t sect) void G_DoSpriteAnimations(int32_t x,int32_t y,int32_t a,int32_t smoothratio) { int32_t i, j, k, p, sect; - intptr_t l, t_data1,t_data3,t_data4; + intptr_t l; spritetype *s,*t; - int32_t switchpic; if (!spritesortcnt) return; @@ -6159,8 +6166,13 @@ void G_DoSpriteAnimations(int32_t x,int32_t y,int32_t a,int32_t smoothratio) for (j=spritesortcnt-1; j>=0; j--) //Between drawrooms() and drawmasks() { -#if 0 // def LUNATIC - const int32_t *tptr; + int32_t switchpic; +#ifndef LUNATIC + int32_t t_data1,t_data3,t_data4; +#else + int32_t t_data[14] = { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0 }; + + Bassert(sizeof(t_data) == sizeof(actor[0].t_data)); #endif //is the perfect time to animate sprites t = &tsprite[j]; @@ -6259,12 +6271,17 @@ void G_DoSpriteAnimations(int32_t x,int32_t y,int32_t a,int32_t smoothratio) } sect = s->sectnum; +#ifndef LUNATIC t_data1 = T2; t_data3 = T4; -#if 1 // ndef LUNATIC t_data4 = T5; // SACTION #else - tptr = &actor[i].t_data; + t_data[1] = T2; + t_data[3] = T4; + t_data[4] = T5; + + set_action_members(t_data); + set_move_members(t_data); #endif switchpic = s->picnum; @@ -6402,7 +6419,11 @@ void G_DoSpriteAnimations(int32_t x,int32_t y,int32_t a,int32_t smoothratio) } else t->cstat &= ~4; +#ifndef LUNATIC if (klabs(t_data3) > 64) k += 7; +#else + if (klabs(t_data[3]) > 64) k += 7; +#endif t->picnum = RECON+k; break; @@ -6534,14 +6555,18 @@ void G_DoSpriteAnimations(int32_t x,int32_t y,int32_t a,int32_t smoothratio) if (g_player[p].ps->newowner > -1) { -#if 1 // ndef LUNATIC +#ifndef LUNATIC t_data4 = *(actorscrptr[APLAYER]+1); -#else - // Lunatic TODO: SACTION of APLAYER - tptr = (void)0; // forced compilation error -#endif t_data3 = 0; t_data1 = *(actorscrptr[APLAYER]+2); +#else + t_data[4] = *(actorscrptr[APLAYER]+1); // TODO: this must go! + set_action_members(t_data); + + t_data[3] = 0; + t_data[1] = *(actorscrptr[APLAYER]+2); // TODO: this must go! + set_move_members(t_data); +#endif } if (ud.camerasprite == -1 && g_player[p].ps->newowner == -1) @@ -6648,13 +6673,13 @@ PALONLY: } */ -#if 1 //ndef LUNATIC +#ifndef LUNATIC if ((unsigned)t_data4 + 2 >= (unsigned)g_scriptSize) goto skip; - l = *(script + t_data4 + 2); + l = script[t_data4 + 2]; #else - l = SACTION_VIEWTYPE(tptr); + l = ACTION_VIEWTYPE(t_data); #endif #ifdef USE_OPENGL @@ -6711,10 +6736,10 @@ PALONLY: break; } -#if 1 // ndef LUNATIC +#ifndef LUNATIC t->picnum += k + *(script + t_data4) + l*t_data3; #else - t->picnum += k + SACTION_STARTFRAME(tptr) + l*t_data3; + t->picnum += k + ACTION_STARTFRAME(t_data) + l*t_data[3]; #endif if (l > 0) @@ -6729,7 +6754,9 @@ PALONLY: /* completemirror() already reverses the drawn frame, so the above isn't necessary. * Even Polymost's and Polymer's mirror seems to function correctly this way. */ +#ifndef LUNATIC skip: +#endif if (g_player[screenpeek].ps->inv_amount[GET_HEATS] > 0 && g_player[screenpeek].ps->heat_on && (A_CheckEnemySprite(s) || A_CheckSpriteFlags(t->owner,SPRITE_NVG) || s->picnum == APLAYER || s->statnum == STAT_DUMMYPLAYER)) { @@ -6874,7 +6901,11 @@ skip: break; case WATERSPLASH2__STATIC: +#ifndef LUNATIC t->picnum = WATERSPLASH2+t_data1; +#else + t->picnum = WATERSPLASH2+t_data[1]; +#endif break; case SHELL__STATIC: t->picnum = s->picnum+(T1&1); @@ -9866,6 +9897,9 @@ int32_t app_main(int32_t argc, const char **argv) ENetCallbacks callbacks = { NULL, NULL, NULL }; #endif +// Bassert(sizeof(actor_t)==128); // fails with x86_64 + Bassert(offsetof(actor_t, bposx) == sizeof(netactor_t)); + #ifdef GEKKO L2Enhance(); CON_EnableGecko(1, 1); diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 978d2cb69..dcbfca447 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -433,6 +433,7 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t a) { int32_t ticselapsed = (vm.g_t[0])&31; +#ifndef LUNATIC const intptr_t *moveptr; if ((unsigned)vm.g_t[1] >= (unsigned)g_scriptSize-1) @@ -446,6 +447,10 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t a) vm.g_sp->xvel += (*moveptr-vm.g_sp->xvel)/5; if (vm.g_sp->zvel < 648) vm.g_sp->zvel += ((*(moveptr+1)<<4)-vm.g_sp->zvel)/5; +#else + vm.g_sp->xvel += (MOVE_H(vm.g_t)-vm.g_sp->xvel)/5; + if (vm.g_sp->zvel < 648) vm.g_sp->zvel += ((MOVE_V(vm.g_t)<<4)-vm.g_sp->zvel)/5; +#endif if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->extra <= 0) // hack return; @@ -505,7 +510,9 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t a) GAMEEXEC_STATIC void VM_Move(void) { int32_t l; +#ifndef LUNATIC const intptr_t *moveptr; +#endif int32_t a = vm.g_sp->hitag, goalang, angdif; int32_t daxvel; int32_t deadflag = (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->extra <= 0); @@ -571,6 +578,7 @@ GAMEEXEC_STATIC void VM_Move(void) } dead: +#ifndef LUNATIC if ((unsigned)vm.g_t[1] >= (unsigned)g_scriptSize) { vm.g_t[1] = 0; @@ -582,6 +590,10 @@ dead: if (a&geth) vm.g_sp->xvel += ((*moveptr)-vm.g_sp->xvel)>>1; if (a&getv) vm.g_sp->zvel += ((*(moveptr+1)<<4)-vm.g_sp->zvel)>>1; +#else + if (a&geth) vm.g_sp->xvel += (MOVE_H(vm.g_t)-vm.g_sp->xvel)>>1; + if (a&getv) vm.g_sp->zvel += ((MOVE_V(vm.g_t)<<4)-vm.g_sp->zvel)>>1; +#endif if (a&dodgebullet && !deadflag) A_Dodge(vm.g_sp); @@ -911,7 +923,16 @@ skip_check: vm.g_t[5] = *insptr++; // Ai vm.g_t[4] = *(script + vm.g_t[5]); // Action - if (vm.g_t[5]) vm.g_t[1] = *(script + vm.g_t[5] + 1); // move +#ifdef LUNATIC + set_action_members(vm.g_t); +#endif + if (vm.g_t[5]) + { + vm.g_t[1] = *(script + vm.g_t[5] + 1); // move +#ifdef LUNATIC + set_move_members(vm.g_t); +#endif + } vm.g_sp->hitag = *(script + vm.g_t[5] + 2); // move flags vm.g_t[0] = vm.g_t[2] = vm.g_t[3] = 0; // count, actioncount... vm.g_t[3] = ?? @@ -924,6 +945,9 @@ skip_check: insptr++; vm.g_t[2] = vm.g_t[3] = 0; vm.g_t[4] = *insptr++; +#ifdef LUNATIC + set_action_members(vm.g_t); +#endif continue; case CON_IFPDISTL: @@ -1235,14 +1259,20 @@ skip_check: default: // fix for flying/jumping monsters getting stuck in water { +#ifndef LUNATIC int32_t moveScriptOfs = vm.g_t[1]; +#endif if ((vm.g_sp->hitag & jumptoplayer) || (actorscrptr[vm.g_sp->picnum] && - (unsigned)moveScriptOfs < (unsigned)g_scriptSize - 1 && *(script + moveScriptOfs + 1) +#ifndef LUNATIC + (unsigned)moveScriptOfs < (unsigned)g_scriptSize-1 && script[moveScriptOfs + 1] +#else + MOVE_V(vm.g_t) != 0 +#endif )) { - // OSD_Printf("%d\n",*(moveptr+1)); + // OSD_Printf("%d\n", script[moveScriptOfs + 1]); break; } } @@ -1453,6 +1483,9 @@ skip_check: insptr++; vm.g_t[0]=0; vm.g_t[1] = *insptr++; +#ifdef LUNATIC + set_move_members(vm.g_t); +#endif vm.g_sp->hitag = *insptr++; if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->extra <= 0) // hack continue; @@ -5011,15 +5044,15 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) /* Helixhorned: let's do away with intptr_t's... */ if ((unsigned)vm.g_t[4] + 4 < (unsigned)g_scriptSize) { -#if 1 //ndef LUNATIC +#ifndef LUNATIC const int32_t action_frames = *(script + vm.g_t[4] + 1); const int32_t action_incval = *(script + vm.g_t[4] + 3); const int32_t action_delay = *(script + vm.g_t[4] + 4); #else // SACTION - const int32_t action_frames = SACTION_NUMFRAMES(vm.g_t); - const int32_t action_incval = SACTION_INCVAL(vm.g_t); - const int32_t action_delay = SACTION_DELAY(vm.g_t); + const int32_t action_frames = ACTION_NUMFRAMES(vm.g_t); + const int32_t action_incval = ACTION_INCVAL(vm.g_t); + const int32_t action_delay = ACTION_DELAY(vm.g_t); #endif vm.g_sp->lotag += TICSPERFRAME; diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 72557e8ef..3bcb85c2c 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -148,7 +148,7 @@ ffi.cdef[[ // XXX: might still need to make some fields read-only typedef struct { - const int32_t t_data[10]; // 40b sometimes used to hold offsets to con code + const int32_t t_data[14]; // 56b sometimes used to hold offsets to con code int16_t picnum,ang,extra,owner; //8b int16_t movflag,tempang,timetosleep; //6b @@ -159,7 +159,7 @@ typedef struct const int16_t lightId, lightcount, lightmaxrange, cgg; //8b int16_t actorstayput, dispicnum, shootzvel; // 6b - const int8_t _do_not_use[24]; + const int8_t _do_not_use[8]; } actor_t; #pragma pack(pop)