From 7c3f7909ccfdbb3eeef00657e236d2a7f7c3d96f Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 4 Jul 2013 19:38:46 +0000 Subject: [PATCH] Lunatic: various changes. - swap 2d and 3rd args in xmath.rotate() -- now rotate(point, ang, pivot) - add vec3 method 'rotate', calling xmath.rotate - store game tic count in savegames git-svn-id: https://svn.eduke32.com/eduke32@3929 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/demo.c | 2 -- polymer/eduke32/source/gameexec.c | 2 +- polymer/eduke32/source/lunatic/control.lua | 2 +- polymer/eduke32/source/lunatic/test/helixspawner.lua | 2 +- polymer/eduke32/source/lunatic/test/test_dists.lua | 4 ++-- polymer/eduke32/source/lunatic/xmath.lua | 10 ++++++++-- polymer/eduke32/source/premap.c | 7 ++++--- polymer/eduke32/source/premap.h | 2 +- polymer/eduke32/source/savegame.c | 11 ++++++++++- 9 files changed, 28 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/source/demo.c b/polymer/eduke32/source/demo.c index c5bb43936..e93d879ec 100644 --- a/polymer/eduke32/source/demo.c +++ b/polymer/eduke32/source/demo.c @@ -123,8 +123,6 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine ud.god = ud.cashman = ud.eog = ud.showallmap = 0; ud.noclip = ud.scrollmode = ud.overhead_on = 0; //= ud.pause_on = 0; - // G_NewGame(ud.volume_number,ud.level_number,ud.player_skill); - // G_ResetTimers(); totalclock = ototalclock = lockclock = 0; return 1; diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index b2088b2f4..923dd5a03 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5711,7 +5711,7 @@ void G_RestoreMapState(void) Net_ResetPrediction(); G_ClearFIFO(); - G_ResetTimers(); + G_ResetTimers(0); } } diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 1f00db61f..12d64d3d2 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1512,7 +1512,7 @@ end function _rotatepoint(pivotx, pivoty, posx, posy, ang) local pos = ivec3(posx, posy) local pivot = ivec3(pivotx, pivoty) - pos = rotate(pos, pivot, ang):toivec3() + pos = rotate(pos, ang, pivot):toivec3() return pos.x, pos.y end diff --git a/polymer/eduke32/source/lunatic/test/helixspawner.lua b/polymer/eduke32/source/lunatic/test/helixspawner.lua index 6e16ebc5b..6f1499e7c 100644 --- a/polymer/eduke32/source/lunatic/test/helixspawner.lua +++ b/polymer/eduke32/source/lunatic/test/helixspawner.lua @@ -120,7 +120,7 @@ gameactor -- SPAWNSPERTIC*GTICSPERSEC stars. local ii = ((gv.gametic*SPAWNSPERTIC)%(GTICSPERSEC*SPAWNSPERTIC)) + i local v = (radius/16)*angvec(ii*TWOPI/(GTICSPERSEC*SPAWNSPERTIC)) - local circvec = xmath.rotate(xmath.vec3(0, v.x, 16*v.y), xmath.vec3(), spr.ang) -- XXX + local circvec = xmath.vec3(0, v.x, 16*v.y):rotate(spr.ang) local pos = spr^(zofs + radius) + 256*bangvec(spr.ang) + circvec con.insertsprite{D.TRANSPORTERSTAR+4, pos, spr.sectnum, statnum=actor.STAT.ACTOR, diff --git a/polymer/eduke32/source/lunatic/test/test_dists.lua b/polymer/eduke32/source/lunatic/test/test_dists.lua index 7ed3d9520..3cfea1547 100755 --- a/polymer/eduke32/source/lunatic/test/test_dists.lua +++ b/polymer/eduke32/source/lunatic/test/test_dists.lua @@ -65,14 +65,14 @@ t = os.clock() local function _rotatepoint(pivotx, pivoty, posx, posy, ang) local pos = xmath.ivec3(posx, posy) local pivot = xmath.ivec3(pivotx, pivoty) - pos = xmath.rotate(pos, pivot, ang):toivec3() + pos = xmath.rotate(pos, ang, pivot):toivec3() return pos.x, pos.y end sum = 0 for i=1,numpoints do for j=1,numpoints do --- local p = xmath.rotate(pts[i], pts[j], j) +-- local p = xmath.rotate(pts[i], j, pts[j]) -- sum = sum+p.x sum = sum + _rotatepoint(pts[j].x, pts[j].y, pts[i].x, pts[i].y, j) end diff --git a/polymer/eduke32/source/lunatic/xmath.lua b/polymer/eduke32/source/lunatic/xmath.lua index 19e3997da..499e323e8 100644 --- a/polymer/eduke32/source/lunatic/xmath.lua +++ b/polymer/eduke32/source/lunatic/xmath.lua @@ -159,6 +159,8 @@ local vec2_mt = { }, } +local l_rotate -- fwd-decl (XXX: could be the other way around) + -- The vec3 metatable is shared between the integer- and double-based 3-vector -- types. However, some operations are slightly different. local vec3_mt = { @@ -220,7 +222,7 @@ local vec3_mt = { tobuild = function(v) return v:_ctor(v.x, v.y, 16*v.z) end, - -- TODO: v:rotate()? + rotate = function(v, ang, pivot) return l_rotate(v, ang, pivot) end, -- PRIVATE methods -- @@ -283,10 +285,12 @@ end ---=== MISCELLANEOUS MATH ===--- +local zerovec = vec3() -- Point rotation. Note the different order of arguments from engine function. -- XXX: passing mixed vec2/vec3 is problematic. Get rid of vec2? -- : BUILD angle (0-2047 based) -function rotate(pos, pivot, ang) +function rotate(pos, ang, pivot) + pivot = pivot or zerovec local p = vec3(pos)-pivot local c, s = cosb(ang), sinb(ang) local x, y = p.x, p.y @@ -295,6 +299,8 @@ function rotate(pos, pivot, ang) return p end +l_rotate = rotate + -- Two-element vector cross product. -- Anti-commutative, distributive. diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index c2d72f7c0..4be308818 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1676,7 +1676,7 @@ static inline void clearfrags(void) } } -void G_ResetTimers(void) +void G_ResetTimers(uint8_t keepgtics) { vel = svel = angvel = horiz = 0; @@ -1686,7 +1686,8 @@ void G_ResetTimers(void) lockclock = 0; ready2send = 1; g_levelTextTime = 85; - g_moveThingsCount = 0; + if (!keepgtics) + g_moveThingsCount = 0; } void G_ClearFIFO(void) @@ -2042,7 +2043,7 @@ int32_t G_EnterLevel(int32_t g) clearfrags(); - G_ResetTimers(); // Here we go + G_ResetTimers(0); // Here we go //Bsprintf(g_szBuf,"G_EnterLevel L=%d V=%d",ud.level_number, ud.volume_number); //AddLog(g_szBuf); diff --git a/polymer/eduke32/source/premap.h b/polymer/eduke32/source/premap.h index 126239d7d..cc5569dfc 100644 --- a/polymer/eduke32/source/premap.h +++ b/polymer/eduke32/source/premap.h @@ -42,7 +42,7 @@ void G_CacheMapData(void); void G_FadeLoad(int32_t r,int32_t g,int32_t b,int32_t start,int32_t end,int32_t step,int32_t ticwait); void G_FreeMapState(int32_t mapnum); void G_NewGame(int32_t vn,int32_t ln,int32_t sk); -void G_ResetTimers(void); +void G_ResetTimers(uint8_t keepgtics); void G_SetCrosshairColor(int32_t r,int32_t g,int32_t b); void G_UpdateScreenArea(void); void G_SetViewportShrink(int32_t dir); diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 2ecd06c73..75dff9826 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -917,6 +917,11 @@ static const dataspec_t svgm_udnetw[] = { 0, connectpoint2, sizeof(connectpoint2), 1 }, { 0, &randomseed, sizeof(randomseed), 1 }, { 0, &g_globalRandom, sizeof(g_globalRandom), 1 }, +#ifdef LUNATIC + // Save game tic count for Lunatic because it is exposed to userland. See + // test/helixspawner.lua for an example. + { 0, &g_moveThingsCount, sizeof(g_moveThingsCount), 1 }, +#endif // { 0, &lockclock_dummy, sizeof(lockclock), 1 }, { DS_END, 0, 0, 0 } }; @@ -1999,7 +2004,11 @@ static void postloadplayer(int32_t savegamep) //8 // if (savegamep) ? - G_ResetTimers(); +#ifdef LUNATIC + G_ResetTimers(1); +#else + G_ResetTimers(0); +#endif #ifdef POLYMER //9