From 362d8956152881f528d6fb9949b650e59b584789 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 25 Mar 2012 09:19:49 +0300 Subject: [PATCH] removed costab --- src/awish.c | 7 + src/polymod.c | 16 +- src/sincostab.c | 1086 +++++++++++++++++++------------------------------------ 3 files changed, 382 insertions(+), 727 deletions(-) rewrite src/sincostab.c (98%) diff --git a/src/awish.c b/src/awish.c index d7f91b8..efa1f92 100644 --- a/src/awish.c +++ b/src/awish.c @@ -209,6 +209,7 @@ static void quitCleanupRes (void) { //////////////////////////////////////////////////////////////////////////////// +#include "sincostab.c" static int awishRST (int tid, int opcode, int argc, int argv[], int *argp[]) { vmGVars[GVAR_RST_RESULT] = 0; // @@ -419,6 +420,11 @@ dolen: if (pos >= 0) { } if (str != NULL && len > 0) textAdd(str, len, x, y, scale, angle, color, 255); } + } else if (argv[0] == CONST_FRST_COS || argv[0] == CONST_FRST_SIN) { + if (argc < 2) argv[1] = vmPop(tid); + argv[1] %= 360; if (argv[1] < 0) argv[1] += 360; + if (argv[0] == CONST_FRST_COS) argv[1] = (argv[1]+90)%360; + vmGVars[GVAR_RST_RESULT] = sintab[argv[1]]; } else { if (gameRSTCB) return gameRSTCB(tid, opcode, argc, argv, argp); fatal("invalid RST: %d", argv[0]); @@ -575,6 +581,7 @@ int main (int argc, char *argv[]) { } vmCodeSize += csz; initLabels(); + vmGVars[GVAR_POLYFIX_BASE] = POLYFIX_BASE; // { int rsz = 0; diff --git a/src/polymod.c b/src/polymod.c index e868eb0..3c96b11 100644 --- a/src/polymod.c +++ b/src/polymod.c @@ -42,7 +42,8 @@ static int firstX, firstY; static int lastX, lastY; static int pofsx, pofsy; static int pscale; -static int pangle; +static int pangles; +static int panglec; static int vertexnum; @@ -112,12 +113,20 @@ static inline void rotate (int *x, int *y) { *y = (tx*sintab[pangle]+ty*costab[pangle])/POLYFIX_BASE+pofsy; } */ +/* #define rotate(x, y) do { \ int64_t tx = (int64_t)(x)*pscale/POLYFIX_BASE; \ int64_t ty = (int64_t)(y)*pscale/POLYFIX_BASE; \ (x) = (tx*costab[pangle]-ty*sintab[pangle])/POLYFIX_BASE+pofsx; \ (y) = (tx*sintab[pangle]+ty*costab[pangle])/POLYFIX_BASE+pofsy; \ } while (0) +*/ +#define rotate(x, y) do { \ + int64_t tx = (int64_t)(x)*pscale/POLYFIX_BASE; \ + int64_t ty = (int64_t)(y)*pscale/POLYFIX_BASE; \ + (x) = (tx*sintab[panglec]-ty*sintab[pangles])/POLYFIX_BASE+pofsx; \ + (y) = (tx*sintab[pangles]+ty*sintab[panglec])/POLYFIX_BASE+pofsy; \ +} while (0) static void lineDDA (int x0, int y0, int x1, int y1) { @@ -164,8 +173,9 @@ void polymodStart (int ofsx, int ofsy, int scale, int angle) { pofsx = ofsx; pofsy = ofsy; pscale = scale; - while (angle < 0) angle += 360; // hehe - pangle = angle%360; + angle %= 360; if (angle < 0) angle += 360; + pangles = angle; + panglec = (angle+90)%360; if (polyDump) { fdump = fopen("zdump.txt", "w"); } diff --git a/src/sincostab.c b/src/sincostab.c dissimilarity index 98% index 56b97d2..a7e9d6b 100644 --- a/src/sincostab.c +++ b/src/sincostab.c @@ -1,724 +1,362 @@ -static const int costab[360] = { -16384, -16381, -16374, -16361, -16344, -16321, -16294, -16261, -16224, -16182, -16135, -16082, -16025, -15964, -15897, -15825, -15749, -15668, -15582, -15491, -15395, -15295, -15190, -15081, -14967, -14848, -14725, -14598, -14466, -14329, -14188, -14043, -13894, -13740, -13582, -13420, -13254, -13084, -12910, -12732, -12550, -12365, -12175, -11982, -11785, -11585, -11381, -11173, -10963, -10748, -10531, -10310, -10086, -9860, -9630, -9397, -9161, -8923, -8682, -8438, -8192, -7943, -7691, -7438, -7182, -6924, -6663, -6401, -6137, -5871, -5603, -5334, -5062, -4790, -4516, -4240, -3963, -3685, -3406, -3126, -2845, -2563, -2280, -1996, -1712, -1427, -1142, -857, -571, -285, -0, --285, --571, --857, --1142, --1427, --1712, --1996, --2280, --2563, --2845, --3126, --3406, --3685, --3963, --4240, --4516, --4790, --5062, --5334, --5603, --5871, --6137, --6401, --6663, --6924, --7182, --7438, --7691, --7943, --8191, --8438, --8682, --8923, --9161, --9397, --9630, --9860, --10086, --10310, --10531, --10748, --10963, --11173, --11381, --11585, --11785, --11982, --12175, --12365, --12550, --12732, --12910, --13084, --13254, --13420, --13582, --13740, --13894, --14043, --14188, --14329, --14466, --14598, --14725, --14848, --14967, --15081, --15190, --15295, --15395, --15491, --15582, --15668, --15749, --15825, --15897, --15964, --16025, --16082, --16135, --16182, --16224, --16261, --16294, --16321, --16344, --16361, --16374, --16381, --16384, --16381, --16374, --16361, --16344, --16321, --16294, --16261, --16224, --16182, --16135, --16082, --16025, --15964, --15897, --15825, --15749, --15668, --15582, --15491, --15395, --15295, --15190, --15081, --14967, --14848, --14725, --14598, --14466, --14329, --14188, --14043, --13894, --13740, --13582, --13420, --13254, --13084, --12910, --12732, --12550, --12365, --12175, --11982, --11785, --11585, --11381, --11173, --10963, --10748, --10531, --10310, --10086, --9860, --9630, --9397, --9161, --8923, --8682, --8438, --8192, --7943, --7691, --7438, --7182, --6924, --6663, --6401, --6137, --5871, --5603, --5334, --5062, --4790, --4516, --4240, --3963, --3685, --3406, --3126, --2845, --2563, --2280, --1996, --1712, --1427, --1142, --857, --571, --285, -0, -285, -571, -857, -1142, -1427, -1712, -1996, -2280, -2563, -2845, -3126, -3406, -3685, -3963, -4240, -4516, -4790, -5062, -5334, -5603, -5871, -6137, -6401, -6663, -6924, -7182, -7438, -7691, -7943, -8192, -8438, -8682, -8923, -9161, -9397, -9630, -9860, -10086, -10310, -10531, -10748, -10963, -11173, -11381, -11585, -11785, -11982, -12175, -12365, -12550, -12732, -12910, -13084, -13254, -13420, -13582, -13740, -13894, -14043, -14188, -14329, -14466, -14598, -14725, -14848, -14967, -15081, -15190, -15295, -15395, -15491, -15582, -15668, -15749, -15825, -15897, -15964, -16025, -16082, -16135, -16182, -16224, -16261, -16294, -16321, -16344, -16361, -16374, -16381, -}; -static const int sintab[360] = { -0, -285, -571, -857, -1142, -1427, -1712, -1996, -2280, -2563, -2845, -3126, -3406, -3685, -3963, -4240, -4516, -4790, -5062, -5334, -5603, -5871, -6137, -6401, -6663, -6924, -7182, -7438, -7691, -7943, -8191, -8438, -8682, -8923, -9161, -9397, -9630, -9860, -10086, -10310, -10531, -10748, -10963, -11173, -11381, -11585, -11785, -11982, -12175, -12365, -12550, -12732, -12910, -13084, -13254, -13420, -13582, -13740, -13894, -14043, -14188, -14329, -14466, -14598, -14725, -14848, -14967, -15081, -15190, -15295, -15395, -15491, -15582, -15668, -15749, -15825, -15897, -15964, -16025, -16082, -16135, -16182, -16224, -16261, -16294, -16321, -16344, -16361, -16374, -16381, -16384, -16381, -16374, -16361, -16344, -16321, -16294, -16261, -16224, -16182, -16135, -16082, -16025, -15964, -15897, -15825, -15749, -15668, -15582, -15491, -15395, -15295, -15190, -15081, -14967, -14848, -14725, -14598, -14466, -14329, -14188, -14043, -13894, -13740, -13582, -13420, -13254, -13084, -12910, -12732, -12550, -12365, -12175, -11982, -11785, -11585, -11381, -11173, -10963, -10748, -10531, -10310, -10086, -9860, -9630, -9397, -9161, -8923, -8682, -8438, -8191, -7943, -7691, -7438, -7182, -6924, -6663, -6401, -6137, -5871, -5603, -5334, -5062, -4790, -4516, -4240, -3963, -3685, -3406, -3126, -2845, -2563, -2280, -1996, -1712, -1427, -1142, -857, -571, -285, -0, --285, --571, --857, --1142, --1427, --1712, --1996, --2280, --2563, --2845, --3126, --3406, --3685, --3963, --4240, --4516, --4790, --5062, --5334, --5603, --5871, --6137, --6401, --6663, --6924, --7182, --7438, --7691, --7943, --8192, --8438, --8682, --8923, --9161, --9397, --9630, --9860, --10086, --10310, --10531, --10748, --10963, --11173, --11381, --11585, --11785, --11982, --12175, --12365, --12550, --12732, --12910, --13084, --13254, --13420, --13582, --13740, --13894, --14043, --14188, --14329, --14466, --14598, --14725, --14848, --14967, --15081, --15190, --15295, --15395, --15491, --15582, --15668, --15749, --15825, --15897, --15964, --16025, --16082, --16135, --16182, --16224, --16261, --16294, --16321, --16344, --16361, --16374, --16381, --16384, --16381, --16374, --16361, --16344, --16321, --16294, --16261, --16224, --16182, --16135, --16082, --16025, --15964, --15897, --15825, --15749, --15668, --15582, --15491, --15395, --15295, --15190, --15081, --14967, --14848, --14725, --14598, --14466, --14329, --14188, --14043, --13894, --13740, --13582, --13420, --13254, --13084, --12910, --12732, --12550, --12365, --12175, --11982, --11785, --11585, --11381, --11173, --10963, --10748, --10531, --10310, --10086, --9860, --9630, --9397, --9161, --8923, --8682, --8438, --8192, --7943, --7691, --7438, --7182, --6924, --6663, --6401, --6137, --5871, --5603, --5334, --5062, --4790, --4516, --4240, --3963, --3685, --3406, --3126, --2845, --2563, --2280, --1996, --1712, --1427, --1142, --857, --571, --285, -}; +static const int short sintab[360] = { +0, +71, +142, +214, +285, +356, +428, +499, +570, +640, +711, +781, +851, +921, +990, +1060, +1129, +1197, +1265, +1333, +1400, +1467, +1534, +1600, +1665, +1731, +1795, +1859, +1922, +1985, +2047, +2109, +2170, +2230, +2290, +2349, +2407, +2465, +2521, +2577, +2632, +2687, +2740, +2793, +2845, +2896, +2946, +2995, +3043, +3091, +3137, +3183, +3227, +3271, +3313, +3355, +3395, +3435, +3473, +3510, +3547, +3582, +3616, +3649, +3681, +3712, +3741, +3770, +3797, +3823, +3848, +3872, +3895, +3917, +3937, +3956, +3974, +3991, +4006, +4020, +4033, +4045, +4056, +4065, +4073, +4080, +4086, +4090, +4093, +4095, +4096, +4095, +4093, +4090, +4086, +4080, +4073, +4065, +4056, +4045, +4033, +4020, +4006, +3991, +3974, +3956, +3937, +3917, +3895, +3872, +3848, +3823, +3797, +3770, +3741, +3712, +3681, +3649, +3616, +3582, +3547, +3510, +3473, +3435, +3395, +3355, +3313, +3271, +3227, +3183, +3137, +3091, +3043, +2995, +2946, +2896, +2845, +2793, +2740, +2687, +2632, +2577, +2521, +2465, +2407, +2349, +2290, +2230, +2170, +2109, +2047, +1985, +1922, +1859, +1795, +1731, +1665, +1600, +1534, +1467, +1400, +1333, +1265, +1197, +1129, +1060, +990, +921, +851, +781, +711, +640, +570, +499, +428, +356, +285, +214, +142, +71, +0, +-71, +-142, +-214, +-285, +-356, +-428, +-499, +-570, +-640, +-711, +-781, +-851, +-921, +-990, +-1060, +-1129, +-1197, +-1265, +-1333, +-1400, +-1467, +-1534, +-1600, +-1665, +-1731, +-1795, +-1859, +-1922, +-1985, +-2048, +-2109, +-2170, +-2230, +-2290, +-2349, +-2407, +-2465, +-2521, +-2577, +-2632, +-2687, +-2740, +-2793, +-2845, +-2896, +-2946, +-2995, +-3043, +-3091, +-3137, +-3183, +-3227, +-3271, +-3313, +-3355, +-3395, +-3435, +-3473, +-3510, +-3547, +-3582, +-3616, +-3649, +-3681, +-3712, +-3741, +-3770, +-3797, +-3823, +-3848, +-3872, +-3895, +-3917, +-3937, +-3956, +-3974, +-3991, +-4006, +-4020, +-4033, +-4045, +-4056, +-4065, +-4073, +-4080, +-4086, +-4090, +-4093, +-4095, +-4096, +-4095, +-4093, +-4090, +-4086, +-4080, +-4073, +-4065, +-4056, +-4045, +-4033, +-4020, +-4006, +-3991, +-3974, +-3956, +-3937, +-3917, +-3895, +-3872, +-3848, +-3823, +-3797, +-3770, +-3741, +-3712, +-3681, +-3649, +-3616, +-3582, +-3547, +-3510, +-3473, +-3435, +-3395, +-3355, +-3313, +-3271, +-3227, +-3183, +-3137, +-3091, +-3043, +-2995, +-2946, +-2896, +-2845, +-2793, +-2740, +-2687, +-2632, +-2577, +-2521, +-2465, +-2407, +-2349, +-2290, +-2230, +-2170, +-2109, +-2048, +-1985, +-1922, +-1859, +-1795, +-1731, +-1665, +-1600, +-1534, +-1467, +-1400, +-1333, +-1265, +-1197, +-1129, +-1060, +-990, +-921, +-851, +-781, +-711, +-640, +-570, +-499, +-428, +-356, +-285, +-214, +-142, +-71, +}; -- 2.11.4.GIT