From black at icculus.org Sat Mar 4 08:46:51 2006 From: black at icculus.org (black at icculus.org) Date: 4 Mar 2006 08:46:51 -0500 Subject: r658 - trunk Message-ID: <20060304134651.10536.qmail@icculus.org> Author: black Date: 2006-03-04 08:46:51 -0500 (Sat, 04 Mar 2006) New Revision: 658 Modified: trunk/TODO.txt Log: hopefully the commit mails work again Modified: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2006-03-04 12:22:31 UTC (rev 657) +++ trunk/TODO.txt 2006-03-04 13:46:51 UTC (rev 658) @@ -60,6 +60,8 @@ LordHavoc's research progress: still figuring out how to write LISP interpreters... and now distracted by other things. +Black: This can be regarded as done. + ============================================================================== input discussion From coderjoe at icculus.org Sun Mar 5 01:36:46 2006 From: coderjoe at icculus.org (coderjoe at icculus.org) Date: 5 Mar 2006 01:36:46 -0500 Subject: r659 - trunk Message-ID: <20060305063646.12147.qmail@icculus.org> Author: coderjoe Date: 2006-03-05 01:36:45 -0500 (Sun, 05 Mar 2006) New Revision: 659 Modified: trunk/TODO.txt Log: test. email AND CIA should now work together. (who overwrote the post-commit hook file with the default version, killing my CIA line??) Modified: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2006-03-04 13:46:51 UTC (rev 658) +++ trunk/TODO.txt 2006-03-05 06:36:45 UTC (rev 659) @@ -62,6 +62,7 @@ Black: This can be regarded as done. + ============================================================================== input discussion From black at icculus.org Sun Mar 5 10:28:05 2006 From: black at icculus.org (black at icculus.org) Date: 5 Mar 2006 10:28:05 -0500 Subject: r660 - in trunk: . game Message-ID: <20060305152805.22782.qmail@icculus.org> Author: black Date: 2006-03-05 10:28:05 -0500 (Sun, 05 Mar 2006) New Revision: 660 Modified: trunk/game/g_audio.c trunk/lhsound.c trunk/lhsound.h trunk/lhsound_mixmode.h trunk/system.c trunk/system.h Log: refactor the lhsound code to use multiple enums. added a macro to make the system states const for everything except the system implementation and made the system more of a black box. Modified: trunk/game/g_audio.c =================================================================== --- trunk/game/g_audio.c 2006-03-05 06:36:45 UTC (rev 659) +++ trunk/game/g_audio.c 2006-03-05 15:28:05 UTC (rev 660) @@ -147,7 +147,7 @@ // start mixing this sound sound = (Sound *)Resource_GetData(entity->sound.resourceindex); lhsoundBindSample(sound->samplenumber); - lhsoundBegin(LHSOUND_SEGMENT_STRIP); + lhsoundBegin(LHSOUND_RENDER_SEGMENT_STRIP); // output the previous mix point so that we have a valid // segment, all later points will be added individually // with no further segment checks Modified: trunk/lhsound.c =================================================================== --- trunk/lhsound.c 2006-03-05 06:36:45 UTC (rev 659) +++ trunk/lhsound.c 2006-03-05 15:28:05 UTC (rev 660) @@ -13,11 +13,11 @@ typedef struct lhsound_sample_s { int used; // true if GenSamples has marked this, made false by DeleteSamples - lhsound_enum_t internalformat; - lhsound_enum_t repeatmode; // one of LHSOUND_CLAMP, LHSOUND_WRAP, LHSOUND_REPEATSECTION - lhsound_enum_t minfilter; // minification filter (what to do when the input maps to the output as multiple input samples to one output sample) - lhsound_enum_t magfilter; // magnification filter (what to do when the input maps to the output as one input sample to multiple output samples) - // if LHSOUND_REPEATSECTION is used, it will repeat the range repeatposition...length + lhsound_format_t internalformat; + lhsound_repeatmode_t repeatmode; + lhsound_filter_t minfilter; // minification filter (what to do when the input maps to the output as multiple input samples to one output sample) + lhsound_filter_t magfilter; // magnification filter (what to do when the input maps to the output as one input sample to multiple output samples) + // if LHSOUND_REEPAT_REPEATSECTION is used, it will repeat the range repeatposition...length int repeatposition; int length; void *data; @@ -49,12 +49,12 @@ lhsound_sample_t *boundsample; // used only during Begin...End - lhsound_enum_t beginmode; + lhsound_rendermode_t rendermode; unsigned int numpoints; lhsound_point_t points[2]; // current error code - int errornum; + lhsound_error_t errornum; // mixing framebuffer int mixbufferlength; @@ -62,7 +62,7 @@ } lhsound_state; -int lhsoundGetError(void) +lhsound_error_t lhsoundGetError(void) { int n = lhsound_state.errornum; lhsound_state.errornum = 0; @@ -98,7 +98,7 @@ { if (lhsound_state.boundsampleindex == number) return; - LHSOUNDASSERT(number < LHSOUND_MAX_SAMPLES, LHSOUND_OUT_OF_MEMORY); + LHSOUNDASSERT(number < LHSOUND_MAX_SAMPLES, LHSOUND_ERROR_OUT_OF_MEMORY); lhsoundExpandSamplesArray(number); lhsound_state.boundsampleindex = number; lhsound_state.boundsample = lhsound_state.samples + number; @@ -113,17 +113,16 @@ void lhsoundGenSamples(int count, int *array) { int i; - LHSOUNDASSERT(count > 0, LHSOUND_INVALID_VALUE); + LHSOUNDASSERT(count > 0, LHSOUND_ERROR_INVALID_VALUE); // TODO: add a firstunused optimization - for (i = 1;count > 0;i++) + for (i = 1;count > 0;count--) { - LHSOUNDASSERT(i < LHSOUND_MAX_SAMPLES, LHSOUND_OUT_OF_MEMORY); + LHSOUNDASSERT(i < LHSOUND_MAX_SAMPLES, LHSOUND_ERROR_OUT_OF_MEMORY); lhsoundExpandSamplesArray(i); if (!lhsound_state.samples[i].used) { lhsound_state.samples[i].used = LHSOUND_TRUE; - count--; - *array++ = i; + *array++ = i++; } } } @@ -146,12 +145,12 @@ } } -void lhsoundSample(unsigned int length, lhsound_enum_t providedformat, const void *data) +void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data) { unsigned int i; unsigned int bytes; - int internalformat; - LHSOUNDASSERT(length >= 1, LHSOUND_INVALID_VALUE); + lhsound_format_t internalformat; + LHSOUNDASSERT(length >= 1, LHSOUND_ERROR_INVALID_VALUE); // decide which internal format and detect invalid formats // TODO: add swapped versions bytes = 1; @@ -175,7 +174,7 @@ bytes = 4; break; default: - LHSOUNDERROR(LHSOUND_INVALID_ENUM); + LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM); break; } if (lhsound_state.boundsample->data) @@ -265,37 +264,37 @@ } } -void lhsoundSampleParami(lhsound_enum_t parameter, int value) +void lhsoundSampleParami(lhsound_sampleparam_t parameter, int value) { switch (parameter) { case LHSOUND_SAMPLE_REPEAT: switch(value) { - case LHSOUND_CLAMP: - case LHSOUND_WRAP: + case LHSOUND_REPEAT_CLAMP: + case LHSOUND_REPEAT_WRAP: lhsound_state.boundsample->repeatmode = value; break; default: - LHSOUNDERROR(LHSOUND_INVALID_ENUM); + LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM); break; } break; case LHSOUND_SAMPLE_REPEATPOSITION: - LHSOUNDASSERT(value >= 0 && value < lhsound_state.boundsample->length, LHSOUND_INVALID_VALUE); + LHSOUNDASSERT(value >= 0 && value < lhsound_state.boundsample->length, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.boundsample->repeatposition = value; break; case LHSOUND_SAMPLE_MINFILTER: // TODO: add LHSOUND_SAMPLE_MINFILTER values LHSOUND_NEAREST_MIPMAP_NEAREST, LHSOUND_NEAREST_MIPMAP_LINEAR, LHSOUND_LINEAR_MIPMAP_NEAREST, LHSOUND_LINEAR_MIPMAP_LINEAR - LHSOUNDASSERT(value == LHSOUND_NEAREST || value == LHSOUND_LINEAR, LHSOUND_INVALID_VALUE); + LHSOUNDASSERT(value == LHSOUND_NEAREST || value == LHSOUND_LINEAR, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.boundsample->minfilter = value; break; case LHSOUND_SAMPLE_MAGFILTER: - LHSOUNDASSERT(value == LHSOUND_NEAREST || value == LHSOUND_LINEAR, LHSOUND_INVALID_VALUE); + LHSOUNDASSERT(value == LHSOUND_NEAREST || value == LHSOUND_LINEAR, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.boundsample->magfilter = value; break; default: - LHSOUNDERROR(LHSOUND_INVALID_ENUM); + LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM); break; } } @@ -304,7 +303,8 @@ { double x1, x2, slope_scale, slope_s, slope_v, s, v, send; int x, x1s, x2s, si1, si2; - lhsound_enum_t mixmode, filter; + lhsound_repeatmode_t mixmode; + lhsound_filter_t filter; float datasi1, datasi2, sfrac, *out; lhsound_sample_t *sample = lhsound_state.boundsample; // if backwards, swap the order @@ -335,7 +335,7 @@ send = s + slope_s * (x2s-x1s); // if entirely inside the 0-1 time range use a faster mixing mode if (s >= 0 && s < 1 && send >= 0 && send < 1) - mixmode = LHSOUND_NONE; + mixmode = LHSOUND_REPEAT_NONE; else mixmode = sample->repeatmode; filter = sample->magfilter; @@ -366,29 +366,29 @@ return; } -void lhsoundBegin(lhsound_enum_t mode) +void lhsoundBegin(lhsound_rendermode_t mode) { - LHSOUNDASSERT(lhsound_state.beginmode == LHSOUND_NONE, LHSOUND_INVALID_OPERATION); + LHSOUNDASSERT(lhsound_state.rendermode == LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); switch (mode) { - case LHSOUND_SEGMENTS: - case LHSOUND_SEGMENT_STRIP: - lhsound_state.beginmode = mode; + case LHSOUND_RENDER_SEGMENTS: + case LHSOUND_RENDER_SEGMENT_STRIP: + lhsound_state.rendermode = mode; lhsound_state.numpoints = 0; break; default: - LHSOUNDERROR(LHSOUND_INVALID_ENUM); + LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM); break; } } void lhsoundPoint(double x, double s, double v) { - LHSOUNDASSERT(lhsound_state.beginmode != LHSOUND_NONE, LHSOUND_INVALID_OPERATION); - switch (lhsound_state.beginmode) + LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); + switch (lhsound_state.rendermode) { - case LHSOUND_SEGMENTS: - case LHSOUND_SEGMENT_STRIP: + case LHSOUND_RENDER_SEGMENTS: + case LHSOUND_RENDER_SEGMENT_STRIP: lhsound_state.points[0] = lhsound_state.points[1]; lhsound_state.points[1].x = x; lhsound_state.points[1].s = s; @@ -398,7 +398,7 @@ { lhsoundRenderSegment(&lhsound_state.points[0], &lhsound_state.points[1]); lhsound_state.numpoints = 0; - if (lhsound_state.beginmode == LHSOUND_SEGMENTS) + if (lhsound_state.rendermode == LHSOUND_RENDER_SEGMENTS) lhsound_state.numpoints = 0; else { @@ -415,8 +415,8 @@ void lhsoundEnd(void) { - LHSOUNDASSERT(lhsound_state.beginmode != LHSOUND_NONE, LHSOUND_INVALID_OPERATION); - lhsound_state.beginmode = LHSOUND_NONE; + LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); + lhsound_state.rendermode = LHSOUND_RENDER_NONE; } void lhsoundInit(void) @@ -429,17 +429,17 @@ lhsound_state.boundsample = lhsound_state.samples; lhsound_state.boundsample->used = LHSOUND_TRUE; lhsound_state.boundsample->internalformat = LHSOUND_SIGNED_BYTE; - lhsound_state.boundsample->repeatmode = LHSOUND_CLAMP; + lhsound_state.boundsample->repeatmode = LHSOUND_REPEAT_CLAMP; lhsound_state.boundsample->minfilter = LHSOUND_LINEAR; lhsound_state.boundsample->magfilter = LHSOUND_LINEAR; lhsound_state.boundsample->repeatposition = 0; lhsound_state.boundsample->length = 0; lhsound_state.boundsample->data = NULL; - lhsound_state.beginmode = LHSOUND_NONE; + lhsound_state.rendermode = LHSOUND_RENDER_NONE; lhsound_state.numpoints = 0; - lhsound_state.errornum = LHSOUND_NONE; + lhsound_state.errornum = LHSOUND_ERROR_NONE; lhsound_state.mixbufferlength = 0; } @@ -454,20 +454,22 @@ lhsoundClearMemory(&lhsound_state, 0, sizeof(lhsound_state)); } -void lhsoundGeti(lhsound_enum_t what, int *output) +void lhsoundGeti(lhsound_queryname_t pname, int *output) { - switch (what) + switch (pname) { - case LHSOUND_MIX_BUFFER_LENGTH:LHSOUNDASSERT(lhsound_state.beginmode, LHSOUND_INVALID_OPERATION);output[0] = lhsound_state.mixbufferlength;break; - default:LHSOUNDERROR(LHSOUND_INVALID_ENUM);break; + case LHSOUND_MIX_BUFFER_LENGTH:LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION);output[0] = lhsound_state.mixbufferlength;break; + default:LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM);break; } } void lhsoundMixBegin(int bufferlength) { - LHSOUNDASSERT(!lhsound_state.beginmode, LHSOUND_INVALID_OPERATION); - LHSOUNDASSERT(bufferlength >= 1 && bufferlength < 65536, LHSOUND_INVALID_VALUE); - lhsound_state.beginmode = LHSOUND_TRUE; + LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); + LHSOUNDASSERT(bufferlength >= 1 && bufferlength < 65536, LHSOUND_ERROR_INVALID_VALUE); + //FIXME: AK this is bad since it would allow a End call without a BeginCall + // but I guess its because of Geti, anyway, commented out since it should be solved somehow else + //lhsound_state.rendermode = LHSOUND_TRUE; if (lhsound_state.mixbufferlength != bufferlength) { lhsound_state.mixbufferlength = bufferlength; @@ -476,7 +478,7 @@ lhsoundClearMemory(lhsound_state.mixbuffer, 0, lhsound_state.mixbufferlength * sizeof(*lhsound_state.mixbuffer)); } -void lhsoundMixEnd(lhsound_enum_t format, size_t stride, void *output, int bufferlength) +void lhsoundMixEnd(lhsound_format_t format, size_t stride, void *output, int bufferlength) { int i; int ival; @@ -489,29 +491,30 @@ unsigned short s; } swaptest; - LHSOUNDASSERT(lhsound_state.beginmode, LHSOUND_INVALID_OPERATION); - LHSOUNDASSERT(bufferlength == lhsound_state.mixbufferlength, LHSOUND_INVALID_VALUE); - LHSOUNDASSERT(stride != 0, LHSOUND_INVALID_VALUE); + // FIXME: same as in mixbegin + LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); + LHSOUNDASSERT(bufferlength == lhsound_state.mixbufferlength, LHSOUND_ERROR_INVALID_VALUE); + LHSOUNDASSERT(stride != 0, LHSOUND_ERROR_INVALID_VALUE); swaptest.s = 1; switch (format) { - case LHSOUND_UNSIGNED_SHORT_BIG_ENDIAN: format = LHSOUND_UNSIGNED_SHORT;swap = swaptest.c[0] != 0;break; - case LHSOUND_SIGNED_SHORT_BIG_ENDIAN: format = LHSOUND_SIGNED_SHORT;swap = swaptest.c[0] != 0;break; - case LHSOUND_UNSIGNED_INT_BIG_ENDIAN: format = LHSOUND_UNSIGNED_INT;swap = swaptest.c[0] != 0;break; - case LHSOUND_SIGNED_INT_BIG_ENDIAN: format = LHSOUND_SIGNED_INT;swap = swaptest.c[0] != 0;break; - case LHSOUND_FLOAT_BIG_ENDIAN: format = LHSOUND_FLOAT;swap = swaptest.c[0] != 0;break; + case LHSOUND_UNSIGNED_SHORT_BIG_ENDIAN: format = LHSOUND_UNSIGNED_SHORT; swap = swaptest.c[0] != 0;break; + case LHSOUND_SIGNED_SHORT_BIG_ENDIAN: format = LHSOUND_SIGNED_SHORT; swap = swaptest.c[0] != 0;break; + case LHSOUND_UNSIGNED_INT_BIG_ENDIAN: format = LHSOUND_UNSIGNED_INT; swap = swaptest.c[0] != 0;break; + case LHSOUND_SIGNED_INT_BIG_ENDIAN: format = LHSOUND_SIGNED_INT; swap = swaptest.c[0] != 0;break; + case LHSOUND_FLOAT_BIG_ENDIAN: format = LHSOUND_FLOAT; swap = swaptest.c[0] != 0;break; - case LHSOUND_UNSIGNED_SHORT_LITTLE_ENDIAN: format = LHSOUND_UNSIGNED_SHORT;swap = swaptest.c[0] == 0;break; - case LHSOUND_SIGNED_SHORT_LITTLE_ENDIAN: format = LHSOUND_SIGNED_SHORT;swap = swaptest.c[0] == 0;break; - case LHSOUND_UNSIGNED_INT_LITTLE_ENDIAN: format = LHSOUND_UNSIGNED_INT;swap = swaptest.c[0] == 0;break; - case LHSOUND_SIGNED_INT_LITTLE_ENDIAN: format = LHSOUND_SIGNED_INT;swap = swaptest.c[0] == 0;break; - case LHSOUND_FLOAT_LITTLE_ENDIAN: format = LHSOUND_FLOAT;swap = swaptest.c[0] == 0;break; + case LHSOUND_UNSIGNED_SHORT_LITTLE_ENDIAN: format = LHSOUND_UNSIGNED_SHORT; swap = swaptest.c[0] == 0;break; + case LHSOUND_SIGNED_SHORT_LITTLE_ENDIAN: format = LHSOUND_SIGNED_SHORT; swap = swaptest.c[0] == 0;break; + case LHSOUND_UNSIGNED_INT_LITTLE_ENDIAN: format = LHSOUND_UNSIGNED_INT; swap = swaptest.c[0] == 0;break; + case LHSOUND_SIGNED_INT_LITTLE_ENDIAN: format = LHSOUND_SIGNED_INT; swap = swaptest.c[0] == 0;break; + case LHSOUND_FLOAT_LITTLE_ENDIAN: format = LHSOUND_FLOAT; swap = swaptest.c[0] == 0;break; - case LHSOUND_UNSIGNED_SHORT_SWAPPED: format = LHSOUND_UNSIGNED_SHORT;swap = LHSOUND_TRUE;break; - case LHSOUND_SIGNED_SHORT_SWAPPED: format = LHSOUND_SIGNED_SHORT;swap = LHSOUND_TRUE;break; - case LHSOUND_UNSIGNED_INT_SWAPPED: format = LHSOUND_UNSIGNED_INT;swap = LHSOUND_TRUE;break; - case LHSOUND_SIGNED_INT_SWAPPED: format = LHSOUND_SIGNED_INT;swap = LHSOUND_TRUE;break; - case LHSOUND_FLOAT_SWAPPED: format = LHSOUND_FLOAT;swap = LHSOUND_TRUE;break; + case LHSOUND_UNSIGNED_SHORT_SWAPPED: format = LHSOUND_UNSIGNED_SHORT; swap = LHSOUND_TRUE;break; + case LHSOUND_SIGNED_SHORT_SWAPPED: format = LHSOUND_SIGNED_SHORT; swap = LHSOUND_TRUE;break; + case LHSOUND_UNSIGNED_INT_SWAPPED: format = LHSOUND_UNSIGNED_INT; swap = LHSOUND_TRUE;break; + case LHSOUND_SIGNED_INT_SWAPPED: format = LHSOUND_SIGNED_INT; swap = LHSOUND_TRUE;break; + case LHSOUND_FLOAT_SWAPPED: format = LHSOUND_FLOAT; swap = LHSOUND_TRUE;break; default: swap = LHSOUND_FALSE; @@ -573,7 +576,7 @@ *((float *)out) = (float)lhsound_state.mixbuffer[i]; break; default: - LHSOUNDERROR(LHSOUND_INVALID_ENUM); + LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM); break; } if (swap) Modified: trunk/lhsound.h =================================================================== --- trunk/lhsound.h 2006-03-05 06:36:45 UTC (rev 659) +++ trunk/lhsound.h 2006-03-05 15:28:05 UTC (rev 660) @@ -2,14 +2,49 @@ #ifndef LHSOUND_H #define LHSOUND_H -typedef enum lhsound_enum_e +#define LHSOUND_ZERO 0 +#define LHSOUND_ONE 1 +#define LHSOUND_FALSE 0 +#define LHSOUND_TRUE 1 + +#define LHSOUND_NULL ((void *)0) + +typedef enum lhsound_error_e { - LHSOUND_ZERO = 0, - LHSOUND_ONE = 1, - LHSOUND_FALSE = 0, - LHSOUND_TRUE = 1, - LHSOUND_NONE = 0, - LHSOUND_SIGNED_BYTE, + LHSOUND_ERROR_NONE, + LHSOUND_ERROR_INVALID_OPERATION, + LHSOUND_ERROR_INVALID_VALUE, + LHSOUND_ERROR_INVALID_ENUM, + LHSOUND_ERROR_OUT_OF_MEMORY, +} +lhsound_error_t; + +typedef enum lhsound_rendermode_e +{ + LHSOUND_RENDER_NONE, + LHSOUND_RENDER_SEGMENTS, + LHSOUND_RENDER_SEGMENT_STRIP, +} +lhsound_rendermode_t; + +typedef enum lhsound_queryname_e +{ + LHSOUND_MIX_BUFFER_LENGTH = 1, +} +lhsound_queryname_t; + +typedef enum lhsound_sampleparam_e +{ + LHSOUND_SAMPLE_REPEAT = 1, + LHSOUND_SAMPLE_REPEATPOSITION, + LHSOUND_SAMPLE_MINFILTER, + LHSOUND_SAMPLE_MAGFILTER, +} +lhsound_sampleparam_t; + +typedef enum lhsound_format_e +{ + LHSOUND_SIGNED_BYTE = 1, LHSOUND_UNSIGNED_BYTE, LHSOUND_SIGNED_SHORT, LHSOUND_UNSIGNED_SHORT, @@ -35,44 +70,47 @@ LHSOUND_UNSIGNED_INT_BIG_ENDIAN, LHSOUND_FLOAT_BIG_ENDIAN, LHSOUND_DOUBLE_BIG_ENDIAN, - LHSOUND_SAMPLE_REPEAT, - LHSOUND_SAMPLE_REPEATPOSITION, - LHSOUND_SAMPLE_MINFILTER, - LHSOUND_SAMPLE_MAGFILTER, - LHSOUND_CLAMP, - LHSOUND_WRAP, - LHSOUND_REPEATSECTION, - LHSOUND_NEAREST, +} +lhsound_format_t; + +typedef enum lhsound_filter_e +{ + LHSOUND_NEAREST = 0, LHSOUND_LINEAR, LHSOUND_NEAREST_MIPMAP_NEAREST, LHSOUND_NEAREST_MIPMAP_LINEAR, LHSOUND_LINEAR_MIPMAP_NEAREST, LHSOUND_LINEAR_MIPMAP_LINEAR, - LHSOUND_SEGMENTS, - LHSOUND_SEGMENT_STRIP, - LHSOUND_MIX_BUFFER_LENGTH, - LHSOUND_INVALID_OPERATION, - LHSOUND_INVALID_VALUE, - LHSOUND_INVALID_ENUM, - LHSOUND_OUT_OF_MEMORY, } -lhsound_enum_t; +lhsound_filter_t; -#define LHSOUND_NULL ((void *)0) +typedef enum lhsound_repeatmode_e +{ + LHSOUND_REPEAT_NONE = 0, + LHSOUND_REPEAT_CLAMP, + LHSOUND_REPEAT_WRAP, + LHSOUND_REPEAT_REPEATSECTION, +} +lhsound_repeatmode_t; -int lhsoundGetError(void); -void lhsoundGeti(lhsound_enum_t what, int *output); +lhsound_error_t lhsoundGetError(void); +void lhsoundGeti(lhsound_queryname_t pname, int *output); + void lhsoundBindSample(unsigned int number); void lhsoundGenSamples(int count, int *array); void lhsoundDeleteSamples(unsigned int count, int *array); -void lhsoundSample(unsigned int length, lhsound_enum_t providedformat, const void *data); -void lhsoundSampleParami(lhsound_enum_t parameter, int value); -void lhsoundBegin(lhsound_enum_t mode); + +void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data); +void lhsoundSampleParami(lhsound_sampleparam_t parameter, int value); + +void lhsoundBegin(lhsound_rendermode_t mode); void lhsoundPoint(double x, double s, double v); void lhsoundEnd(void); + void lhsoundInit(void); void lhsoundShutdown(void); + void lhsoundMixBegin(int bufferlength); -void lhsoundMixEnd(lhsound_enum_t format, size_t stride, void *output, int bufferlength); +void lhsoundMixEnd(lhsound_format_t format, size_t stride, void *output, int bufferlength); #endif Modified: trunk/lhsound_mixmode.h =================================================================== --- trunk/lhsound_mixmode.h 2006-03-05 06:36:45 UTC (rev 659) +++ trunk/lhsound_mixmode.h 2006-03-05 15:28:05 UTC (rev 660) @@ -1,22 +1,22 @@ switch(mixmode) { - case LHSOUND_NONE: + case LHSOUND_REPEAT_NONE: #define MIX_WRAP(datasi, si) ((datasi) = data[(si)]) #include "lhsound_mixloop.h" #undef MIX_WRAP break; - case LHSOUND_CLAMP: + case LHSOUND_REPEAT_CLAMP: #define MIX_WRAP(datasi, si) ((datasi) = ((si) >= 0 && (si) < sample->length) ? data[(si)] : 0) #include "lhsound_mixloop.h" #undef MIX_WRAP break; - case LHSOUND_WRAP: + case LHSOUND_REPEAT_WRAP: #define MIX_WRAP(datasi, si) ((datasi) = ((si) >= 0 && (si) < sample->length) ? data[(si)] : data[(si) - ((si) / sample->length) * sample->length]) #include "lhsound_mixloop.h" #undef MIX_WRAP break; - case LHSOUND_REPEATSECTION: + case LHSOUND_REPEAT_REPEATSECTION: #define MIX_WRAP(datasi, si) ((datasi) = (si) >= 0 ? ((si) < sample->length ? data[(si)] : (data[(si) - ((si - sample->repeatposition) / (sample->length - sample->repeatposition)) * (sample->length - sample->repeatposition)])) : 0) #include "lhsound_mixloop.h" #undef MIX_WRAP Modified: trunk/system.c =================================================================== --- trunk/system.c 2006-03-05 06:36:45 UTC (rev 659) +++ trunk/system.c 2006-03-05 15:28:05 UTC (rev 660) @@ -1,3 +1,4 @@ +#define SYSTEM_IMPLEMENTATION #include "ncommon.h" #include "SDL.h" @@ -14,6 +15,10 @@ AudioState Audio; InputState Input; +static void Video_Frame(void); +static void Input_Frame(void); +static void Audio_Frame(void); + // private static SDL_Surface *Video_Surface; @@ -73,7 +78,7 @@ return true; } -void Video_Frame(void) +static void Video_Frame(void) { Video.framecount++; G_DrawFrame(); @@ -165,7 +170,7 @@ return true; } -void Audio_Frame(void) +static void Audio_Frame(void) { // TODO update something here? Audio.framecount++; @@ -179,7 +184,7 @@ } extern void G_Command_Quit(void); -void Input_Frame(void) +static void Input_Frame(void) { SDL_Event event; Modified: trunk/system.h =================================================================== --- trunk/system.h 2006-03-05 06:36:45 UTC (rev 659) +++ trunk/system.h 2006-03-05 15:28:05 UTC (rev 660) @@ -2,7 +2,6 @@ #ifndef SYSTEM_H #define SYSTEM_H - typedef struct SystemState { NUint argc; @@ -48,22 +47,27 @@ } InputState; -extern SystemState System; -extern VideoState Video; -extern AudioState Audio; -extern InputState Input; +#undef STATEMODIFIER +#ifndef SYSTEM_IMPLEMENTATION +# define STATEMODIFIER const +#else +# define STATEMODIFIER +#endif +extern STATEMODIFIER SystemState System; +extern STATEMODIFIER VideoState Video; +extern STATEMODIFIER AudioState Audio; +extern STATEMODIFIER InputState Input; + Nbool Video_SetMode(NUint width, NUint height, NUint bpp, Nbool fullscreen, Nbool openglmode); -void Video_Frame(void); Nbool Audio_SetMode(NUint rate, NUint channels); -void Audio_Frame(void); void Input_SetMode(Nbool grabmouse); -void Input_Frame(void); // calls Video_Frame, Audio_Frame, and Input_Frame void System_Frame(void); Ndouble System_Time(void); NUint32 System_CheckParm(const char *name, NUint32 requiredparms); +// these functions need to be implemented by the game system void G_KeyEvent(NUint mod, NUint sym, NUint character, Nbool downevent); void G_DrawFrame(void); void G_Main(void); From black at icculus.org Mon Mar 6 13:46:24 2006 From: black at icculus.org (black at icculus.org) Date: 6 Mar 2006 13:46:24 -0500 Subject: r661 - in trunk: . game Message-ID: <20060306184624.17228.qmail@icculus.org> Author: black Date: 2006-03-06 13:46:24 -0500 (Mon, 06 Mar 2006) New Revision: 661 Modified: trunk/game/g_audio.c trunk/game/g_main.c trunk/game/m_menucore.h trunk/lhsound.c trunk/lhsound.h trunk/sound.c trunk/sound.h Log: Added #ifndef... and a newline to m_menucore.h. Changed the script name for the shell commands executed in g_main.c. Added channel support to lhsound: lhsoundSample now takes a channelcount param which it uses as stride (with the info from providedformat). Changed sound to create a sample for each channel (up to 8) on load. Updated g_audio to always use channel 0 (perhaps add support for playing stereo music or surround ambient effects to the sound mixer later - I dont think its supporting multiple speakers correctly right now anyway). Modified: trunk/game/g_audio.c =================================================================== --- trunk/game/g_audio.c 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/game/g_audio.c 2006-03-06 18:46:24 UTC (rev 661) @@ -146,7 +146,8 @@ { // start mixing this sound sound = (Sound *)Resource_GetData(entity->sound.resourceindex); - lhsoundBindSample(sound->samplenumber); + //TODO: add support for multiple channels + lhsoundBindSample(sound->samplenumber[0]); lhsoundBegin(LHSOUND_RENDER_SEGMENT_STRIP); // output the previous mix point so that we have a valid // segment, all later points will be added individually Modified: trunk/game/g_main.c =================================================================== --- trunk/game/g_main.c 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/game/g_main.c 2006-03-06 18:46:24 UTC (rev 661) @@ -207,11 +207,11 @@ // run config scripts if (System_CheckParm("-dedicated", 0)) - Shell_ExecuteScript( "console", "exec server.cfg\n" ); + Shell_ExecuteScript( "init", "exec server.cfg\n" ); else { - Shell_ExecuteScript( "console", "exec default.cfg\n" ); - Shell_ExecuteScript( "console", "exec config.cfg\n" ); + Shell_ExecuteScript( "init", "exec default.cfg\n" ); + Shell_ExecuteScript( "init", "exec config.cfg\n" ); } // TODO: make a cvar able to change these Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/game/m_menucore.h 2006-03-06 18:46:24 UTC (rev 661) @@ -1,3 +1,7 @@ + +#ifndef M_MENUCORE_H +#define M_MENUCORE_H + typedef struct Menu_Inheritance { int addpos[2]; @@ -108,4 +112,6 @@ void Menu_Main(void); void Menu_Init(void); Nbool Menu_IsVisible(void); -Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent); \ No newline at end of file +Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent); + +#endif Modified: trunk/lhsound.c =================================================================== --- trunk/lhsound.c 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/lhsound.c 2006-03-06 18:46:24 UTC (rev 661) @@ -50,6 +50,7 @@ // used only during Begin...End lhsound_rendermode_t rendermode; + lhsound_bool_t mixbeginstate; // only true or false unsigned int numpoints; lhsound_point_t points[2]; @@ -145,12 +146,14 @@ } } -void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data) +void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data, unsigned channelcount) { unsigned int i; unsigned int bytes; lhsound_format_t internalformat; LHSOUNDASSERT(length >= 1, LHSOUND_ERROR_INVALID_VALUE); + LHSOUNDASSERT(channelcount >= 1, LHSOUND_ERROR_INVALID_VALUE); + LHSOUNDASSERT(data != LHSOUND_NULL, LHSOUND_ERROR_INVALID_VALUE); // decide which internal format and detect invalid formats // TODO: add swapped versions bytes = 1; @@ -191,7 +194,7 @@ { const unsigned char *in; signed char *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = *in - 128; out[0] = out[-1]; // for LINEAR resample } @@ -200,7 +203,7 @@ { const signed char *in; signed char *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = *in; out[0] = out[-1]; // for LINEAR resample } @@ -209,7 +212,7 @@ { const unsigned short *in; signed short *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = *in - 32768; out[0] = out[-1]; // for LINEAR resample } @@ -218,7 +221,7 @@ { const signed short *in; signed short *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = *in; out[0] = out[-1]; // for LINEAR resample } @@ -227,7 +230,7 @@ { const unsigned int *in; float *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = (float)((double)*in / (2048.0 * 1024.0 * 1024.0) - 1.0); out[0] = out[-1]; // for LINEAR resample } @@ -236,7 +239,7 @@ { const signed int *in; float *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = (float)((double)*in / (2048.0 * 1024.0 * 1024.0)); out[0] = out[-1]; // for LINEAR resample } @@ -245,7 +248,7 @@ { const float *in; float *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = *in; out[0] = out[-1]; // for LINEAR resample } @@ -254,7 +257,7 @@ { const double *in; float *out; - for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++) + for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) *out = *in; out[0] = out[-1]; // for LINEAR resample } @@ -458,18 +461,16 @@ { switch (pname) { - case LHSOUND_MIX_BUFFER_LENGTH:LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION);output[0] = lhsound_state.mixbufferlength;break; + case LHSOUND_MIX_BUFFER_LENGTH:LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_TRUE, LHSOUND_ERROR_INVALID_OPERATION);output[0] = lhsound_state.mixbufferlength;break; default:LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM);break; } } void lhsoundMixBegin(int bufferlength) { - LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); + LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_FALSE, LHSOUND_ERROR_INVALID_OPERATION); LHSOUNDASSERT(bufferlength >= 1 && bufferlength < 65536, LHSOUND_ERROR_INVALID_VALUE); - //FIXME: AK this is bad since it would allow a End call without a BeginCall - // but I guess its because of Geti, anyway, commented out since it should be solved somehow else - //lhsound_state.rendermode = LHSOUND_TRUE; + lhsound_state.mixbeginstate = LHSOUND_TRUE; if (lhsound_state.mixbufferlength != bufferlength) { lhsound_state.mixbufferlength = bufferlength; @@ -491,10 +492,10 @@ unsigned short s; } swaptest; - // FIXME: same as in mixbegin - LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION); + LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_TRUE, LHSOUND_ERROR_INVALID_OPERATION); LHSOUNDASSERT(bufferlength == lhsound_state.mixbufferlength, LHSOUND_ERROR_INVALID_VALUE); LHSOUNDASSERT(stride != 0, LHSOUND_ERROR_INVALID_VALUE); + lhsound_state.mixbeginstate = LHSOUND_FALSE; swaptest.s = 1; switch (format) { @@ -610,6 +611,6 @@ default: break; } - } + } } Modified: trunk/lhsound.h =================================================================== --- trunk/lhsound.h 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/lhsound.h 2006-03-06 18:46:24 UTC (rev 661) @@ -2,13 +2,19 @@ #ifndef LHSOUND_H #define LHSOUND_H +// FIXME: this isnt actually used at all, so better remove it if it stays this way.. #define LHSOUND_ZERO 0 #define LHSOUND_ONE 1 -#define LHSOUND_FALSE 0 -#define LHSOUND_TRUE 1 #define LHSOUND_NULL ((void *)0) +typedef enum lhsound_bool_e +{ + LHSOUND_FALSE, + LHSOUND_TRUE, +} +lhsound_bool_t; + typedef enum lhsound_error_e { LHSOUND_ERROR_NONE, @@ -100,7 +106,9 @@ void lhsoundGenSamples(int count, int *array); void lhsoundDeleteSamples(unsigned int count, int *array); -void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data); +// expects the data to be tightly packed, channelcount specifies the stride (actual stride = sizeof(providedformat)*channelcount) +// note that a sample can only contain one channel, so you have to create a sample for each channel of e.g. a stereo wave +void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data, unsigned channelcount); void lhsoundSampleParami(lhsound_sampleparam_t parameter, int value); void lhsoundBegin(lhsound_rendermode_t mode); Modified: trunk/sound.c =================================================================== --- trunk/sound.c 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/sound.c 2006-03-06 18:46:24 UTC (rev 661) @@ -195,44 +195,55 @@ void Sound_Load(ResourceEntry *r) { - int samplenumber; Sound *sound; SoundInfo info; + int channelcount; + int channel; + int samplenumber[SOUND_MAX_CHANNEL_COUNT]; + if (!Sound_LoadWaveFile(r->name, &info, r->memzone)) { Console_Printf("Sound_Load: failed to load \"%s\" - error: %s\n", r->name, info.errormessage); return; } - lhsoundGenSamples(1, &samplenumber); - lhsoundBindSample(samplenumber); - lhsoundSample(info.length, info.lhsoundformat, info.data); - // TODO: add mipmaps and use LHSOUND_LINEAR_MIPMAP_LINEAR - lhsoundSampleParami(LHSOUND_SAMPLE_MINFILTER, LHSOUND_LINEAR); - lhsoundSampleParami(LHSOUND_SAMPLE_MAGFILTER, LHSOUND_LINEAR); + // init the local decl + channelcount = Min(info.channels, SOUND_MAX_CHANNEL_COUNT); + lhsoundGenSamples(channelcount, &samplenumber[0]); + // bind the sounds and load them + for( channel = 0 ; channel < channelcount ; channel++ ) + { + void *channelStart = (NUint8*) info.data + channel * info.bytespersample; + + lhsoundBindSample(samplenumber[channel]); + lhsoundSample(info.length, info.lhsoundformat, channelStart, info.channels); + // TODO: add mipmaps and use LHSOUND_LINEAR_MIPMAP_LINEAR + lhsoundSampleParami(LHSOUND_SAMPLE_MINFILTER, LHSOUND_LINEAR); + lhsoundSampleParami(LHSOUND_SAMPLE_MAGFILTER, LHSOUND_LINEAR); + } lhsoundBindSample(0); // since no errors were encountered, set up the resource data now sound = Mem_Alloc(r->memzone, sizeof(Sound)); + sound->channels = channelcount; sound->speed = info.framespersecond; - sound->channels = info.channels; - sound->samplenumber = samplenumber; + for( channel = 0 ; channel < channelcount ; channel++ ) + sound->samplenumber[channel] = samplenumber[channel]; + r->data = (void *)sound; Mem_Free(info.data); } void Sound_Unload(ResourceEntry *r) { - int samplenumber; Sound *sound = (Sound *)r->data; - samplenumber = sound->samplenumber; - lhsoundDeleteSamples(1, &samplenumber); + lhsoundDeleteSamples(sound->channels, &sound->samplenumber[0]); } -NUint32 Sound_GetNumber(NUint32 resourceindex) +NUint32 Sound_GetNumber(NUint32 resourceindex, NUint32 channel) { Sound *sound = (Sound *)Resource_GetData(resourceindex); - if (!sound) + if (!sound || sound->channels >= channel) return 0; - return sound->samplenumber; + return sound->samplenumber[channel]; } Modified: trunk/sound.h =================================================================== --- trunk/sound.h 2006-03-05 15:28:05 UTC (rev 660) +++ trunk/sound.h 2006-03-06 18:46:24 UTC (rev 661) @@ -2,17 +2,20 @@ #ifndef SOUND_H #define SOUND_H +#define SOUND_MAX_CHANNEL_COUNT 8 + typedef struct Sound { NUint32 speed; NUint32 channels; - NUint32 samplenumber; + NUint32 samplenumber[SOUND_MAX_CHANNEL_COUNT]; } Sound; void Sound_Load(ResourceEntry *r); void Sound_Unload(ResourceEntry *r); -NUint32 Sound_GetNumber(NUint32 resourceindex); +// FIXME: use this function in g_audio perhaps? +NUint32 Sound_GetNumber(NUint32 resourceindex, NUint32 channel); #endif From black at icculus.org Mon Mar 6 18:01:25 2006 From: black at icculus.org (black at icculus.org) Date: 6 Mar 2006 18:01:25 -0500 Subject: r662 - trunk Message-ID: <20060306230125.20747.qmail@icculus.org> Author: black Date: 2006-03-06 18:01:25 -0500 (Mon, 06 Mar 2006) New Revision: 662 Modified: trunk/lhsound.c trunk/lhsound.h trunk/sound.c trunk/system.c trunk/system.h trunk/todo Log: Some minor changes, mostly code reviewing and fixing possible bugs. Modified: trunk/lhsound.c =================================================================== --- trunk/lhsound.c 2006-03-06 18:46:24 UTC (rev 661) +++ trunk/lhsound.c 2006-03-06 23:01:25 UTC (rev 662) @@ -33,9 +33,9 @@ lhsound_point_t; // FIXME: allocate someday -#define LHSOUND_MAX_SAMPLES 65536 +#define LHSOUND_MAX_SAMPLES 65536U // FIXME: make configurable -#define LHSOUND_MAX_MIXBUFFERLENGTH 8192 +#define LHSOUND_MAX_MIXBUFFERLENGTH 65535U static struct lhsound_state_s { @@ -70,7 +70,7 @@ return n; } -static void *lhsoundAllocateMemory(int size) +static void *lhsoundAllocateMemory(unsigned int size) { return malloc(size); } @@ -80,14 +80,14 @@ free(memory); } -static void lhsoundClearMemory(void *memory, int fill, int size) +static void lhsoundClearMemory(void *memory, int fill, unsigned int size) { memset(memory, fill, size); } -static void lhsoundExpandSamplesArray(int number) +static void lhsoundExpandSamplesArray(unsigned int number) { - // FIXME: this crashes if number is >= lhsound_state.maxsamples + LHSOUNDASSERT(number < lhsound_state.maxsamples, LHSOUND_ERROR_OUT_OF_MEMORY); while (number >= lhsound_state.numsamples) { lhsoundClearMemory(&lhsound_state.samples[lhsound_state.numsamples], 0, sizeof(lhsound_sample_t)); @@ -111,24 +111,27 @@ } } -void lhsoundGenSamples(int count, int *array) +void lhsoundGenSamples(unsigned int count, unsigned int *array) { - int i; + unsigned int i; LHSOUNDASSERT(count > 0, LHSOUND_ERROR_INVALID_VALUE); // TODO: add a firstunused optimization - for (i = 1;count > 0;count--) + for (i = 1;i < LHSOUND_MAX_SAMPLES;i++) { - LHSOUNDASSERT(i < LHSOUND_MAX_SAMPLES, LHSOUND_ERROR_OUT_OF_MEMORY); lhsoundExpandSamplesArray(i); if (!lhsound_state.samples[i].used) { lhsound_state.samples[i].used = LHSOUND_TRUE; - *array++ = i++; + *array++ = i; + if( --count == 0 ) { + return; + } } } + LHSOUNDERROR(LHSOUND_ERROR_OUT_OF_MEMORY); } -void lhsoundDeleteSamples(unsigned int count, int *array) +void lhsoundDeleteSamples(unsigned int count, unsigned int *array) { unsigned int i; for (i = 0;i < count;i++) @@ -146,7 +149,7 @@ } } -void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data, unsigned channelcount) +void lhsoundSample(unsigned int length, lhsound_format_t providedformat, unsigned int channelcount, const void *data) { unsigned int i; unsigned int bytes; @@ -258,7 +261,7 @@ const double *in; float *out; for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++) - *out = *in; + *out = (float) *in; out[0] = out[-1]; // for LINEAR resample } break; @@ -276,6 +279,7 @@ { case LHSOUND_REPEAT_CLAMP: case LHSOUND_REPEAT_WRAP: + case LHSOUND_REPEAT_REPEATSECTION: lhsound_state.boundsample->repeatmode = value; break; default: @@ -284,6 +288,7 @@ } break; case LHSOUND_SAMPLE_REPEATPOSITION: + // FIXME: this should actually passed as clamped float since lhSoundPoint takes the time in the 0..1 range, too LHSOUNDASSERT(value >= 0 && value < lhsound_state.boundsample->length, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.boundsample->repeatposition = value; break; @@ -428,8 +433,10 @@ lhsound_state.maxsamples = sizeof(lhsound_state.samples) / sizeof(lhsound_sample_t); lhsound_state.numsamples = 1; + lhsound_state.boundsampleindex = 0; lhsound_state.boundsample = lhsound_state.samples; + // init the default sample with our default states lhsound_state.boundsample->used = LHSOUND_TRUE; lhsound_state.boundsample->internalformat = LHSOUND_SIGNED_BYTE; lhsound_state.boundsample->repeatmode = LHSOUND_REPEAT_CLAMP; @@ -444,11 +451,15 @@ lhsound_state.errornum = LHSOUND_ERROR_NONE; + lhsound_state.mixbeginstate = LHSOUND_FALSE; lhsound_state.mixbufferlength = 0; } void lhsoundShutdown(void) { + if( lhsound_state.mixbuffer != LHSOUND_NULL ) + lhsoundFreeMemory(lhsound_state.mixbuffer); + while (lhsound_state.numsamples > 0) { int number = --lhsound_state.numsamples; @@ -466,25 +477,28 @@ } } -void lhsoundMixBegin(int bufferlength) +void lhsoundMixBegin(unsigned int bufferlength) { LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_FALSE, LHSOUND_ERROR_INVALID_OPERATION); - LHSOUNDASSERT(bufferlength >= 1 && bufferlength < 65536, LHSOUND_ERROR_INVALID_VALUE); + LHSOUNDASSERT(bufferlength >= 1 && bufferlength < LHSOUND_MAX_MIXBUFFERLENGTH, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.mixbeginstate = LHSOUND_TRUE; if (lhsound_state.mixbufferlength != bufferlength) { + // free the old buffer (if existing) + if (lhsound_state.mixbuffer != LHSOUND_NULL) + lhsoundFreeMemory(lhsound_state.mixbuffer); + lhsound_state.mixbufferlength = bufferlength; lhsound_state.mixbuffer = lhsoundAllocateMemory(lhsound_state.mixbufferlength * sizeof(*lhsound_state.mixbuffer)); } lhsoundClearMemory(lhsound_state.mixbuffer, 0, lhsound_state.mixbufferlength * sizeof(*lhsound_state.mixbuffer)); } -void lhsoundMixEnd(lhsound_format_t format, size_t stride, void *output, int bufferlength) +void lhsoundMixEnd(unsigned int bufferlength, lhsound_format_t format, unsigned int stride, void *output) { - int i; - int ival; - float fval; + unsigned int i; unsigned char *out; + // the swaptest is fast even if its bloats the code a bit, so lets keep it here.. int swap; union swaptest_u { @@ -496,6 +510,7 @@ LHSOUNDASSERT(bufferlength == lhsound_state.mixbufferlength, LHSOUND_ERROR_INVALID_VALUE); LHSOUNDASSERT(stride != 0, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.mixbeginstate = LHSOUND_FALSE; + swaptest.s = 1; switch (format) { @@ -527,6 +542,7 @@ case LHSOUND_UNSIGNED_BYTE: for (i = 0;i < bufferlength;i++, out += stride) { + int ival; ival = (int)floor(lhsound_state.mixbuffer[i] * 127.5f + 128.0f); ival = ival >= 0 ? (ival <= 255 ? ival : 255) : 0; *((unsigned char *)out) = (unsigned char)ival; @@ -535,6 +551,7 @@ case LHSOUND_SIGNED_BYTE: for (i = 0;i < bufferlength;i++, out += stride) { + int ival; ival = (int)floor(lhsound_state.mixbuffer[i] * 127.5f); ival = ival >= -128 ? (ival <= 127 ? ival : 127) : -128; *((signed char *)out) = (signed char)ival; @@ -543,6 +560,7 @@ case LHSOUND_UNSIGNED_SHORT: for (i = 0;i < bufferlength;i++, out += stride) { + int ival; ival = (int)floor(lhsound_state.mixbuffer[i] * 32767.5f + 32768.0f); ival = ival >= 0 ? (ival <= 65535 ? ival : 65535) : 0; *((unsigned short *)out) = (unsigned short)ival; @@ -551,6 +569,7 @@ case LHSOUND_SIGNED_SHORT: for (i = 0;i < bufferlength;i++, out += stride) { + int ival; ival = (int)floor(lhsound_state.mixbuffer[i] * 32767.5f); ival = ival >= -32768 ? (ival <= 32767 ? ival : 32767) : -32768; *((signed short *)out) = (signed short)ival; @@ -559,6 +578,7 @@ case LHSOUND_UNSIGNED_INT: for (i = 0;i < bufferlength;i++, out += stride) { + float fval; fval = lhsound_state.mixbuffer[i]; fval = fval >= -1.0f ? (fval <= 1.0f ? fval : 1.0f) : -1.0f; *((unsigned int *)out) = (unsigned int)floor(fval * (65536.0 * 32768.0 - 0.5) + (65536.0 * 32768.0)); @@ -567,6 +587,7 @@ case LHSOUND_SIGNED_INT: for (i = 0;i < bufferlength;i++, out += stride) { + float fval; fval = lhsound_state.mixbuffer[i]; fval = fval >= -1.0f ? (fval <= 1.0f ? fval : 1.0f) : -1.0f; *((signed int *)out) = (signed int)floor(fval * (65536.0 * 32768.0 - 0.5)); @@ -582,7 +603,6 @@ } if (swap) { - unsigned char a, b; out = (unsigned char *)output; switch(format) { @@ -590,6 +610,8 @@ case LHSOUND_SIGNED_SHORT: for (i = 0;i < bufferlength;i++, out += stride) { + unsigned char a; + a = out[0]; out[0] = out[1]; out[1] = a; @@ -600,6 +622,8 @@ case LHSOUND_FLOAT: for (i = 0;i < bufferlength;i++, out += stride) { + unsigned char a, b; + a = out[0]; b = out[1]; out[0] = out[3]; Modified: trunk/lhsound.h =================================================================== --- trunk/lhsound.h 2006-03-06 18:46:24 UTC (rev 661) +++ trunk/lhsound.h 2006-03-06 23:01:25 UTC (rev 662) @@ -103,12 +103,12 @@ void lhsoundGeti(lhsound_queryname_t pname, int *output); void lhsoundBindSample(unsigned int number); -void lhsoundGenSamples(int count, int *array); -void lhsoundDeleteSamples(unsigned int count, int *array); +void lhsoundGenSamples(unsigned int count, unsigned int *array); +void lhsoundDeleteSamples(unsigned int count, unsigned int *array); // expects the data to be tightly packed, channelcount specifies the stride (actual stride = sizeof(providedformat)*channelcount) // note that a sample can only contain one channel, so you have to create a sample for each channel of e.g. a stereo wave -void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data, unsigned channelcount); +void lhsoundSample(unsigned int length, lhsound_format_t providedformat, unsigned int channelcount, const void *data); void lhsoundSampleParami(lhsound_sampleparam_t parameter, int value); void lhsoundBegin(lhsound_rendermode_t mode); @@ -118,7 +118,7 @@ void lhsoundInit(void); void lhsoundShutdown(void); -void lhsoundMixBegin(int bufferlength); -void lhsoundMixEnd(lhsound_format_t format, size_t stride, void *output, int bufferlength); +void lhsoundMixBegin(unsigned int bufferlength); +void lhsoundMixEnd(unsigned int bufferlength, lhsound_format_t format, unsigned int stride, void *output); #endif Modified: trunk/sound.c =================================================================== --- trunk/sound.c 2006-03-06 18:46:24 UTC (rev 661) +++ trunk/sound.c 2006-03-06 23:01:25 UTC (rev 662) @@ -215,7 +215,7 @@ void *channelStart = (NUint8*) info.data + channel * info.bytespersample; lhsoundBindSample(samplenumber[channel]); - lhsoundSample(info.length, info.lhsoundformat, channelStart, info.channels); + lhsoundSample(info.length, info.lhsoundformat, info.channels, channelStart); // TODO: add mipmaps and use LHSOUND_LINEAR_MIPMAP_LINEAR lhsoundSampleParami(LHSOUND_SAMPLE_MINFILTER, LHSOUND_LINEAR); lhsoundSampleParami(LHSOUND_SAMPLE_MAGFILTER, LHSOUND_LINEAR); Modified: trunk/system.c =================================================================== --- trunk/system.c 2006-03-06 18:46:24 UTC (rev 661) +++ trunk/system.c 2006-03-06 23:01:25 UTC (rev 662) @@ -102,14 +102,14 @@ static void Audio_Callback(void *userdata, NUint8 *stream, int len) { - int speakerindex; - int bufferlength = len / Audio.bytespersampleframe; + NUint speakerindex; + NUint bufferlength = len / Audio.bytesperframe; Audio.callbackcount++; for (speakerindex = 0;speakerindex < Audio.speakers;speakerindex++) { lhsoundMixBegin(bufferlength); G_AudioMix(bufferlength); - lhsoundMixEnd(Audio.lhsoundformat, Audio.bytespersampleframe, (void *)(stream + speakerindex * Audio.bytespersample), bufferlength); + lhsoundMixEnd(bufferlength, Audio.lhsoundformat, Audio.bytesperframe, (void *)(stream + speakerindex * Audio.bytespersample)); } } @@ -159,7 +159,7 @@ Audio.speakers = speakers; Audio.lhsoundformat = LHSOUND_SIGNED_SHORT; Audio.bytespersample = sizeof(short); - Audio.bytespersampleframe = speakers * Audio.bytespersample; + Audio.bytesperframe = speakers * Audio.bytespersample; SDL_PauseAudio(false); } else @@ -176,6 +176,16 @@ Audio.framecount++; } +static void Audio_Init(void) +{ + lhsoundInit(); +} + +static void Audio_Quit(void) +{ + lhsoundShutdown(); +} + // input section void Input_SetMode(Nbool grabmouse) @@ -316,6 +326,7 @@ File_Init(); File_Start(".", "~/.darkwar/"); File_AddPath("base/"); + Audio_Init(); // FIXME: check system memory to decide how much resource memory to use // 128mb memory for resources Resource_Init(128 * (1 << 20)); @@ -323,7 +334,7 @@ G_Main(); Util_Quit(); Resource_Quit(); - S_Quit(); + Audio_Quit(); R_Quit(); File_Quit(); DynGL_CloseLibrary (); Modified: trunk/system.h =================================================================== --- trunk/system.h 2006-03-06 18:46:24 UTC (rev 661) +++ trunk/system.h 2006-03-06 23:01:25 UTC (rev 662) @@ -30,7 +30,7 @@ NUint speakers; NUint lhsoundformat; NUint bytespersample; - NUint bytespersampleframe; + NUint bytesperframe; } AudioState; Modified: trunk/todo =================================================================== --- trunk/todo 2006-03-06 18:46:24 UTC (rev 661) +++ trunk/todo 2006-03-06 23:01:25 UTC (rev 662) @@ -7,6 +7,7 @@ 0 feature darkwar console: add mousewheel scrolling of console 0 feature darkwar console: condump cvar to dump console history (Kazashi) 0 feature darkwar input: add a mouse inversion cvar (Sajt) +0 fixme darkwar sound: figure out whether we need s_main.c/h at all and what do with Audio_Init/Shutdown 1 change darkwar filesystem: use shGetSpecialFolderPath with CSIDL_PERSONAL to get the My Documents directory path, and use My Documents/DarkWar as the user path (Black) 2 feature darkwar console: console_logfile cvar (Kazashi) 4 change darkwar drawview: redesign G_DrawView to allow different scope flags on each surface of an entity From spike at icculus.org Tue Mar 7 21:19:29 2006 From: spike at icculus.org (spike at icculus.org) Date: 7 Mar 2006 21:19:29 -0500 Subject: r663 - trunk Message-ID: <20060308021929.22458.qmail@icculus.org> Author: spike Date: 2006-03-07 21:19:29 -0500 (Tue, 07 Mar 2006) New Revision: 663 Modified: trunk/system.c Log: make sure the driver is switched off before the mixer dies (SDL runs in a seperate thread) (yes, this did just crash on me for this reason). Modified: trunk/system.c =================================================================== --- trunk/system.c 2006-03-06 23:01:25 UTC (rev 662) +++ trunk/system.c 2006-03-08 02:19:29 UTC (rev 663) @@ -183,6 +183,7 @@ static void Audio_Quit(void) { + Audio_SetMode(0, 0); //shut down the driver lhsoundShutdown(); } From spike at icculus.org Tue Mar 7 21:30:28 2006 From: spike at icculus.org (spike at icculus.org) Date: 7 Mar 2006 21:30:28 -0500 Subject: r664 - trunk/game Message-ID: <20060308023028.23850.qmail@icculus.org> Author: spike Date: 2006-03-07 21:30:28 -0500 (Tue, 07 Mar 2006) New Revision: 664 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: Added editable(edit) items and List-Of-Values(combo) menu item types. Added test/demo items to the main menu. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-08 02:19:29 UTC (rev 663) +++ trunk/game/m_menucore.c 2006-03-08 02:30:28 UTC (rev 664) @@ -115,6 +115,10 @@ if (thisi->parent->selecteditem == item) thisi->parent->selecteditem = NULL; Menu_RemoveFromParent(item); + + if (Menu.grabs == item) + Menu.grabs = NULL; //hrm. + Mem_Free(&item); } Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, int x, int y, int bytes) @@ -153,18 +157,23 @@ R_SetTexture(R.resource_font); R_DrawString(thisi->text, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); } +void Menu_Text_DefaultUse (struct Menu_TextItem *item) +{ + Shell_ExecuteScript("console", item->command); +} Nbool Menu_Text_KeyPress (void *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { Menu_TextItem *thisi = item; if (sym == SDLK_RETURN || sym == MOUSE1) { if (downevent) - Shell_ExecuteScript("console", thisi->command); + if (thisi->UseTextItem) + thisi->UseTextItem(thisi); return true; } return false; } -Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, int x, int y, char *text, char *command) +Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, int x, int y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)) { Menu_TextItem *it; it = (Menu_TextItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_TextItem)); @@ -181,17 +190,276 @@ it->text = text; it->command = command; + if (UseTextItem == NULL && command) + UseTextItem = Menu_Text_DefaultUse; + + it->UseTextItem = UseTextItem; + return it; } +//text-edit fields +//fixme: only work with grabs? +void Menu_DrawEditItem(void *item, Menu_Inheritance *inh) +{ + Menu_EditItem *thisi = item; + R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + R_SetTexture(R.resource_font); + R_DrawString(thisi->text, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + if (thisi->super.parent->selecteditem == &thisi->super) + R_DrawString("_", 0, thisi->super.pos[0] + inh->addpos[0] + thisi->cursorpos*8, thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, 0); +} +Nbool Menu_Edit_KeyPress (void *item, UNUSED NUint mod, NUint sym, NUint character, Nbool downevent) +{ + Menu_EditItem *thisi = item; + if (sym == SDLK_RETURN || sym == MOUSE1) + { +// if (downevent) +// Shell_ExecuteScript("console", thisi->command); + return true; + } + if (sym == SDLK_BACKSPACE) + { + if (!downevent) + return true; + if (!thisi->cursorpos) + { + if (*thisi->text) + thisi->cursorpos = 1; + else + return true; + } + memmove(thisi->text+thisi->cursorpos-1, thisi->text+thisi->cursorpos, strlen(thisi->text+thisi->cursorpos)+1); + thisi->cursorpos--; + return true; + } + if (sym == SDLK_HOME) + { + thisi->cursorpos = 0; + return true; + } + if (sym == SDLK_END) + { + thisi->cursorpos = strlen(thisi->text); + return true; + } + if (sym == SDLK_LEFT) + { + thisi->cursorpos -= downevent; + if (thisi->cursorpos < 0) + thisi->cursorpos = 0; + return true; + } + if (sym == SDLK_RIGHT) + { + thisi->cursorpos += downevent; + if (thisi->cursorpos > strlen(thisi->text)) + thisi->cursorpos = strlen(thisi->text); + return true; + } + if (character && character != SDLK_TAB) + { + char *newt; + if (!downevent) + return true; + if (thisi->maxchars && thisi->maxchars <= strlen(thisi->text)) + return true; //already reached the max + newt = Mem_Alloc(Menu.menu_zone, strlen(thisi->text)+2); + memcpy(newt, thisi->text, thisi->cursorpos); + memcpy(newt+thisi->cursorpos+1, thisi->text+thisi->cursorpos, strlen(thisi->text+thisi->cursorpos)+1); + newt[thisi->cursorpos] = character; + Mem_Free(&thisi->text); + thisi->text = newt; + + thisi->cursorpos++; + return true; + } + return false; +} +Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, int x, int y, char *text) +{ + Menu_EditItem *it; + it = (Menu_EditItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_EditItem)); + + it->super.DrawMenu = Menu_DrawEditItem; + it->super.MouseMove = Menu_Generic_MouseMoveSelectable; + it->super.KeyEvent = Menu_Edit_KeyPress; + it->super.size[0] = 8*strlen(text); + it->super.size[1] = 8; + + //FIXME: No delete to free the text + it->text = Mem_Alloc(Menu.menu_zone, strlen(text)+1); + strcpy(it->text, text); + it->cursorpos = strlen(text); +// it->command = command; + + return it; +} + + + + + + + + + + +//combos +void Menu_DrawComboItem(void *item, Menu_Inheritance *inh) +{ + Menu_ComboItem *thisi = item; + R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + R_SetTexture(R.resource_font); + R_DrawString(thisi->text, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + + R_DrawString("V", 0, thisi->super.pos[0] + thisi->super.size[0]-8 + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); +} + +void Menu_Combo_SetText(Menu_ComboItem *thisi, char *text)//it's just easier. not sure weather this should be public or not. +{ + Menu_ComboOption *option; + char *oldtext; + oldtext = thisi->text; + thisi->text = Mem_Alloc(Menu.menu_zone, strlen(text)+1); + strcpy(thisi->text, text); + + thisi->selected = NULL; + for (option = thisi->options; option; option = option->next) + { + if (!strcmp(option->text, text)) + { + thisi->selected = option; + break; + } + } + + Mem_Free(&oldtext); +} + +void Menu_ComboSlider (struct Menu_SliderItem *slider) +{ + Menu_SubMenu *thisi = slider->data; + thisi->subwindow.pos[1] = -slider->value; +} +void Menu_UseOption (Menu_TextItem *it) +{ + Menu_ComboItem *thisi = (void*)it->command; + Menu_Combo_SetText(thisi, it->text); + + //seeing as this happens from a key event, and the text control will return true, we can safly kill the popup + thisi->popup->super.Destroy(thisi->popup); +} + + +Nbool Menu_Combo_KeyPress (void *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent) +{ + int i; + Menu_TextItem *txt; + Menu_ComboItem *thisi = item; + Menu_ComboOption *option; + Menu_SubMenu *interior; + int pixels; + if (sym == SDLK_RETURN || sym == MOUSE1) + { + thisi->popup = Menu_CreateMenu(&Menu.rootmenu); + Menu_BringToFront(thisi->popup); + interior = Menu_CreateMenu(thisi->popup); + interior->allowclose = false; + Menu.grabs = &thisi->popup->super; + option = thisi->options; + for (i = 0; option; i+=8, option = option->next) + { + txt = Menu_CreateTextItem(interior, 0, i, option->text, thisi, Menu_UseOption); + txt->super.size[0] = thisi->super.size[0] - 8; + } + pixels = i-64; + if (pixels < 0) + pixels = 0; + Menu_CreateVSliderItem(thisi->popup, thisi->super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_ComboSlider, NULL, interior); + + thisi->popup->super.pos[0] = Input.mouse[0]; + thisi->popup->super.pos[1] = Input.mouse[1]; + + thisi->popup->subwindow.pos[0] = thisi->popup->super.pos[0]; + thisi->popup->subwindow.pos[1] = thisi->popup->super.pos[1]; + Menu_FinishMenu(interior); + interior->super.size[1] = ((i>64)?64:i); + Menu_FinishMenu(thisi->popup); + return true; + } + return false; +} + +void Menu_Combo_Destroy(void *item) +{ + Menu_ComboItem *combo = item; + if (combo->popup) + combo->popup->super.Destroy(combo->popup); + Menu_Generic_Destroy(item); +} + +Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, int x, int y, int w, char *defalt, char *list) +{ + char *pipe; + int chars; + int ident; + Menu_ComboOption *option; + //list is pipe-sperated + Menu_ComboItem *it; + it = (Menu_ComboItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_ComboItem)); + + it->super.DrawMenu = Menu_DrawComboItem; + it->super.MouseMove = Menu_Generic_MouseMoveSelectable; + it->super.KeyEvent = Menu_Combo_KeyPress; + it->super.Destroy = Menu_Combo_Destroy; + it->super.size[0] = w; + it->super.size[1] = 8; + + //FIXME: no delete to free the text + it->text = Mem_Alloc(Menu.menu_zone, strlen(defalt)+1); + strcpy(it->text, defalt); + + if (*list) + { + ident = 0; + for (pipe = list; ; pipe++) + { + if (*pipe == '|' || *pipe == '\0') + { + chars = pipe - list; + + option = Mem_Alloc(Menu.menu_zone, sizeof(Menu_ComboOption) + chars+1); + option->text = (char*)(option+1); + option->ident = ident++; + strncpy(option->text, list, chars); + option->text[chars] = '\0'; + option->next = it->options; + it->options = option; + + if (*pipe == '\0') + break; + pipe++; + list = pipe; + } + } + } + + return it; +} + + + + + //picture items void Menu_Picture_Draw(void *item, Menu_Inheritance *inh) { @@ -427,7 +695,7 @@ int j; int wmin, wmax; - if (Menu.grabs == &thisi->super) + if (Menu.grabs == &thisi->super && thisi->dragable) { thisi->subwindow.pos[0] += Input.mouse[0] - thisi->dragmousepos[0]; thisi->subwindow.pos[1] += Input.mouse[1] - thisi->dragmousepos[1]; @@ -478,7 +746,7 @@ void Menu_DrawSubMenu(void *item, Menu_Inheritance *inh) { Menu_SubMenu *thisi = item; - Menu_Item *subitem; + Menu_Item *subitem, *next; Menu_Inheritance ninh; int wmin, wmax; int j; @@ -507,8 +775,11 @@ R_SetScissor(ninh.window.pos[0], ninh.window.pos[1], ninh.window.size[0], ninh.window.size[1]); - for (subitem = thisi->subitems; subitem; subitem = subitem->next) + for (subitem = thisi->subitems; subitem; subitem = next) + { + next = subitem->next;//this funkyness is so that we can unlink and kill things in the draw function (if the need arises). subitem->DrawMenu(subitem, &ninh); + } R_SetScissor(inh->window.pos[0], inh->window.pos[1], inh->window.size[0], inh->window.size[1]); } @@ -637,41 +908,52 @@ void Menu_ArrangeSubItems(Menu_SubMenu *menu, Nbool horizontal, int pad, Menu_ArrangeStyle arrange) { Menu_Item *sitem; - int side; + int axis, otheraxis; int val = 0; int maxval=0; + //axis is usually the 'vertical' axis, where each field is spaced with padding + //otheraxis is the axis on which we align stuff (rather than just space it) + if (horizontal) - side = 0; + axis = 0; else - side = 1; + axis = 1; + otheraxis = !axis; + for (sitem = menu->subitems; sitem; sitem = sitem->next) { - sitem->pos[side] = maxval; - maxval += sitem->size[side] + pad; + sitem->pos[axis] = maxval; + maxval += sitem->size[axis] + pad; } val = maxval; for (sitem = menu->subitems; sitem; sitem = sitem->next) { - val -= sitem->size[side] + pad; - sitem->pos[side] = val; + val -= sitem->size[axis] + pad; + sitem->pos[axis] = val; switch(arrange) { + case MENU_ARRANGESTYLE_LEAVEALONE: + break; + case MENU_ARRANGESTYLE_LEFT: - sitem->pos[side^1] = 0; + sitem->pos[otheraxis] = 0; break; + case MENU_ARRANGESTYLE_CENTER: - sitem->pos[side^1] = (menu->subwindow.size[side^1] - sitem->size[side^1])/2; + sitem->pos[otheraxis] = (menu->subwindow.size[otheraxis] - sitem->size[otheraxis])/2; break; + case MENU_ARRANGESTYLE_RIGHT: - sitem->pos[side^1] = (menu->subwindow.size[side^1] - sitem->size[side^1]); + sitem->pos[otheraxis] = (menu->subwindow.size[otheraxis] - sitem->size[otheraxis]); break; + case MENU_ARRANGESTYLE_RESIZE: - sitem->pos[side^1] = 0; - sitem->size[side^1] = menu->subwindow.size[side^1]; + sitem->pos[otheraxis] = 0; + sitem->size[otheraxis] = menu->subwindow.size[otheraxis]; break; } } @@ -708,6 +990,19 @@ + + + + + + + + + + + + + float sliderscale = 8; float imagesize = 512; float windowsize = 128; @@ -782,17 +1077,20 @@ Menu_SubMenu *menu = Menu_CreateMenu(&Menu.rootmenu); menu->dragable = true; - Menu_CreateTextItem(menu, 0, 0, "Main menu", NULL); + Menu_CreateTextItem(menu, 0, 0, "Main menu", NULL, NULL); - Menu_CreateTextItem(menu, 0, 16, "Hello World", "echo Hello World\n"); - Menu_CreateTextItem(menu, 0, 24, "Start up test map", "map test\n"); - Menu_CreateTextItem(menu, 0, 32, "Go to the west!", "map west\n"); - Menu_CreateTextItem(menu, 0, 40, "quit", "menu_quit\n"); + Menu_CreateTextItem(menu, 0, 16, "Hello World", "echo Hello World\n", NULL); + Menu_CreateTextItem(menu, 0, 24, "Start up test map", "map test\n", NULL); + Menu_CreateTextItem(menu, 0, 32, "Go to the west!", "map west\n", NULL); + Menu_CreateTextItem(menu, 0, 40, "quit", "menu_quit\n", NULL); - Menu_CreateTextItem(menu, 0, 56, "Close menu", "menu_close\n"); + Menu_CreateTextItem(menu, 0, 56, "Close menu", "menu_close\n", NULL); - Menu_CreateTextItem(menu, 0, 56+16, "test menu", "menu_test\n"); + Menu_CreateTextItem(menu, 0, 56+16, "test menu", "menu_test\n", NULL); + Menu_CreateEditItem(menu, 0, 56, "EditItem"); + Menu_CreateComboItem(menu, 0, 56, 21*8, "ComboItem", "Option 1|Option 2|Option 3|Fuzzy Little Bunnies|Big Rocket Launcher|Children|Lightning Gun|Newborn Chicks|Grenade Launcher|Rodents|Nukes"); + Menu_FinishMenu(menu); Menu_ArrangeSubItems(menu, false, 0, MENU_ARRANGESTYLE_CENTER); Menu_FinishMenu(menu); @@ -833,10 +1131,10 @@ Menu_SubMenu *menu = Menu_CreateMenu(&Menu.rootmenu); menu->dragable = true; - Menu_CreateTextItem(menu, 0, 0, "Really Quit?", NULL); + Menu_CreateTextItem(menu, 0, 0, "Really Quit?", NULL, NULL); - Menu_CreateTextItem(menu, 0, 16, "Yes, and wipe my harddrive too.", "quit\n"); - Menu_CreateTextItem(menu, 0, 24, "No. I want to keep playing this awesome game", "menu_close\n"); + Menu_CreateTextItem(menu, 0, 16, "Yes, and wipe my harddrive too.", "quit\n", NULL); + Menu_CreateTextItem(menu, 0, 24, "No. I want to keep playing this awesome game", "menu_close\n", NULL); Menu_FinishMenu(menu); Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-08 02:19:29 UTC (rev 663) +++ trunk/game/m_menucore.h 2006-03-08 02:30:28 UTC (rev 664) @@ -54,17 +54,55 @@ { Menu_Item super; - char *text; - char *command; //it's handy + char *text; //what to display (warning: it's a pointer, isn't freed, and isn't copied) + void *command; //command is a misnomer, it should be used as a cookie for the text item + + void (*UseTextItem) (struct Menu_TextItem *item); //called when the user uses this item } Menu_TextItem; +typedef struct Menu_EditItem +{ + Menu_Item super; + + char *text; //what it currently says + int cursorpos; //where the cursor is, set between 0 and strlen(text) + int scrollpos; //fixme + int maxchars; //0 for unlimited +} +Menu_EditItem; + +typedef struct Menu_ComboOption +{ + char *text; //the text of the item + int ident; //if you wish to assosiate an int key with the item. + struct Menu_ComboOption *next; +} +Menu_ComboOption; + +typedef struct Menu_ComboItem +{ + Menu_Item super; + + Nbool editable; //user may type into the control + struct Menu_ComboOption *options; //a list of the current options + struct Menu_ComboOption *selected; //set + + char *text; + int cursorpos; + int scrollpos; + int maxchars; + + struct Menu_SubMenu *popup; +} +Menu_ComboItem; + typedef struct Menu_PictureItem { Menu_Item super; char *imagename; - char *command; //it's handy + char *command; //console command when clicked } Menu_PictureItem; @@ -75,22 +113,23 @@ void *data; //for custom stuff float value;//set and used in the slider code - float minv; - float maxv; + float minv;//min value + float maxv;//max (can be inverted) - float scale; + float scale;//size of slider, in pixels. //notification function void (*SliderChanged) (struct Menu_SliderItem *slider); //the user just changed the slider->value void (*SliderUpdate) (struct Menu_SliderItem *slider); //about to draw the slider's value, where you should feel free to update the value from external sources //internal - Nbool mousepressed; + Nbool mousepressed; //adjust the slider with the mouse } Menu_SliderItem; typedef enum Menu_ArrangeStyle { + MENU_ARRANGESTYLE_LEAVEALONE, MENU_ARRANGESTYLE_LEFT, MENU_ARRANGESTYLE_CENTER, MENU_ARRANGESTYLE_RIGHT, @@ -114,4 +153,13 @@ Nbool Menu_IsVisible(void); Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent); + +Menu_SubMenu *Menu_CreateMenu(Menu_SubMenu *parent); +Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, int x, int y, int w, int h, float minv, float maxv, float defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//vertical scrolling bar +Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, int x, int y, int w, int h, float minv, float maxv, float defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//horizontal scrolling bar +Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, int x, int y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. +Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, int x, int y, char *text); //an item for editing text (fixme: needs callbacks and stuff) +Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, int x, int y, int w, char *defalt, char *list);//a list of multiple choices. +Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, int x, int y, int w, int h, char *imagename, char *command); //just a simple picture. clicking it can give a console command (fixme: make like text) + #endif From sajt at icculus.org Wed Mar 8 12:08:05 2006 From: sajt at icculus.org (sajt at icculus.org) Date: 8 Mar 2006 12:08:05 -0500 Subject: r665 - trunk Message-ID: <20060308170805.13553.qmail@icculus.org> Author: sajt Date: 2006-03-08 12:08:05 -0500 (Wed, 08 Mar 2006) New Revision: 665 Modified: trunk/TODO.txt Log: Testing Modified: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2006-03-08 02:30:28 UTC (rev 664) +++ trunk/TODO.txt 2006-03-08 17:08:05 UTC (rev 665) @@ -61,6 +61,7 @@ still figuring out how to write LISP interpreters... and now distracted by other things. Black: This can be regarded as done. +Sajt: Howdedoodee. ============================================================================== From sajt at icculus.org Wed Mar 8 12:15:53 2006 From: sajt at icculus.org (sajt at icculus.org) Date: 8 Mar 2006 12:15:53 -0500 Subject: r666 - trunk/game Message-ID: <20060308171553.15223.qmail@icculus.org> Author: sajt Date: 2006-03-08 12:15:53 -0500 (Wed, 08 Mar 2006) New Revision: 666 Modified: trunk/game/g_commands.c trunk/game/g_main.c Log: Added invert mouse cvar (g_invertmouse) Modified: trunk/game/g_commands.c =================================================================== --- trunk/game/g_commands.c 2006-03-08 17:08:05 UTC (rev 665) +++ trunk/game/g_commands.c 2006-03-08 17:15:53 UTC (rev 666) @@ -185,6 +185,8 @@ Cvar_LimitValueRange("g_fullbright", 0, 1); Cvar_Register("g_usemouse", "1", "Whether to use the mouse", CVAR_ENGINE | CVAR_DEFAULT); Cvar_LimitValueRange("g_usemouse", 0, 1); + Cvar_Register("g_invertmouse", "0", "Whether to invert the mouse pitch axis", CVAR_ENGINE | CVAR_DEFAULT); + Cvar_LimitValueRange("g_invertmouse", 0, 1); Cvar_Register("g_showshadowvolumes", "0", "Shows shadow volumes cast from visible lights", CVAR_ENGINE | CVAR_DEFAULT); Cvar_LimitValueRange("g_showshadowvolumes", 0, 1); Cvar_Register("g_showtris", "0", "Shows triangles of all model geometry (not shadow volumes)", CVAR_ENGINE | CVAR_DEFAULT); Modified: trunk/game/g_main.c =================================================================== --- trunk/game/g_main.c 2006-03-08 17:08:05 UTC (rev 665) +++ trunk/game/g_main.c 2006-03-08 17:15:53 UTC (rev 666) @@ -140,6 +140,9 @@ relativeviewangles[0] = Input.mousemove[1] * Cvar_GetValue("g_sensitivity")->vval[0]; relativeviewangles[1] = -Input.mousemove[0] * Cvar_GetValue("g_sensitivity")->vval[0]; relativeviewangles[2] = 0; + + if (Cvar_GetValue("g_invertmouse")->ival) + relativeviewangles[0] = -relativeviewangles[0]; } VectorAdd(user->sendinput_relativeviewangles, relativeviewangles, user->sendinput_relativeviewangles); VectorAdd(user->localinput_relativeviewangles, relativeviewangles, user->localinput_relativeviewangles); From black at icculus.org Wed Mar 8 15:40:12 2006 From: black at icculus.org (black at icculus.org) Date: 8 Mar 2006 15:40:12 -0500 Subject: r667 - trunk/game Message-ID: <20060308204012.18873.qmail@icculus.org> Author: black Date: 2006-03-08 15:40:12 -0500 (Wed, 08 Mar 2006) New Revision: 667 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: First round: Changed the menucore to use the N* types and added a Menu_Rect struct to replace the various anonymous struct declarations. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-08 17:15:53 UTC (rev 666) +++ trunk/game/m_menucore.c 2006-03-08 20:40:12 UTC (rev 667) @@ -89,7 +89,7 @@ void Menu_Generic_MouseMoveSelectable(void *item, Menu_Inheritance *inh) { Menu_Item *thisi = item; - int j; + NUint j; for (j = 0; j < 2; j++) { @@ -98,8 +98,7 @@ } if (thisi->parent->selecteditem != thisi) - - thisi->parent->selecteditem = thisi; //mouse is in us. + thisi->parent->selecteditem = thisi; //mouse is in us. } void Menu_Generic_MouseMoveNonSelectable(UNUSED void *item, UNUSED Menu_Inheritance *inh) { @@ -121,7 +120,7 @@ Mem_Free(&item); } -Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, int x, int y, int bytes) +Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, NSint x, NSint y, NSint bytes) { Menu_Item *it; it = Mem_Alloc(Menu.menu_zone, bytes); @@ -173,7 +172,7 @@ } return false; } -Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, int x, int y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)) +Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)) { Menu_TextItem *it; it = (Menu_TextItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_TextItem)); @@ -284,7 +283,7 @@ } return false; } -Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, int x, int y, char *text) +Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, NSint x, NSint y, char *text) { Menu_EditItem *it; it = (Menu_EditItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_EditItem)); @@ -362,14 +361,15 @@ Nbool Menu_Combo_KeyPress (void *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent) { - int i; - Menu_TextItem *txt; - Menu_ComboItem *thisi = item; - Menu_ComboOption *option; - Menu_SubMenu *interior; - int pixels; if (sym == SDLK_RETURN || sym == MOUSE1) { + Menu_TextItem *txt; + Menu_ComboItem *thisi = item; + Menu_ComboOption *option; + Menu_SubMenu *interior; + NSint pixels; + NUint i; + thisi->popup = Menu_CreateMenu(&Menu.rootmenu); Menu_BringToFront(thisi->popup); interior = Menu_CreateMenu(thisi->popup); @@ -407,12 +407,8 @@ Menu_Generic_Destroy(item); } -Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, int x, int y, int w, char *defalt, char *list) +Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list) { - char *pipe; - int chars; - int ident; - Menu_ComboOption *option; //list is pipe-sperated Menu_ComboItem *it; it = (Menu_ComboItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_ComboItem)); @@ -430,6 +426,10 @@ if (*list) { + char *pipe; + NUint chars; + NSint ident; + Menu_ComboOption *option; ident = 0; for (pipe = list; ; pipe++) { @@ -480,7 +480,7 @@ } return false; } -Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, int x, int y, int w, int h, char *imagename, char *command) +Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command) { Menu_PictureItem *it; it = (Menu_PictureItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_PictureItem)); @@ -513,7 +513,7 @@ { Menu_SliderItem *thisi = item; - float frac; + Nfloat frac; // R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // R_SetColor(1, 1, 1, 1); @@ -582,7 +582,7 @@ } return false; } -Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, int x, int y, int w, int h, float minv, float maxv, float defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) +Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) { Menu_SliderItem *it; it = (Menu_SliderItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_SliderItem)); @@ -616,7 +616,7 @@ void Menu_SliderV_Draw(void *item, Menu_Inheritance *inh) { Menu_SliderItem *thisi = item; - float frac; + Nfloat frac; // R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // R_SetColor(1, 1, 1, 1); @@ -654,7 +654,7 @@ R_DrawString("A", 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); R_DrawString("V", 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1] - thisi->scale + (thisi->super.size[1]), thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); } -Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, int x, int y, int w, int h, float minv, float maxv, float defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) +Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) { Menu_SliderItem *it; it = (Menu_SliderItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_SliderItem)); @@ -692,8 +692,7 @@ Menu_SubMenu *thisi = item; Menu_Item *subitem; Menu_Inheritance ninh; - int j; - int wmin, wmax; + NUint j; if (Menu.grabs == &thisi->super && thisi->dragable) { @@ -708,6 +707,7 @@ for (j = 0; j < 2; j++) { + NSint wmin, wmax; /* if (Input.mouse[j] < thisi->subwindow.pos[j]+inh->addpos[j] || Input.mouse[j] > thisi->subwindow.pos[j]+inh->addpos[j] + thisi->subwindow.size[j]) { thisi->indrag = false; @@ -748,8 +748,7 @@ Menu_SubMenu *thisi = item; Menu_Item *subitem, *next; Menu_Inheritance ninh; - int wmin, wmax; - int j; + NUint j; if (thisi->super.parent) { @@ -762,6 +761,7 @@ for (j = 0; j < 2; j++) { + NSint wmin, wmax; wmin = inh->addpos[j] + thisi->super.pos[j]; wmax = wmin + thisi->super.size[j]; if (wmin < inh->window.pos[j]) @@ -883,7 +883,7 @@ void Menu_FinishMenu(Menu_SubMenu *menu) { Menu_Item *subitem; - int maxpos[2]; + NSint maxpos[2]; if (!menu) return; @@ -905,12 +905,12 @@ menu->subwindow.size[1] = maxpos[1]; } -void Menu_ArrangeSubItems(Menu_SubMenu *menu, Nbool horizontal, int pad, Menu_ArrangeStyle arrange) +void Menu_ArrangeSubItems(Menu_SubMenu *menu, Nbool horizontal, NSint pad, Menu_ArrangeStyle arrange) { Menu_Item *sitem; - int axis, otheraxis; - int val = 0; - int maxval=0; + NSint axis, otheraxis; + NSint val = 0; + NSint maxval=0; //axis is usually the 'vertical' axis, where each field is spaced with padding //otheraxis is the axis on which we align stuff (rather than just space it) @@ -1003,13 +1003,13 @@ -float sliderscale = 8; -float imagesize = 512; -float windowsize = 128; +Nfloat sliderscale = 8; +Nfloat imagesize = 512; +Nfloat windowsize = 128; void MoveMenuH(Menu_SliderItem *it) { Menu_SubMenu *menu = it->data; -// it->value = 16*(int)(it->value/16); +// it->value = 16*(NSint)(it->value/16); menu->subwindow.pos[0] = it->value; } Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-08 17:15:53 UTC (rev 666) +++ trunk/game/m_menucore.h 2006-03-08 20:40:12 UTC (rev 667) @@ -2,16 +2,18 @@ #ifndef M_MENUCORE_H #define M_MENUCORE_H +typedef struct Menu_Rect +{ + NSint32 pos[2]; + NSint32 size[2]; +} +Menu_Rect; + typedef struct Menu_Inheritance { - int addpos[2]; + NSint addpos[2]; - struct - { - NSint32 pos[2]; - NSint32 size[2]; - } - window; + Menu_Rect window; } Menu_Inheritance; @@ -34,12 +36,7 @@ { Menu_Item super; - struct - { - NSint32 pos[2]; - NSint32 size[2]; - } - subwindow; + Menu_Rect subwindow; Nbool dragable; Nbool allowclose; @@ -66,16 +63,16 @@ Menu_Item super; char *text; //what it currently says - int cursorpos; //where the cursor is, set between 0 and strlen(text) - int scrollpos; //fixme - int maxchars; //0 for unlimited + NUint cursorpos; //where the cursor is, set between 0 and strlen(text) + NSint scrollpos; //fixme + NUint maxchars; //0 for unlimited } Menu_EditItem; typedef struct Menu_ComboOption { char *text; //the text of the item - int ident; //if you wish to assosiate an int key with the item. + NSint ident; //if you wish to assosiate an int key with the item. struct Menu_ComboOption *next; } Menu_ComboOption; @@ -89,9 +86,9 @@ struct Menu_ComboOption *selected; //set char *text; - int cursorpos; - int scrollpos; - int maxchars; + NSint cursorpos; + NUint scrollpos; + NUint maxchars; struct Menu_SubMenu *popup; } @@ -111,12 +108,12 @@ Menu_Item super; void *data; //for custom stuff - float value;//set and used in the slider code + Nfloat value;//set and used in the slider code - float minv;//min value - float maxv;//max (can be inverted) + Nfloat minv;//min value + Nfloat maxv;//max (can be inverted) - float scale;//size of slider, in pixels. + Nfloat scale;//size of slider, in pixels. //notification function void (*SliderChanged) (struct Menu_SliderItem *slider); //the user just changed the slider->value @@ -155,11 +152,11 @@ Menu_SubMenu *Menu_CreateMenu(Menu_SubMenu *parent); -Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, int x, int y, int w, int h, float minv, float maxv, float defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//vertical scrolling bar -Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, int x, int y, int w, int h, float minv, float maxv, float defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//horizontal scrolling bar -Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, int x, int y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. -Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, int x, int y, char *text); //an item for editing text (fixme: needs callbacks and stuff) -Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, int x, int y, int w, char *defalt, char *list);//a list of multiple choices. -Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, int x, int y, int w, int h, char *imagename, char *command); //just a simple picture. clicking it can give a console command (fixme: make like text) +Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//vertical scrolling bar +Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//horizontal scrolling bar +Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. +Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, NSint x, NSint y, char *text); //an item for editing text (fixme: needs callbacks and stuff) +Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list);//a list of multiple choices. +Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command); //just a simple picture. clicking it can give a console command (fixme: make like text) #endif From black at icculus.org Wed Mar 8 17:07:58 2006 From: black at icculus.org (black at icculus.org) Date: 8 Mar 2006 17:07:58 -0500 Subject: r668 - trunk/game Message-ID: <20060308220758.2414.qmail@icculus.org> Author: black Date: 2006-03-08 17:07:58 -0500 (Wed, 08 Mar 2006) New Revision: 668 Modified: trunk/game/m_menucore.c Log: Made all the callbacks take pointers to their real type instead of void* to get rid of thisi. Fixed a bug in the combo list code (popup wasnt set to NULL on delete, which caused it to crash on destruction of the parent item). Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-08 20:40:12 UTC (rev 667) +++ trunk/game/m_menucore.c 2006-03-08 22:07:58 UTC (rev 668) @@ -14,31 +14,30 @@ void Menu_FinishMenu(Menu_SubMenu *menu); -void Menu_RemoveFromParent(void *item) +void Menu_RemoveFromParent(Menu_Item *item) { - Menu_Item *thisi = item; Menu_Item *ref; - if (thisi->parent) + if (item->parent) { - if (thisi->parent->subitems == NULL) + if (item->parent->subitems == NULL) { } - else if (thisi->parent->subitems == item) - thisi->parent->subitems = thisi->parent->subitems->next; + else if (item->parent->subitems == item) + item->parent->subitems = item->parent->subitems->next; else { - for (ref = thisi->parent->subitems; ref->next; ref = ref->next) + for (ref = item->parent->subitems; ref->next; ref = ref->next) { - if (ref->next == thisi) + if (ref->next == item) { ref->next = ref->next->next; - thisi->next = NULL; + item->next = NULL; break; } } } - thisi->next = NULL; - thisi->parent = NULL; + item->next = NULL; + item->parent = NULL; } } void Menu_AddAtFront(Menu_SubMenu *parent, Menu_SubMenu *menu) @@ -59,7 +58,7 @@ void Menu_BringToFront(Menu_SubMenu *menu) { Menu_SubMenu *p = menu->super.parent; - Menu_RemoveFromParent(menu); + Menu_RemoveFromParent(&menu->super); Menu_AddAtFront(p, menu); } @@ -86,19 +85,18 @@ } //generic items -void Menu_Generic_MouseMoveSelectable(void *item, Menu_Inheritance *inh) +void Menu_Generic_MouseMoveSelectable(Menu_Item *item, Menu_Inheritance *inh) { - Menu_Item *thisi = item; NUint j; for (j = 0; j < 2; j++) { - if (Input.mouse[j] < thisi->pos[j]+inh->addpos[j] || Input.mouse[j] > thisi->pos[j]+inh->addpos[j] + thisi->size[j]) + if (Input.mouse[j] < item->pos[j]+inh->addpos[j] || Input.mouse[j] > item->pos[j]+inh->addpos[j] + item->size[j]) return; } - if (thisi->parent->selecteditem != thisi) - thisi->parent->selecteditem = thisi; //mouse is in us. + if (item->parent->selecteditem != item) + item->parent->selecteditem = item; //mouse is in us. } void Menu_Generic_MouseMoveNonSelectable(UNUSED void *item, UNUSED Menu_Inheritance *inh) { @@ -107,12 +105,11 @@ { return false; } -void Menu_Generic_Destroy(void *item) +void Menu_Generic_Destroy(Menu_Item *item) { - Menu_Item *thisi = item; - if (thisi->parent) - if (thisi->parent->selecteditem == item) - thisi->parent->selecteditem = NULL; + if (item->parent) + if (item->parent->selecteditem == item) + item->parent->selecteditem = NULL; Menu_RemoveFromParent(item); if (Menu.grabs == item) @@ -149,25 +146,23 @@ //text items -void Menu_DrawTextItem(void *item, Menu_Inheritance *inh) +void Menu_DrawTextItem(Menu_TextItem *item, Menu_Inheritance *inh) { - Menu_TextItem *thisi = item; R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); - R_DrawString(thisi->text, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } void Menu_Text_DefaultUse (struct Menu_TextItem *item) { Shell_ExecuteScript("console", item->command); } -Nbool Menu_Text_KeyPress (void *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) +Nbool Menu_Text_KeyPress (Menu_TextItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { - Menu_TextItem *thisi = item; if (sym == SDLK_RETURN || sym == MOUSE1) { if (downevent) - if (thisi->UseTextItem) - thisi->UseTextItem(thisi); + if (item->UseTextItem) + item->UseTextItem(item); return true; } return false; @@ -202,62 +197,60 @@ //text-edit fields //fixme: only work with grabs? -void Menu_DrawEditItem(void *item, Menu_Inheritance *inh) +void Menu_DrawEditItem(Menu_EditItem *item, Menu_Inheritance *inh) { - Menu_EditItem *thisi = item; R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); - R_DrawString(thisi->text, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); - if (thisi->super.parent->selecteditem == &thisi->super) - R_DrawString("_", 0, thisi->super.pos[0] + inh->addpos[0] + thisi->cursorpos*8, thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, 0); + R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + if (item->super.parent->selecteditem == &item->super) + R_DrawString("_", 0, item->super.pos[0] + inh->addpos[0] + item->cursorpos*8, item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, 0); } -Nbool Menu_Edit_KeyPress (void *item, UNUSED NUint mod, NUint sym, NUint character, Nbool downevent) +Nbool Menu_Edit_KeyPress (Menu_EditItem *item, UNUSED NUint mod, NUint sym, NUint character, Nbool downevent) { - Menu_EditItem *thisi = item; if (sym == SDLK_RETURN || sym == MOUSE1) { // if (downevent) -// Shell_ExecuteScript("console", thisi->command); +// Shell_ExecuteScript("console", item->command); return true; } if (sym == SDLK_BACKSPACE) { if (!downevent) return true; - if (!thisi->cursorpos) + if (!item->cursorpos) { - if (*thisi->text) - thisi->cursorpos = 1; + if (*item->text) + item->cursorpos = 1; else return true; } - memmove(thisi->text+thisi->cursorpos-1, thisi->text+thisi->cursorpos, strlen(thisi->text+thisi->cursorpos)+1); - thisi->cursorpos--; + memmove(item->text+item->cursorpos-1, item->text+item->cursorpos, strlen(item->text+item->cursorpos)+1); + item->cursorpos--; return true; } if (sym == SDLK_HOME) { - thisi->cursorpos = 0; + item->cursorpos = 0; return true; } if (sym == SDLK_END) { - thisi->cursorpos = strlen(thisi->text); + item->cursorpos = strlen(item->text); return true; } if (sym == SDLK_LEFT) { - thisi->cursorpos -= downevent; - if (thisi->cursorpos < 0) - thisi->cursorpos = 0; + item->cursorpos -= downevent; + if (item->cursorpos < 0) + item->cursorpos = 0; return true; } if (sym == SDLK_RIGHT) { - thisi->cursorpos += downevent; - if (thisi->cursorpos > strlen(thisi->text)) - thisi->cursorpos = strlen(thisi->text); + item->cursorpos += downevent; + if (item->cursorpos > strlen(item->text)) + item->cursorpos = strlen(item->text); return true; } @@ -267,18 +260,18 @@ if (!downevent) return true; - if (thisi->maxchars && thisi->maxchars <= strlen(thisi->text)) + if (item->maxchars && item->maxchars <= strlen(item->text)) return true; //already reached the max - newt = Mem_Alloc(Menu.menu_zone, strlen(thisi->text)+2); - memcpy(newt, thisi->text, thisi->cursorpos); - memcpy(newt+thisi->cursorpos+1, thisi->text+thisi->cursorpos, strlen(thisi->text+thisi->cursorpos)+1); - newt[thisi->cursorpos] = character; + newt = Mem_Alloc(Menu.menu_zone, strlen(item->text)+2); + memcpy(newt, item->text, item->cursorpos); + memcpy(newt+item->cursorpos+1, item->text+item->cursorpos, strlen(item->text+item->cursorpos)+1); + newt[item->cursorpos] = character; - Mem_Free(&thisi->text); - thisi->text = newt; + Mem_Free(&item->text); + item->text = newt; - thisi->cursorpos++; + item->cursorpos++; return true; } return false; @@ -313,30 +306,29 @@ //combos -void Menu_DrawComboItem(void *item, Menu_Inheritance *inh) +void Menu_DrawComboItem(Menu_ComboItem *item, Menu_Inheritance *inh) { - Menu_ComboItem *thisi = item; R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); - R_DrawString(thisi->text, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("V", 0, thisi->super.pos[0] + thisi->super.size[0]-8 + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + R_DrawString("V", 0, item->super.pos[0] + item->super.size[0]-8 + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } -void Menu_Combo_SetText(Menu_ComboItem *thisi, char *text)//it's just easier. not sure weather this should be public or not. +void Menu_Combo_SetText(Menu_ComboItem *item, char *text)//it's just easier. not sure whether this should be public or not. { Menu_ComboOption *option; char *oldtext; - oldtext = thisi->text; - thisi->text = Mem_Alloc(Menu.menu_zone, strlen(text)+1); - strcpy(thisi->text, text); + oldtext = item->text; + item->text = Mem_Alloc(Menu.menu_zone, strlen(text)+1); + strcpy(item->text, text); - thisi->selected = NULL; - for (option = thisi->options; option; option = option->next) + item->selected = NULL; + for (option = item->options; option; option = option->next) { if (!strcmp(option->text, text)) { - thisi->selected = option; + item->selected = option; break; } } @@ -344,67 +336,66 @@ Mem_Free(&oldtext); } -void Menu_ComboSlider (struct Menu_SliderItem *slider) +void Menu_ComboSlider (Menu_SliderItem *slider) { - Menu_SubMenu *thisi = slider->data; - thisi->subwindow.pos[1] = -slider->value; + Menu_SubMenu *submenu = slider->data; + submenu->subwindow.pos[1] = -slider->value; } void Menu_UseOption (Menu_TextItem *it) { - Menu_ComboItem *thisi = (void*)it->command; - Menu_Combo_SetText(thisi, it->text); + Menu_ComboItem *comboitem = (void*)it->command; + Menu_Combo_SetText(comboitem, it->text); //seeing as this happens from a key event, and the text control will return true, we can safly kill the popup - thisi->popup->super.Destroy(thisi->popup); + comboitem->popup->super.Destroy(comboitem->popup); + comboitem->popup = NULL; } -Nbool Menu_Combo_KeyPress (void *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent) +Nbool Menu_Combo_KeyPress (Menu_ComboItem *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent) { if (sym == SDLK_RETURN || sym == MOUSE1) { Menu_TextItem *txt; - Menu_ComboItem *thisi = item; Menu_ComboOption *option; Menu_SubMenu *interior; NSint pixels; NUint i; - thisi->popup = Menu_CreateMenu(&Menu.rootmenu); - Menu_BringToFront(thisi->popup); - interior = Menu_CreateMenu(thisi->popup); + item->popup = Menu_CreateMenu(&Menu.rootmenu); + Menu_BringToFront(item->popup); + interior = Menu_CreateMenu(item->popup); interior->allowclose = false; - Menu.grabs = &thisi->popup->super; - option = thisi->options; + Menu.grabs = &item->popup->super; + option = item->options; for (i = 0; option; i+=8, option = option->next) { - txt = Menu_CreateTextItem(interior, 0, i, option->text, thisi, Menu_UseOption); - txt->super.size[0] = thisi->super.size[0] - 8; + txt = Menu_CreateTextItem(interior, 0, i, option->text, item, Menu_UseOption); + txt->super.size[0] = item->super.size[0] - 8; } pixels = i-64; if (pixels < 0) pixels = 0; - Menu_CreateVSliderItem(thisi->popup, thisi->super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_ComboSlider, NULL, interior); + Menu_CreateVSliderItem(item->popup, item->super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_ComboSlider, NULL, interior); - thisi->popup->super.pos[0] = Input.mouse[0]; - thisi->popup->super.pos[1] = Input.mouse[1]; + item->popup->super.pos[0] = Input.mouse[0]; + item->popup->super.pos[1] = Input.mouse[1]; - thisi->popup->subwindow.pos[0] = thisi->popup->super.pos[0]; - thisi->popup->subwindow.pos[1] = thisi->popup->super.pos[1]; + item->popup->subwindow.pos[0] = item->popup->super.pos[0]; + item->popup->subwindow.pos[1] = item->popup->super.pos[1]; Menu_FinishMenu(interior); interior->super.size[1] = ((i>64)?64:i); - Menu_FinishMenu(thisi->popup); + Menu_FinishMenu(item->popup); return true; } return false; } -void Menu_Combo_Destroy(void *item) +void Menu_Combo_Destroy(Menu_ComboItem *item) { - Menu_ComboItem *combo = item; - if (combo->popup) - combo->popup->super.Destroy(combo->popup); - Menu_Generic_Destroy(item); + if (item->popup) + item->popup->super.Destroy(item->popup); + Menu_Generic_Destroy(&item->super); } Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list) @@ -461,21 +452,19 @@ //picture items -void Menu_Picture_Draw(void *item, Menu_Inheritance *inh) +void Menu_Picture_Draw(Menu_PictureItem *item, Menu_Inheritance *inh) { - Menu_PictureItem *thisi = item; R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetColor(1, 1, 1, 1); - R_SetTexture(Resource_IndexForName(thisi->imagename, RESOURCETYPE_TEXTURE, 0, 0)); - R_DrawPic(thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], thisi->super.size[0], thisi->super.size[1]); + R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); + R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); } -Nbool Menu_Picture_KeyPress (void *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) +Nbool Menu_Picture_KeyPress (Menu_PictureItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { - Menu_PictureItem *thisi = item; if (sym == SDLK_RETURN || sym == MOUSE1) { if (downevent) - Shell_ExecuteScript("console", thisi->command); + Shell_ExecuteScript("console", item->command); return true; } return false; @@ -509,55 +498,52 @@ //sliderh items -void Menu_SliderH_Draw(void *item, Menu_Inheritance *inh) +void Menu_SliderH_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) { - Menu_SliderItem *thisi = item; - Nfloat frac; // R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // R_SetColor(1, 1, 1, 1); -// R_SetTexture(Resource_IndexForName(thisi->imagename, RESOURCETYPE_TEXTURE, 0, 0)); -// R_DrawPic(thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], thisi->super.size[0], thisi->super.size[1]); +// R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); +// R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); - if (Menu.grabs == item) + if (Menu.grabs == &item->super) { { - thisi->value = Input.mouse[0] - (thisi->super.pos[0]+inh->addpos[0] + thisi->scale*1.5); - if (thisi->value < 0) - thisi->value = 0; - if (thisi->value > thisi->super.size[0] - thisi->scale*3) - thisi->value = thisi->super.size[0] - thisi->scale*3; + item->value = Input.mouse[0] - (item->super.pos[0]+inh->addpos[0] + item->scale*1.5); + if (item->value < 0) + item->value = 0; + if (item->value > item->super.size[0] - item->scale*3) + item->value = item->super.size[0] - item->scale*3; - thisi->value *= thisi->maxv - thisi->minv; - thisi->value /= thisi->super.size[0] - thisi->scale*3; - thisi->value += thisi->minv; + item->value *= item->maxv - item->minv; + item->value /= item->super.size[0] - item->scale*3; + item->value += item->minv; - thisi->SliderChanged(thisi); + item->SliderChanged(item); } } - if (thisi->SliderUpdate) - thisi->SliderUpdate(thisi); + if (item->SliderUpdate) + item->SliderUpdate(item); R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - frac = (thisi->value-thisi->minv)/(thisi->maxv-thisi->minv); + frac = (item->value-item->minv)/(item->maxv-item->minv); R_SetTexture(R.resource_font); // snprintf(value, sizeof(value), "%f%%", frac); -// R_DrawString(value, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); +// R_DrawString(value, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("x", 0, thisi->super.pos[0] + inh->addpos[0] + thisi->scale + (thisi->super.size[0]-thisi->scale*3)*frac, thisi->super.pos[1] + inh->addpos[1], thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); - R_DrawString("<", 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); - R_DrawString(">", 0, thisi->super.pos[0] + inh->addpos[0] - thisi->scale + (thisi->super.size[0]), thisi->super.pos[1] + inh->addpos[1], thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0] + item->scale + (item->super.size[0]-item->scale*3)*frac, item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("<", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString(">", 0, item->super.pos[0] + inh->addpos[0] - item->scale + (item->super.size[0]), item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } -Nbool Menu_Slider_KeyPress (void *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) +Nbool Menu_Slider_KeyPress (Menu_SliderItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { - Menu_SliderItem *thisi = item; if (sym == MOUSE1) { if (downevent) - Menu.grabs = item; + Menu.grabs = &item->super; else Menu.grabs = NULL; return true; @@ -566,8 +552,8 @@ { if (downevent) { - thisi->value -= 1; - thisi->SliderChanged(thisi); + item->value -= 1; + item->SliderChanged(item); } return true; } @@ -575,8 +561,8 @@ { if (downevent) { - thisi->value += 1; - thisi->SliderChanged(thisi); + item->value += 1; + item->SliderChanged(item); } return true; } @@ -613,46 +599,45 @@ //sliderv items -void Menu_SliderV_Draw(void *item, Menu_Inheritance *inh) +void Menu_SliderV_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) { - Menu_SliderItem *thisi = item; Nfloat frac; // R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // R_SetColor(1, 1, 1, 1); -// R_SetTexture(Resource_IndexForName(thisi->imagename, RESOURCETYPE_TEXTURE, 0, 0)); -// R_DrawPic(thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], thisi->super.size[0], thisi->super.size[1]); +// R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); +// R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); - if (Menu.grabs == item) + if (Menu.grabs == &item->super) { { - thisi->value = Input.mouse[1] - ((thisi->super.pos[1]+inh->addpos[1]) + thisi->scale*1.5); - if (thisi->value < 0) - thisi->value = 0; - if (thisi->value > thisi->super.size[1] - thisi->scale*3) - thisi->value = thisi->super.size[1] - thisi->scale*3; + item->value = Input.mouse[1] - ((item->super.pos[1]+inh->addpos[1]) + item->scale*1.5); + if (item->value < 0) + item->value = 0; + if (item->value > item->super.size[1] - item->scale*3) + item->value = item->super.size[1] - item->scale*3; - thisi->value *= thisi->maxv - thisi->minv; - thisi->value /= thisi->super.size[1] - thisi->scale*3; - thisi->value += thisi->minv; + item->value *= item->maxv - item->minv; + item->value /= item->super.size[1] - item->scale*3; + item->value += item->minv; - thisi->SliderChanged(thisi); + item->SliderChanged(item); } } - if (thisi->SliderUpdate) - thisi->SliderUpdate(thisi); + if (item->SliderUpdate) + item->SliderUpdate(item); R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - frac = (thisi->value-thisi->minv)/(thisi->maxv-thisi->minv); + frac = (item->value-item->minv)/(item->maxv-item->minv); R_SetTexture(R.resource_font); // snprintf(value, sizeof(value), "%f%%", frac); -// R_DrawString(value, 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); +// R_DrawString(value, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("x", 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1] + thisi->scale + (thisi->super.size[1]-thisi->scale*3)*frac, thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); - R_DrawString("A", 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1], thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); - R_DrawString("V", 0, thisi->super.pos[0] + inh->addpos[0], thisi->super.pos[1] + inh->addpos[1] - thisi->scale + (thisi->super.size[1]), thisi->scale, thisi->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, thisi->super.parent->selecteditem == &thisi->super); + R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] + item->scale + (item->super.size[1]-item->scale*3)*frac, item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("A", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("V", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) { @@ -687,36 +672,35 @@ //submenus -void Menu_MouseMoveSubMenu(void *item, Menu_Inheritance *inh) +void Menu_MouseMoveSubMenu(Menu_SubMenu *item, Menu_Inheritance *inh) { - Menu_SubMenu *thisi = item; Menu_Item *subitem; Menu_Inheritance ninh; NUint j; - if (Menu.grabs == &thisi->super && thisi->dragable) + if (Menu.grabs == &item->super && item->dragable) { - thisi->subwindow.pos[0] += Input.mouse[0] - thisi->dragmousepos[0]; - thisi->subwindow.pos[1] += Input.mouse[1] - thisi->dragmousepos[1]; - thisi->super.pos[0] += Input.mouse[0] - thisi->dragmousepos[0]; - thisi->super.pos[1] += Input.mouse[1] - thisi->dragmousepos[1]; - thisi->dragmousepos[0] = Input.mouse[0]; - thisi->dragmousepos[1] = Input.mouse[1]; -// Menu_FinishMenu(thisi->super.parent); + item->subwindow.pos[0] += Input.mouse[0] - item->dragmousepos[0]; + item->subwindow.pos[1] += Input.mouse[1] - item->dragmousepos[1]; + item->super.pos[0] += Input.mouse[0] - item->dragmousepos[0]; + item->super.pos[1] += Input.mouse[1] - item->dragmousepos[1]; + item->dragmousepos[0] = Input.mouse[0]; + item->dragmousepos[1] = Input.mouse[1]; +// Menu_FinishMenu(item->super.parent); } for (j = 0; j < 2; j++) { NSint wmin, wmax; -/* if (Input.mouse[j] < thisi->subwindow.pos[j]+inh->addpos[j] || Input.mouse[j] > thisi->subwindow.pos[j]+inh->addpos[j] + thisi->subwindow.size[j]) +/* if (Input.mouse[j] < item->subwindow.pos[j]+inh->addpos[j] || Input.mouse[j] > item->subwindow.pos[j]+inh->addpos[j] + item->subwindow.size[j]) { - thisi->indrag = false; + item->indrag = false; return; } */ - wmin = inh->addpos[j] + thisi->super.pos[j]; - wmax = wmin + thisi->super.size[j]; + wmin = inh->addpos[j] + item->super.pos[j]; + wmax = wmin + item->super.size[j]; if (inh->window.pos[j] > wmin) wmin = inh->window.pos[j]; if (inh->window.pos[j] + inh->window.size[j] < wmax) @@ -731,39 +715,38 @@ ninh.window.size[j] = wmax-wmin; } - ninh.addpos[0] = inh->addpos[0] + thisi->subwindow.pos[0]; - ninh.addpos[1] = inh->addpos[1] + thisi->subwindow.pos[1]; + ninh.addpos[0] = inh->addpos[0] + item->subwindow.pos[0]; + ninh.addpos[1] = inh->addpos[1] + item->subwindow.pos[1]; - if (thisi->super.parent) - thisi->super.parent->selecteditem = &thisi->super; //mouse is in us. + if (item->super.parent) + item->super.parent->selecteditem = &item->super; //mouse is in us. - thisi->selecteditem = NULL; + item->selecteditem = NULL; - for (subitem = thisi->subitems; subitem; subitem = subitem->next) + for (subitem = item->subitems; subitem; subitem = subitem->next) subitem->MouseMove(subitem, &ninh); } -void Menu_DrawSubMenu(void *item, Menu_Inheritance *inh) +void Menu_DrawSubMenu(Menu_SubMenu *item, Menu_Inheritance *inh) { - Menu_SubMenu *thisi = item; Menu_Item *subitem, *next; Menu_Inheritance ninh; NUint j; - if (thisi->super.parent) + if (item->super.parent) { - if (thisi->super.parent->selecteditem != item) - thisi->selecteditem = NULL; + if (item->super.parent->selecteditem != &item->super) + item->selecteditem = NULL; } - ninh.addpos[0] = inh->addpos[0] + thisi->subwindow.pos[0]; - ninh.addpos[1] = inh->addpos[1] + thisi->subwindow.pos[1]; + ninh.addpos[0] = inh->addpos[0] + item->subwindow.pos[0]; + ninh.addpos[1] = inh->addpos[1] + item->subwindow.pos[1]; for (j = 0; j < 2; j++) { NSint wmin, wmax; - wmin = inh->addpos[j] + thisi->super.pos[j]; - wmax = wmin + thisi->super.size[j]; + wmin = inh->addpos[j] + item->super.pos[j]; + wmax = wmin + item->super.size[j]; if (wmin < inh->window.pos[j]) wmin = inh->window.pos[j]; ninh.window.pos[j] = wmin; @@ -775,7 +758,7 @@ R_SetScissor(ninh.window.pos[0], ninh.window.pos[1], ninh.window.size[0], ninh.window.size[1]); - for (subitem = thisi->subitems; subitem; subitem = next) + for (subitem = item->subitems; subitem; subitem = next) { next = subitem->next;//this funkyness is so that we can unlink and kill things in the draw function (if the need arises). subitem->DrawMenu(subitem, &ninh); @@ -783,60 +766,59 @@ R_SetScissor(inh->window.pos[0], inh->window.pos[1], inh->window.size[0], inh->window.size[1]); } -Nbool Menu_KeyEventSubMenu (void *item, NUint mod, NUint sym, NUint character, Nbool downevent) +Nbool Menu_KeyEventSubMenu (Menu_SubMenu *item, NUint mod, NUint sym, NUint character, Nbool downevent) { - Menu_SubMenu *thisi = item; Menu_Item *subitem; - Menu_BringToFront(thisi); + Menu_BringToFront(item); - subitem = thisi->selecteditem; - if (thisi->selecteditem) + subitem = item->selecteditem; + if (item->selecteditem) if (subitem->KeyEvent(subitem, mod, sym, character, downevent)) return true; - if (thisi->allowclose && sym == SDLK_ESCAPE) + if (item->allowclose && sym == SDLK_ESCAPE) { - Menu_RemoveFromParent(thisi); - thisi->super.Destroy(thisi); + Menu_RemoveFromParent(&item->super); + item->super.Destroy(item); return true; } - if (thisi->dragable) + if (item->dragable) { if (sym == SDLK_LEFT) { - thisi->super.pos[0] -= 4; - Menu_FinishMenu(thisi); + item->super.pos[0] -= 4; + Menu_FinishMenu(item); return true; } if (sym == SDLK_UP) { - thisi->super.pos[1] -= 4; - Menu_FinishMenu(thisi); + item->super.pos[1] -= 4; + Menu_FinishMenu(item); return true; } if (sym == SDLK_RIGHT) { - thisi->super.pos[0] += 4; - Menu_FinishMenu(thisi); + item->super.pos[0] += 4; + Menu_FinishMenu(item); return true; } if (sym == SDLK_DOWN) { - thisi->super.pos[1] += 4; - Menu_FinishMenu(thisi); + item->super.pos[1] += 4; + Menu_FinishMenu(item); return true; } if (sym == MOUSE1) { if (downevent) - Menu.grabs = &thisi->super; + Menu.grabs = &item->super; else Menu.grabs = NULL; - thisi->dragmousepos[0] = Input.mouse[0]; - thisi->dragmousepos[1] = Input.mouse[1]; + item->dragmousepos[0] = Input.mouse[0]; + item->dragmousepos[1] = Input.mouse[1]; return true; } } @@ -844,17 +826,16 @@ return false; } -void Menu_SubMenu_Destroy(void *item) +void Menu_SubMenu_Destroy(Menu_SubMenu *item) { - Menu_SubMenu *thisi = item; Menu_Item *sub, *old; - for (sub = thisi->subitems; sub; ) + for (sub = item->subitems; sub; ) { old = sub; sub = sub->next; old->Destroy(old); } - Menu_Generic_Destroy(item); + Menu_Generic_Destroy(&item->super); } Menu_SubMenu *Menu_CreateMenu(Menu_SubMenu *parent) From black at icculus.org Sun Mar 12 17:02:12 2006 From: black at icculus.org (black at icculus.org) Date: 12 Mar 2006 17:02:12 -0500 Subject: r669 - trunk Message-ID: <20060312220212.31056.qmail@icculus.org> Author: black Date: 2006-03-12 17:02:12 -0500 (Sun, 12 Mar 2006) New Revision: 669 Modified: trunk/shell.c Log: Fixed a bug in the shell parser and some typos in comments. Modified: trunk/shell.c =================================================================== --- trunk/shell.c 2006-03-08 22:07:58 UTC (rev 668) +++ trunk/shell.c 2006-03-12 22:02:12 UTC (rev 669) @@ -304,7 +304,7 @@ decimalPoint = false; current = text; - if( IsSign( current[0] ) || IsDigit( current[1] ) ) { + if( IsSign( current[0] ) && IsDigit( current[1] ) ) { current += 2; } for( ; *current ; current++ ) { @@ -369,7 +369,8 @@ static inline Nbool Shell_Parser_MatchValue( Shell_Parser *parser ) { if( Shell_Parser_MatchDigit( parser ) || Shell_Parser_MatchSignedDigit( parser ) ) { - while( Shell_Parser_MatchDigit( parser ) ); + while( Shell_Parser_MatchDigit( parser ) ) + ; if( Shell_Parser_MatchChar( parser, '.' ) ) { while( Shell_Parser_MatchDigit( parser ) ); } @@ -409,7 +410,7 @@ } // skips whitespace and // comments and /* */ comments -// result: you'll have a meaningfull char in currentChar +// result: you'll have a meaningful char in currentChar static void Shell_Parser_SkipStuff( Shell_Parser *parser ) { while( 1 ) { while( IsWhitespace( *parser->currentChar ) ) { @@ -689,7 +690,7 @@ from->type = SHELL_TOKENTYPE_EOF; } -// formal makes it put "" around strings, etc. and always return something that can be print +// formal makes it put "" around strings, etc. and always return something that can be printed // otherwise it can return "" sometimes static inline char * Shell_Item_ToString( Shell_Item *item, Nbool formal ) { char *out = NULL; From black at icculus.org Sun Mar 12 17:07:57 2006 From: black at icculus.org (black at icculus.org) Date: 12 Mar 2006 17:07:57 -0500 Subject: r670 - trunk/game Message-ID: <20060312220757.32221.qmail@icculus.org> Author: black Date: 2006-03-12 17:07:57 -0500 (Sun, 12 Mar 2006) New Revision: 670 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: Only a few very small changes to the menucore code. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-12 22:02:12 UTC (rev 669) +++ trunk/game/m_menucore.c 2006-03-12 22:07:57 UTC (rev 670) @@ -12,56 +12,89 @@ #define MOUSE1 (SDLK_LAST + 1) +/* +-make every item have a parent +-make it more strict and error out earlier +*/ + void Menu_FinishMenu(Menu_SubMenu *menu); +// if the item has no parent, it doesn't do anything void Menu_RemoveFromParent(Menu_Item *item) { - Menu_Item *ref; if (item->parent) { + if (item->parent->selecteditem == item) + item->parent->selecteditem = NULL; + if (item->parent->subitems == NULL) { + // FIXME: error condition } else if (item->parent->subitems == item) item->parent->subitems = item->parent->subitems->next; else { - for (ref = item->parent->subitems; ref->next; ref = ref->next) + Menu_Item *node; + for (node = item->parent->subitems; node->next; node = node->next) { - if (ref->next == item) + if (node->next == item) { - ref->next = ref->next->next; - item->next = NULL; + node->next = item->next; break; } } + if( node->next == NULL ) { + // FIXME: error condition + } } item->next = NULL; item->parent = NULL; } } -void Menu_AddAtFront(Menu_SubMenu *parent, Menu_SubMenu *menu) + +void Menu_AddAtFront(Menu_SubMenu *parent, Menu_Item *item) { - Menu_Item *p; - menu->super.parent = parent; - if (!parent) - return; + assert( item != NULL ); + assert( parent != NULL ); + assert( item->parent == NULL ); + + item->parent = parent; + if (!parent->subitems) - parent->subitems = &menu->super; + parent->subitems = item; else { - for (p = parent->subitems; p->next; p = p->next) + Menu_Item *node; + for (node = parent->subitems; node->next; node = node->next) ; - p->next = &menu->super; + node->next = item; } } + +void Menu_AddToBack(Menu_SubMenu *parent, Menu_Item *item ) +{ + assert( item != NULL ); + assert( parent != NULL ); + assert( item->parent == NULL ); + + item->parent = parent; + item->next = parent->subitems; + parent->subitems = item; +} + void Menu_BringToFront(Menu_SubMenu *menu) { - Menu_SubMenu *p = menu->super.parent; + Menu_SubMenu *parent = menu->super.parent; + // FIXME: fix this + if( !parent ) { + return; + } Menu_RemoveFromParent(&menu->super); - Menu_AddAtFront(p, menu); + Menu_AddAtFront(parent, &menu->super); } +// TODO: add fully qualified names with a scope operator (:: or.?) void *Menu_GetItem(Menu_SubMenu *parent, char *name) { Menu_Item *sub; @@ -78,6 +111,7 @@ void Menu_MoveToCenter(Menu_SubMenu *menu) { + // TODO: make it move to the center of the parent menu->super.pos[0] = (Video.width - menu->super.size[0])/2; menu->super.pos[1] = (Video.height - menu->super.size[1])/2; menu->subwindow.pos[0] = menu->super.pos[0]; @@ -91,25 +125,25 @@ for (j = 0; j < 2; j++) { - if (Input.mouse[j] < item->pos[j]+inh->addpos[j] || Input.mouse[j] > item->pos[j]+inh->addpos[j] + item->size[j]) + if (Input.mouse[j] < item->pos[j]+inh->addpos[j] || item->pos[j]+inh->addpos[j] + item->size[j] < Input.mouse[j] ) return; } if (item->parent->selecteditem != item) item->parent->selecteditem = item; //mouse is in us. } + void Menu_Generic_MouseMoveNonSelectable(UNUSED void *item, UNUSED Menu_Inheritance *inh) { } + Nbool Menu_Generic_KeyPressIgnore (UNUSED void *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent) { return false; } + void Menu_Generic_Destroy(Menu_Item *item) { - if (item->parent) - if (item->parent->selecteditem == item) - item->parent->selecteditem = NULL; Menu_RemoveFromParent(item); if (Menu.grabs == item) @@ -117,26 +151,25 @@ Mem_Free(&item); } -Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, NSint x, NSint y, NSint bytes) + +Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, NSint x, NSint y, NUint bytes) { - Menu_Item *it; - it = Mem_Alloc(Menu.menu_zone, bytes); + Menu_Item *item; + item = Mem_Alloc(Menu.menu_zone, bytes); - it->MouseMove = Menu_Generic_MouseMoveNonSelectable; - it->KeyEvent = Menu_Generic_KeyPressIgnore; - it->Destroy = Menu_Generic_Destroy; + item->MouseMove = Menu_Generic_MouseMoveNonSelectable; + item->KeyEvent = Menu_Generic_KeyPressIgnore; + item->Destroy = Menu_Generic_Destroy; - it->pos[0] = x; - it->pos[1] = y; + item->pos[0] = x; + item->pos[1] = y; - it->parent = parent; - if (parent) + if (parent) { - it->next = parent->subitems; - parent->subitems = it; + Menu_AddToBack(parent, item); } - return it; //heh, cool :D + return item; } @@ -154,7 +187,7 @@ } void Menu_Text_DefaultUse (struct Menu_TextItem *item) { - Shell_ExecuteScript("console", item->command); + Shell_ExecuteScript("menu text use", item->command); } Nbool Menu_Text_KeyPress (Menu_TextItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { @@ -842,16 +875,12 @@ { Menu_SubMenu *menu; - Menu.rootmenu.super.size[0] = Video.width; - Menu.rootmenu.super.size[1] = Video.height; - Menu.rootmenu.subwindow.size[0] = Video.width; - Menu.rootmenu.subwindow.size[1] = Video.height; + menu = (Menu_SubMenu*) Menu_CreateGenericItem(NULL, 0, 0, sizeof(Menu_SubMenu)); - menu = (Menu_SubMenu*)Menu_CreateGenericItem(NULL, 0, 0, sizeof(Menu_SubMenu)); + if( parent ) { + Menu_AddAtFront(parent, &menu->super); + } - Menu_AddAtFront(parent, menu); - - menu->super.MouseMove = Menu_MouseMoveSubMenu; menu->super.DrawMenu = Menu_DrawSubMenu; menu->super.KeyEvent = Menu_KeyEventSubMenu; @@ -861,12 +890,13 @@ return menu; } + void Menu_FinishMenu(Menu_SubMenu *menu) { Menu_Item *subitem; NSint maxpos[2]; - if (!menu) - return; + + assert( menu != NULL ); maxpos[0] = 0; maxpos[1] = 0; @@ -891,7 +921,7 @@ Menu_Item *sitem; NSint axis, otheraxis; NSint val = 0; - NSint maxval=0; + NSint maxval = 0; //axis is usually the 'vertical' axis, where each field is spaced with padding //otheraxis is the axis on which we align stuff (rather than just space it) @@ -1143,7 +1173,13 @@ Shell_Register(&Menu_Menu_Quit_Decl, NULL); Shell_Register(&Menu_Menu_Close_Decl, NULL); + // init the root menu Menu.rootmenu.super.MouseMove = Menu_MouseMoveSubMenu; Menu.rootmenu.super.DrawMenu = Menu_DrawSubMenu; Menu.rootmenu.super.KeyEvent = Menu_KeyEventSubMenu; + + Menu.rootmenu.super.size[0] = Video.width; + Menu.rootmenu.super.size[1] = Video.height; + Menu.rootmenu.subwindow.size[0] = Video.width; + Menu.rootmenu.subwindow.size[1] = Video.height; } Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-12 22:02:12 UTC (rev 669) +++ trunk/game/m_menucore.h 2006-03-12 22:07:57 UTC (rev 670) @@ -5,7 +5,7 @@ typedef struct Menu_Rect { NSint32 pos[2]; - NSint32 size[2]; + NUint32 size[2]; } Menu_Rect; @@ -27,8 +27,9 @@ NSint32 pos[2]; NSint32 size[2]; + struct Menu_SubMenu *parent; + // this actually belongs to Menu_SubMenu and is managed by it struct Menu_Item *next; - struct Menu_SubMenu *parent; } Menu_Item; From black at icculus.org Sun Mar 12 17:11:29 2006 From: black at icculus.org (black at icculus.org) Date: 12 Mar 2006 17:11:29 -0500 Subject: r671 - trunk/game Message-ID: <20060312221129.32589.qmail@icculus.org> Author: black Date: 2006-03-12 17:11:29 -0500 (Sun, 12 Mar 2006) New Revision: 671 Modified: trunk/game/m_menucore.c Log: Moved the rootmenu size init code to Menu_Draw. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-12 22:07:57 UTC (rev 670) +++ trunk/game/m_menucore.c 2006-03-12 22:11:29 UTC (rev 671) @@ -991,6 +991,11 @@ Menu_Inheritance inh; memset(&inh, 0, sizeof(inh)); + Menu.rootmenu.super.size[0] = Video.width; + Menu.rootmenu.super.size[1] = Video.height; + Menu.rootmenu.subwindow.size[0] = Video.width; + Menu.rootmenu.subwindow.size[1] = Video.height; + inh.window.size[0] = Video.width; inh.window.size[1] = Video.height; @@ -1162,8 +1167,6 @@ }; - - void Menu_Init(void) { Menu.menu_zone = Mem_AllocZone ("MenuZone", NULL, 0); @@ -1177,9 +1180,4 @@ Menu.rootmenu.super.MouseMove = Menu_MouseMoveSubMenu; Menu.rootmenu.super.DrawMenu = Menu_DrawSubMenu; Menu.rootmenu.super.KeyEvent = Menu_KeyEventSubMenu; - - Menu.rootmenu.super.size[0] = Video.width; - Menu.rootmenu.super.size[1] = Video.height; - Menu.rootmenu.subwindow.size[0] = Video.width; - Menu.rootmenu.subwindow.size[1] = Video.height; } From black at icculus.org Sun Mar 12 17:30:24 2006 From: black at icculus.org (black at icculus.org) Date: 12 Mar 2006 17:30:24 -0500 Subject: r672 - trunk/game Message-ID: <20060312223024.3055.qmail@icculus.org> Author: black Date: 2006-03-12 17:30:24 -0500 (Sun, 12 Mar 2006) New Revision: 672 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: Don't hate me for this: Changed all item spefific functions to use their type as subnamespace instead of using it as suffix. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-12 22:11:29 UTC (rev 671) +++ trunk/game/m_menucore.c 2006-03-12 22:30:24 UTC (rev 672) @@ -152,9 +152,11 @@ Mem_Free(&item); } -Menu_Item *Menu_CreateGenericItem(Menu_SubMenu *parent, NSint x, NSint y, NUint bytes) +Menu_Item *Menu_Generic_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint bytes) { Menu_Item *item; + assert( bytes >= sizeof(Menu_Item) ); + item = Mem_Alloc(Menu.menu_zone, bytes); item->MouseMove = Menu_Generic_MouseMoveNonSelectable; @@ -179,7 +181,7 @@ //text items -void Menu_DrawTextItem(Menu_TextItem *item, Menu_Inheritance *inh) +void Menu_Text_Draw(Menu_TextItem *item, Menu_Inheritance *inh) { R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); @@ -200,12 +202,12 @@ } return false; } -Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)) +Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)) { Menu_TextItem *it; - it = (Menu_TextItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_TextItem)); + it = (Menu_TextItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_TextItem)); - it->super.DrawMenu = Menu_DrawTextItem; + it->super.DrawMenu = Menu_Text_Draw; if (command != NULL) { it->super.MouseMove = Menu_Generic_MouseMoveSelectable; @@ -230,7 +232,7 @@ //text-edit fields //fixme: only work with grabs? -void Menu_DrawEditItem(Menu_EditItem *item, Menu_Inheritance *inh) +void Menu_Edit_Draw(Menu_EditItem *item, Menu_Inheritance *inh) { R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); @@ -309,12 +311,12 @@ } return false; } -Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, NSint x, NSint y, char *text) +Menu_EditItem *Menu_Edit_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text) { Menu_EditItem *it; - it = (Menu_EditItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_EditItem)); + it = (Menu_EditItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_EditItem)); - it->super.DrawMenu = Menu_DrawEditItem; + it->super.DrawMenu = Menu_Edit_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Edit_KeyPress; it->super.size[0] = 8*strlen(text); @@ -339,7 +341,7 @@ //combos -void Menu_DrawComboItem(Menu_ComboItem *item, Menu_Inheritance *inh) +void Menu_Combo_Draw(Menu_ComboItem *item, Menu_Inheritance *inh) { R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); @@ -369,12 +371,12 @@ Mem_Free(&oldtext); } -void Menu_ComboSlider (Menu_SliderItem *slider) +void Menu_Combo_UseSlider (Menu_SliderItem *slider) { Menu_SubMenu *submenu = slider->data; submenu->subwindow.pos[1] = -slider->value; } -void Menu_UseOption (Menu_TextItem *it) +void Menu_Combo_UseOption (Menu_TextItem *it) { Menu_ComboItem *comboitem = (void*)it->command; Menu_Combo_SetText(comboitem, it->text); @@ -395,21 +397,21 @@ NSint pixels; NUint i; - item->popup = Menu_CreateMenu(&Menu.rootmenu); + item->popup = Menu_SubMenu_Create(&Menu.rootmenu); Menu_BringToFront(item->popup); - interior = Menu_CreateMenu(item->popup); + interior = Menu_SubMenu_Create(item->popup); interior->allowclose = false; Menu.grabs = &item->popup->super; option = item->options; for (i = 0; option; i+=8, option = option->next) { - txt = Menu_CreateTextItem(interior, 0, i, option->text, item, Menu_UseOption); + txt = Menu_Text_Create(interior, 0, i, option->text, item, Menu_Combo_UseOption); txt->super.size[0] = item->super.size[0] - 8; } pixels = i-64; if (pixels < 0) pixels = 0; - Menu_CreateVSliderItem(item->popup, item->super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_ComboSlider, NULL, interior); + Menu_VSlider_Create(item->popup, item->super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_Combo_UseSlider, NULL, interior); item->popup->super.pos[0] = Input.mouse[0]; item->popup->super.pos[1] = Input.mouse[1]; @@ -431,13 +433,13 @@ Menu_Generic_Destroy(&item->super); } -Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list) +Menu_ComboItem *Menu_Combo_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list) { //list is pipe-sperated Menu_ComboItem *it; - it = (Menu_ComboItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_ComboItem)); + it = (Menu_ComboItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_ComboItem)); - it->super.DrawMenu = Menu_DrawComboItem; + it->super.DrawMenu = Menu_Combo_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Combo_KeyPress; it->super.Destroy = Menu_Combo_Destroy; @@ -502,10 +504,10 @@ } return false; } -Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command) +Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command) { Menu_PictureItem *it; - it = (Menu_PictureItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_PictureItem)); + it = (Menu_PictureItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_PictureItem)); it->super.DrawMenu = Menu_Picture_Draw; if (command != NULL) @@ -531,7 +533,7 @@ //sliderh items -void Menu_SliderH_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) +void Menu_HSlider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) { Nfloat frac; @@ -601,12 +603,12 @@ } return false; } -Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) +Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) { Menu_SliderItem *it; - it = (Menu_SliderItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_SliderItem)); + it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); - it->super.DrawMenu = Menu_SliderH_Draw; + it->super.DrawMenu = Menu_HSlider_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Slider_KeyPress; @@ -632,7 +634,7 @@ //sliderv items -void Menu_SliderV_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) +void Menu_VSlider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) { Nfloat frac; @@ -672,12 +674,12 @@ R_DrawString("A", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); R_DrawString("V", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } -Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) +Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) { Menu_SliderItem *it; - it = (Menu_SliderItem*)Menu_CreateGenericItem(parent, x, y, sizeof(Menu_SliderItem)); + it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); - it->super.DrawMenu = Menu_SliderV_Draw; + it->super.DrawMenu = Menu_VSlider_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Slider_KeyPress; @@ -705,7 +707,7 @@ //submenus -void Menu_MouseMoveSubMenu(Menu_SubMenu *item, Menu_Inheritance *inh) +void Menu_SubMenu_MouseMove(Menu_SubMenu *item, Menu_Inheritance *inh) { Menu_Item *subitem; Menu_Inheritance ninh; @@ -760,7 +762,7 @@ for (subitem = item->subitems; subitem; subitem = subitem->next) subitem->MouseMove(subitem, &ninh); } -void Menu_DrawSubMenu(Menu_SubMenu *item, Menu_Inheritance *inh) +void Menu_SubMenu_Draw(Menu_SubMenu *item, Menu_Inheritance *inh) { Menu_Item *subitem, *next; Menu_Inheritance ninh; @@ -799,7 +801,7 @@ R_SetScissor(inh->window.pos[0], inh->window.pos[1], inh->window.size[0], inh->window.size[1]); } -Nbool Menu_KeyEventSubMenu (Menu_SubMenu *item, NUint mod, NUint sym, NUint character, Nbool downevent) +Nbool Menu_SubMenu_KeyEvent (Menu_SubMenu *item, NUint mod, NUint sym, NUint character, Nbool downevent) { Menu_Item *subitem; @@ -871,19 +873,19 @@ Menu_Generic_Destroy(&item->super); } -Menu_SubMenu *Menu_CreateMenu(Menu_SubMenu *parent) +Menu_SubMenu *Menu_SubMenu_Create(Menu_SubMenu *parent) { Menu_SubMenu *menu; - menu = (Menu_SubMenu*) Menu_CreateGenericItem(NULL, 0, 0, sizeof(Menu_SubMenu)); + menu = (Menu_SubMenu*) Menu_Generic_Create(NULL, 0, 0, sizeof(Menu_SubMenu)); if( parent ) { Menu_AddAtFront(parent, &menu->super); } - menu->super.MouseMove = Menu_MouseMoveSubMenu; - menu->super.DrawMenu = Menu_DrawSubMenu; - menu->super.KeyEvent = Menu_KeyEventSubMenu; + menu->super.MouseMove = Menu_SubMenu_MouseMove; + menu->super.DrawMenu = Menu_SubMenu_Draw; + menu->super.KeyEvent = Menu_SubMenu_KeyEvent; menu->super.Destroy = Menu_SubMenu_Destroy; menu->allowclose = true; @@ -891,6 +893,7 @@ return menu; } +// TODO: change this name, too void Menu_FinishMenu(Menu_SubMenu *menu) { Menu_Item *subitem; @@ -916,6 +919,7 @@ menu->subwindow.size[1] = maxpos[1]; } +// TODO: change this name as well? void Menu_ArrangeSubItems(Menu_SubMenu *menu, Nbool horizontal, NSint pad, Menu_ArrangeStyle arrange) { Menu_Item *sitem; @@ -1047,25 +1051,25 @@ void Menu_Menu_Test(void) { //fixme: we still need to figure out how to do the parent's frames, so the subwindow doesn't appear outside the parent - Menu_SubMenu *menu = Menu_CreateMenu(&Menu.rootmenu); + Menu_SubMenu *menu = Menu_SubMenu_Create(&Menu.rootmenu); Menu_SubMenu *child; - child = Menu_CreateMenu(menu); + child = Menu_SubMenu_Create(menu); child->subwindow.pos[0] = sliderscale; child->subwindow.pos[1] = sliderscale; child->super.pos[0] = sliderscale; child->super.pos[1] = sliderscale; - Menu_CreateHSliderItem(menu, sliderscale, 0, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); - Menu_CreateHSliderItem(menu, sliderscale, sliderscale+windowsize, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); - Menu_CreateVSliderItem(menu, 0, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); - Menu_CreateVSliderItem(menu, sliderscale+windowsize, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); - Menu_CreatePictureItem(child, 0, 0, imagesize, imagesize, "lhfont.tga", NULL); + Menu_HSlider_Create(menu, sliderscale, 0, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); + Menu_HSlider_Create(menu, sliderscale, sliderscale+windowsize, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); + Menu_VSlider_Create(menu, 0, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); + Menu_VSlider_Create(menu, sliderscale+windowsize, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); + Menu_Picture_Create(child, 0, 0, imagesize, imagesize, "lhfont.tga", NULL); Menu_FinishMenu(child); child->allowclose = false; - Menu_CreatePictureItem(child, 0, 0, child->super.size[0], child->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(child, 0, 0, child->super.size[0], child->super.size[1], "maps/test/skybox_ny.tga", NULL); menu->dragable = true; @@ -1073,7 +1077,7 @@ child->super.size[1] = windowsize; Menu_FinishMenu(menu); - Menu_CreatePictureItem(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); } static Shell_SymbolDecl Menu_Menu_Test_Decl = { "menu_test", @@ -1090,27 +1094,27 @@ void Menu_Main(void) { - Menu_SubMenu *menu = Menu_CreateMenu(&Menu.rootmenu); + Menu_SubMenu *menu = Menu_SubMenu_Create(&Menu.rootmenu); menu->dragable = true; - Menu_CreateTextItem(menu, 0, 0, "Main menu", NULL, NULL); + Menu_Text_Create(menu, 0, 0, "Main menu", NULL, NULL); - Menu_CreateTextItem(menu, 0, 16, "Hello World", "echo Hello World\n", NULL); - Menu_CreateTextItem(menu, 0, 24, "Start up test map", "map test\n", NULL); - Menu_CreateTextItem(menu, 0, 32, "Go to the west!", "map west\n", NULL); - Menu_CreateTextItem(menu, 0, 40, "quit", "menu_quit\n", NULL); + Menu_Text_Create(menu, 0, 16, "Hello World", "echo Hello World\n", NULL); + Menu_Text_Create(menu, 0, 24, "Start up test map", "map test\n", NULL); + Menu_Text_Create(menu, 0, 32, "Go to the west!", "map west\n", NULL); + Menu_Text_Create(menu, 0, 40, "quit", "menu_quit\n", NULL); - Menu_CreateTextItem(menu, 0, 56, "Close menu", "menu_close\n", NULL); + Menu_Text_Create(menu, 0, 56, "Close menu", "menu_close\n", NULL); - Menu_CreateTextItem(menu, 0, 56+16, "test menu", "menu_test\n", NULL); + Menu_Text_Create(menu, 0, 56+16, "test menu", "menu_test\n", NULL); - Menu_CreateEditItem(menu, 0, 56, "EditItem"); - Menu_CreateComboItem(menu, 0, 56, 21*8, "ComboItem", "Option 1|Option 2|Option 3|Fuzzy Little Bunnies|Big Rocket Launcher|Children|Lightning Gun|Newborn Chicks|Grenade Launcher|Rodents|Nukes"); + Menu_Edit_Create(menu, 0, 56, "EditItem"); + Menu_Combo_Create(menu, 0, 56, 21*8, "ComboItem", "Option 1|Option 2|Option 3|Fuzzy Little Bunnies|Big Rocket Launcher|Children|Lightning Gun|Newborn Chicks|Grenade Launcher|Rodents|Nukes"); Menu_FinishMenu(menu); Menu_ArrangeSubItems(menu, false, 0, MENU_ARRANGESTYLE_CENTER); Menu_FinishMenu(menu); - Menu_CreatePictureItem(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); Menu_MoveToCenter(menu); } @@ -1144,17 +1148,17 @@ //The simple quit menu void Menu_Menu_Quit(void) { - Menu_SubMenu *menu = Menu_CreateMenu(&Menu.rootmenu); + Menu_SubMenu *menu = Menu_SubMenu_Create(&Menu.rootmenu); menu->dragable = true; - Menu_CreateTextItem(menu, 0, 0, "Really Quit?", NULL, NULL); + Menu_Text_Create(menu, 0, 0, "Really Quit?", NULL, NULL); - Menu_CreateTextItem(menu, 0, 16, "Yes, and wipe my harddrive too.", "quit\n", NULL); - Menu_CreateTextItem(menu, 0, 24, "No. I want to keep playing this awesome game", "menu_close\n", NULL); + Menu_Text_Create(menu, 0, 16, "Yes, and wipe my harddrive too.", "quit\n", NULL); + Menu_Text_Create(menu, 0, 24, "No. I want to keep playing this awesome game", "menu_close\n", NULL); Menu_FinishMenu(menu); - Menu_CreatePictureItem(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); Menu_MoveToCenter(menu); } @@ -1177,7 +1181,8 @@ Shell_Register(&Menu_Menu_Close_Decl, NULL); // init the root menu - Menu.rootmenu.super.MouseMove = Menu_MouseMoveSubMenu; - Menu.rootmenu.super.DrawMenu = Menu_DrawSubMenu; - Menu.rootmenu.super.KeyEvent = Menu_KeyEventSubMenu; + // FIXME: create the rootmenu using the normal submenu creation function instead? + Menu.rootmenu.super.MouseMove = Menu_SubMenu_MouseMove; + Menu.rootmenu.super.DrawMenu = Menu_SubMenu_Draw; + Menu.rootmenu.super.KeyEvent = Menu_SubMenu_KeyEvent; } Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-12 22:11:29 UTC (rev 671) +++ trunk/game/m_menucore.h 2006-03-12 22:30:24 UTC (rev 672) @@ -152,12 +152,12 @@ Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent); -Menu_SubMenu *Menu_CreateMenu(Menu_SubMenu *parent); -Menu_SliderItem *Menu_CreateVSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//vertical scrolling bar -Menu_SliderItem *Menu_CreateHSliderItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//horizontal scrolling bar -Menu_TextItem *Menu_CreateTextItem(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. -Menu_EditItem *Menu_CreateEditItem(Menu_SubMenu *parent, NSint x, NSint y, char *text); //an item for editing text (fixme: needs callbacks and stuff) -Menu_ComboItem *Menu_CreateComboItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list);//a list of multiple choices. -Menu_PictureItem *Menu_CreatePictureItem(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command); //just a simple picture. clicking it can give a console command (fixme: make like text) +Menu_SubMenu *Menu_SubMenu_Create(Menu_SubMenu *parent); +Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//vertical scrolling bar +Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//horizontal scrolling bar +Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. +Menu_EditItem *Menu_Edit_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text); //an item for editing text (fixme: needs callbacks and stuff) +Menu_ComboItem *Menu_Combo_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list);//a list of multiple choices. +Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command); //just a simple picture. clicking it can give a console command (fixme: make like text) #endif From black at icculus.org Mon Mar 13 15:59:04 2006 From: black at icculus.org (black at icculus.org) Date: 13 Mar 2006 15:59:04 -0500 Subject: r673 - trunk/game Message-ID: <20060313205904.1292.qmail@icculus.org> Author: black Date: 2006-03-13 15:59:04 -0500 (Mon, 13 Mar 2006) New Revision: 673 Modified: trunk/game/m_menucore.c Log: Change a few more functions to use subnamespaces (its consistent with the current relationship between Item and SubMenu). Menu_GetItem is now the last non-global function that doesn't belong to any item namespace. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-12 22:30:24 UTC (rev 672) +++ trunk/game/m_menucore.c 2006-03-13 20:59:04 UTC (rev 673) @@ -17,10 +17,10 @@ -make it more strict and error out earlier */ -void Menu_FinishMenu(Menu_SubMenu *menu); +void Menu_SubMenu_Finish(Menu_SubMenu *menu); // if the item has no parent, it doesn't do anything -void Menu_RemoveFromParent(Menu_Item *item) +void Menu_Item_RemoveFromParent(Menu_Item *item) { if (item->parent) { @@ -53,7 +53,7 @@ } } -void Menu_AddAtFront(Menu_SubMenu *parent, Menu_Item *item) +void Menu_SubMenu_AddAtFront(Menu_SubMenu *parent, Menu_Item *item) { assert( item != NULL ); assert( parent != NULL ); @@ -72,7 +72,7 @@ } } -void Menu_AddToBack(Menu_SubMenu *parent, Menu_Item *item ) +void Menu_SubMenu_AddToBack(Menu_SubMenu *parent, Menu_Item *item ) { assert( item != NULL ); assert( parent != NULL ); @@ -83,30 +83,55 @@ parent->subitems = item; } -void Menu_BringToFront(Menu_SubMenu *menu) +void Menu_SubMenu_BringToFront(Menu_Item *item) { - Menu_SubMenu *parent = menu->super.parent; + Menu_SubMenu *parent = item->parent; // FIXME: fix this if( !parent ) { return; } - Menu_RemoveFromParent(&menu->super); - Menu_AddAtFront(parent, &menu->super); + Menu_Item_RemoveFromParent(item); + Menu_SubMenu_AddAtFront(parent, item); } -// TODO: add fully qualified names with a scope operator (:: or.?) -void *Menu_GetItem(Menu_SubMenu *parent, char *name) +// TODO: use NString for everything +// TODO: this is the last function that doesnt belong to an item type (we may need to rethink its design) +void *Menu_GetItem(Menu_SubMenu *parent, const char *name) { - Menu_Item *sub; - if (!parent) - parent = &Menu.rootmenu; + Menu_SubMenu *current_parent; + Menu_Item *item; + const char *name_start, *name_end; - for (sub = parent->subitems; sub; sub = sub->next) + current_parent = parent; + if (!current_parent) { - if (!strcmp(sub->name, name)) - return sub; + current_parent = &Menu.rootmenu; } - return NULL; + + name_start = name; + while (*name_start) + { + name_end = strchr(name_start, '.'); + if (name_end == NULL) + { + name_end = name + String_Length(name_start); + } + for (item = parent->subitems; item; item = item->next) + { + if (String_NCompare(item->name, name, name_end - name_start) == 0) + { + break; + } + } + if (item == NULL) + { + break; + } + name_start = name_end + 1; + // FIXME: we don't really know whether item is really a submenu... + current_parent = (Menu_SubMenu*) item; + } + return item; } void Menu_MoveToCenter(Menu_SubMenu *menu) @@ -144,7 +169,7 @@ void Menu_Generic_Destroy(Menu_Item *item) { - Menu_RemoveFromParent(item); + Menu_Item_RemoveFromParent(item); if (Menu.grabs == item) Menu.grabs = NULL; //hrm. @@ -168,7 +193,7 @@ if (parent) { - Menu_AddToBack(parent, item); + Menu_SubMenu_AddToBack(parent, item); } return item; @@ -398,7 +423,7 @@ NUint i; item->popup = Menu_SubMenu_Create(&Menu.rootmenu); - Menu_BringToFront(item->popup); + Menu_SubMenu_BringToFront(&item->popup->super); interior = Menu_SubMenu_Create(item->popup); interior->allowclose = false; Menu.grabs = &item->popup->super; @@ -418,9 +443,9 @@ item->popup->subwindow.pos[0] = item->popup->super.pos[0]; item->popup->subwindow.pos[1] = item->popup->super.pos[1]; - Menu_FinishMenu(interior); + Menu_SubMenu_Finish(interior); interior->super.size[1] = ((i>64)?64:i); - Menu_FinishMenu(item->popup); + Menu_SubMenu_Finish(item->popup); return true; } return false; @@ -721,7 +746,7 @@ item->super.pos[1] += Input.mouse[1] - item->dragmousepos[1]; item->dragmousepos[0] = Input.mouse[0]; item->dragmousepos[1] = Input.mouse[1]; -// Menu_FinishMenu(item->super.parent); +// Menu_SubMenu_Finish(item->super.parent); } for (j = 0; j < 2; j++) @@ -805,7 +830,7 @@ { Menu_Item *subitem; - Menu_BringToFront(item); + Menu_SubMenu_BringToFront(&item->super); subitem = item->selecteditem; if (item->selecteditem) @@ -814,7 +839,7 @@ if (item->allowclose && sym == SDLK_ESCAPE) { - Menu_RemoveFromParent(&item->super); + Menu_Item_RemoveFromParent(&item->super); item->super.Destroy(item); return true; } @@ -824,25 +849,25 @@ if (sym == SDLK_LEFT) { item->super.pos[0] -= 4; - Menu_FinishMenu(item); + Menu_SubMenu_Finish(item); return true; } if (sym == SDLK_UP) { item->super.pos[1] -= 4; - Menu_FinishMenu(item); + Menu_SubMenu_Finish(item); return true; } if (sym == SDLK_RIGHT) { item->super.pos[0] += 4; - Menu_FinishMenu(item); + Menu_SubMenu_Finish(item); return true; } if (sym == SDLK_DOWN) { item->super.pos[1] += 4; - Menu_FinishMenu(item); + Menu_SubMenu_Finish(item); return true; } @@ -880,7 +905,7 @@ menu = (Menu_SubMenu*) Menu_Generic_Create(NULL, 0, 0, sizeof(Menu_SubMenu)); if( parent ) { - Menu_AddAtFront(parent, &menu->super); + Menu_SubMenu_AddAtFront(parent, &menu->super); } menu->super.MouseMove = Menu_SubMenu_MouseMove; @@ -893,8 +918,7 @@ return menu; } -// TODO: change this name, too -void Menu_FinishMenu(Menu_SubMenu *menu) +void Menu_SubMenu_Finish(Menu_SubMenu *menu) { Menu_Item *subitem; NSint maxpos[2]; @@ -919,8 +943,7 @@ menu->subwindow.size[1] = maxpos[1]; } -// TODO: change this name as well? -void Menu_ArrangeSubItems(Menu_SubMenu *menu, Nbool horizontal, NSint pad, Menu_ArrangeStyle arrange) +void Menu_SubMenu_Arrange(Menu_SubMenu *menu, Nbool horizontal, NSint pad, Menu_ArrangeStyle arrange) { Menu_Item *sitem; NSint axis, otheraxis; @@ -1067,7 +1090,7 @@ Menu_Picture_Create(child, 0, 0, imagesize, imagesize, "lhfont.tga", NULL); - Menu_FinishMenu(child); + Menu_SubMenu_Finish(child); child->allowclose = false; Menu_Picture_Create(child, 0, 0, child->super.size[0], child->super.size[1], "maps/test/skybox_ny.tga", NULL); @@ -1076,7 +1099,7 @@ child->super.size[0] = windowsize; child->super.size[1] = windowsize; - Menu_FinishMenu(menu); + Menu_SubMenu_Finish(menu); Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); } static Shell_SymbolDecl Menu_Menu_Test_Decl = { @@ -1111,9 +1134,9 @@ Menu_Edit_Create(menu, 0, 56, "EditItem"); Menu_Combo_Create(menu, 0, 56, 21*8, "ComboItem", "Option 1|Option 2|Option 3|Fuzzy Little Bunnies|Big Rocket Launcher|Children|Lightning Gun|Newborn Chicks|Grenade Launcher|Rodents|Nukes"); - Menu_FinishMenu(menu); - Menu_ArrangeSubItems(menu, false, 0, MENU_ARRANGESTYLE_CENTER); - Menu_FinishMenu(menu); + Menu_SubMenu_Finish(menu); + Menu_SubMenu_Arrange(menu, false, 0, MENU_ARRANGESTYLE_CENTER); + Menu_SubMenu_Finish(menu); Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); Menu_MoveToCenter(menu); @@ -1156,7 +1179,7 @@ Menu_Text_Create(menu, 0, 16, "Yes, and wipe my harddrive too.", "quit\n", NULL); Menu_Text_Create(menu, 0, 24, "No. I want to keep playing this awesome game", "menu_close\n", NULL); - Menu_FinishMenu(menu); + Menu_SubMenu_Finish(menu); Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); From spike at icculus.org Mon Mar 13 16:15:28 2006 From: spike at icculus.org (spike at icculus.org) Date: 13 Mar 2006 16:15:28 -0500 Subject: r674 - trunk/game Message-ID: <20060313211528.3347.qmail@icculus.org> Author: spike Date: 2006-03-13 16:15:28 -0500 (Mon, 13 Mar 2006) New Revision: 674 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: tweeked combo. (possibly) improoved offseting (well, makes more sense now). Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-13 20:59:04 UTC (rev 673) +++ trunk/game/m_menucore.c 2006-03-13 21:15:28 UTC (rev 674) @@ -10,7 +10,7 @@ MenuState Menu; -#define MOUSE1 (SDLK_LAST + 1) +#define MOUSE1 (SDLK_LAST + 1) //yeah, this needs something suitable /* -make every item have a parent @@ -44,9 +44,13 @@ break; } } - if( node->next == NULL ) { + /*if( node->next == NULL ) + { // FIXME: error condition - } + + //Black: if you want an error condition here, you should probably make sure that item->next wasn't null too. + //Just felt I should point that out. + }*/ } item->next = NULL; item->parent = NULL; @@ -87,9 +91,8 @@ { Menu_SubMenu *parent = item->parent; // FIXME: fix this - if( !parent ) { + if( !parent ) return; - } Menu_Item_RemoveFromParent(item); Menu_SubMenu_AddAtFront(parent, item); } @@ -139,10 +142,15 @@ // TODO: make it move to the center of the parent menu->super.pos[0] = (Video.width - menu->super.size[0])/2; menu->super.pos[1] = (Video.height - menu->super.size[1])/2; - menu->subwindow.pos[0] = menu->super.pos[0]; - menu->subwindow.pos[1] = menu->super.pos[1]; + menu->subwindow.pos[0] = 0; + menu->subwindow.pos[1] = 0; } + + + + + //generic items void Menu_Generic_MouseMoveSelectable(Menu_Item *item, Menu_Inheritance *inh) { @@ -212,22 +220,22 @@ R_SetTexture(R.resource_font); R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } -void Menu_Text_DefaultUse (struct Menu_TextItem *item) +void Menu_Text_DefaultUse (struct Menu_TextItem *item, void *cookie) { - Shell_ExecuteScript("menu text use", item->command); + Shell_ExecuteScript("menu text use", cookie); } Nbool Menu_Text_KeyPress (Menu_TextItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { if (sym == SDLK_RETURN || sym == MOUSE1) { if (downevent) - if (item->UseTextItem) - item->UseTextItem(item); + if (item->UseItem) + item->UseItem(item, item->cookie); return true; } return false; } -Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)) +Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseItem) (struct Menu_TextItem *item, void *cookie)) { Menu_TextItem *it; it = (Menu_TextItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_TextItem)); @@ -242,12 +250,12 @@ it->super.size[1] = 8; it->text = text; - it->command = command; + it->cookie = command; - if (UseTextItem == NULL && command) - UseTextItem = Menu_Text_DefaultUse; + if (UseItem == NULL && command) + UseItem = Menu_Text_DefaultUse; - it->UseTextItem = UseTextItem; + it->UseItem = UseItem; return it; } @@ -368,20 +376,19 @@ //combos void Menu_Combo_Draw(Menu_ComboItem *item, Menu_Inheritance *inh) { - R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - R_SetTexture(R.resource_font); - R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - - R_DrawString("V", 0, item->super.pos[0] + item->super.size[0]-8 + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + item->super.super.size[0]-=8; + Menu_Edit_Draw(&item->super, inh); + R_DrawString("V", 0, item->super.super.pos[0] + item->super.super.size[0] + inh->addpos[0], item->super.super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.super.parent->selecteditem == &item->super.super); + item->super.super.size[0]+=8; } void Menu_Combo_SetText(Menu_ComboItem *item, char *text)//it's just easier. not sure whether this should be public or not. { Menu_ComboOption *option; char *oldtext; - oldtext = item->text; - item->text = Mem_Alloc(Menu.menu_zone, strlen(text)+1); - strcpy(item->text, text); + oldtext = item->super.text; + item->super.text = Mem_Alloc(Menu.menu_zone, strlen(text)+1); + strcpy(item->super.text, text); item->selected = NULL; for (option = item->options; option; option = option->next) @@ -395,15 +402,19 @@ Mem_Free(&oldtext); } +void Menu_Combo_AddOption(Menu_ComboItem *item, char *text, int key) +{ -void Menu_Combo_UseSlider (Menu_SliderItem *slider) +} + +void Menu_Combo_UseSlider (Menu_SliderItem *slider, void *cookie) { - Menu_SubMenu *submenu = slider->data; + Menu_SubMenu *submenu = cookie; submenu->subwindow.pos[1] = -slider->value; } -void Menu_Combo_UseOption (Menu_TextItem *it) +void Menu_Combo_UseOption (Menu_TextItem *it, void *cookie) { - Menu_ComboItem *comboitem = (void*)it->command; + Menu_ComboItem *comboitem = cookie; Menu_Combo_SetText(comboitem, it->text); //seeing as this happens from a key event, and the text control will return true, we can safly kill the popup @@ -412,7 +423,7 @@ } -Nbool Menu_Combo_KeyPress (Menu_ComboItem *item, UNUSED NUint mod, UNUSED NUint sym, UNUSED NUint character, UNUSED Nbool downevent) +Nbool Menu_Combo_KeyPress (Menu_ComboItem *item, NUint mod, NUint sym, NUint character, Nbool downevent) { if (sym == SDLK_RETURN || sym == MOUSE1) { @@ -431,51 +442,50 @@ for (i = 0; option; i+=8, option = option->next) { txt = Menu_Text_Create(interior, 0, i, option->text, item, Menu_Combo_UseOption); - txt->super.size[0] = item->super.size[0] - 8; + txt->super.size[0] = item->super.super.size[0] - 8; } pixels = i-64; if (pixels < 0) pixels = 0; - Menu_VSlider_Create(item->popup, item->super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_Combo_UseSlider, NULL, interior); + Menu_VSlider_Create(item->popup, item->super.super.size[0] - 8, 0, 8, ((i>64)?64:i), 0, pixels, 0, Menu_Combo_UseSlider, NULL, interior); item->popup->super.pos[0] = Input.mouse[0]; item->popup->super.pos[1] = Input.mouse[1]; - item->popup->subwindow.pos[0] = item->popup->super.pos[0]; - item->popup->subwindow.pos[1] = item->popup->super.pos[1]; Menu_SubMenu_Finish(interior); interior->super.size[1] = ((i>64)?64:i); Menu_SubMenu_Finish(item->popup); return true; } - return false; + else + return Menu_Edit_KeyPress(&item->super, mod, sym, character, downevent); } void Menu_Combo_Destroy(Menu_ComboItem *item) { if (item->popup) item->popup->super.Destroy(item->popup); - Menu_Generic_Destroy(&item->super); + Menu_Generic_Destroy(&item->super.super); } Menu_ComboItem *Menu_Combo_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list) { - //list is pipe-sperated + //list is pipe-seperated Menu_ComboItem *it; it = (Menu_ComboItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_ComboItem)); - it->super.DrawMenu = Menu_Combo_Draw; - it->super.MouseMove = Menu_Generic_MouseMoveSelectable; - it->super.KeyEvent = Menu_Combo_KeyPress; - it->super.Destroy = Menu_Combo_Destroy; - it->super.size[0] = w; - it->super.size[1] = 8; + it->super.super.DrawMenu = Menu_Combo_Draw; + it->super.super.MouseMove = Menu_Generic_MouseMoveSelectable; + it->super.super.KeyEvent = Menu_Combo_KeyPress; + it->super.super.Destroy = Menu_Combo_Destroy; + it->super.super.size[0] = w; + it->super.super.size[1] = 8; //FIXME: no delete to free the text - it->text = Mem_Alloc(Menu.menu_zone, strlen(defalt)+1); - strcpy(it->text, defalt); + it->super.text = Mem_Alloc(Menu.menu_zone, strlen(defalt)+1); + strcpy(it->super.text, defalt); - if (*list) + if (list && *list) { char *pipe; NUint chars; @@ -519,17 +529,24 @@ R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); } +void Menu_Picture_DefaultUse (struct Menu_PictureItem *item, void *cookie) +{ + Shell_ExecuteScript("console", cookie); +} Nbool Menu_Picture_KeyPress (Menu_PictureItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { if (sym == SDLK_RETURN || sym == MOUSE1) { - if (downevent) - Shell_ExecuteScript("console", item->command); - return true; + if (item->UseItem) + { + if (downevent) + item->UseItem(item, item->cookie); + return true; + } } return false; } -Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command) +Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, void *command, void (*UseItem) (struct Menu_PictureItem *item, void *cookie)) { Menu_PictureItem *it; it = (Menu_PictureItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_PictureItem)); @@ -543,8 +560,12 @@ it->super.size[0] = w; it->super.size[1] = h; + if (command && !UseItem) + UseItem = Menu_Picture_DefaultUse; + it->imagename = imagename; - it->command = command; + it->cookie = command; + it->UseItem = UseItem; return it; } @@ -580,12 +601,12 @@ item->value /= item->super.size[0] - item->scale*3; item->value += item->minv; - item->SliderChanged(item); + item->SliderChanged(item, item->cookie); } } if (item->SliderUpdate) - item->SliderUpdate(item); + item->SliderUpdate(item, item->cookie); R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -613,7 +634,7 @@ if (downevent) { item->value -= 1; - item->SliderChanged(item); + item->SliderChanged(item, item->cookie); } return true; } @@ -622,13 +643,13 @@ if (downevent) { item->value += 1; - item->SliderChanged(item); + item->SliderChanged(item, item->cookie); } return true; } return false; } -Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) +Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie) { Menu_SliderItem *it; it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); @@ -642,7 +663,7 @@ it->scale = h; - it->data = data; + it->cookie = cookie; it->maxv = maxv; it->minv = minv; it->value = defaultv; @@ -681,12 +702,12 @@ item->value /= item->super.size[1] - item->scale*3; item->value += item->minv; - item->SliderChanged(item); + item->SliderChanged(item, item->cookie); } } if (item->SliderUpdate) - item->SliderUpdate(item); + item->SliderUpdate(item, item->cookie); R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -699,7 +720,7 @@ R_DrawString("A", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); R_DrawString("V", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } -Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data) +Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie) { Menu_SliderItem *it; it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); @@ -713,7 +734,7 @@ it->scale = w; - it->data = data; + it->cookie = cookie; it->maxv = maxv; it->minv = minv; it->value = defaultv; @@ -740,24 +761,15 @@ if (Menu.grabs == &item->super && item->dragable) { - item->subwindow.pos[0] += Input.mouse[0] - item->dragmousepos[0]; - item->subwindow.pos[1] += Input.mouse[1] - item->dragmousepos[1]; item->super.pos[0] += Input.mouse[0] - item->dragmousepos[0]; item->super.pos[1] += Input.mouse[1] - item->dragmousepos[1]; item->dragmousepos[0] = Input.mouse[0]; item->dragmousepos[1] = Input.mouse[1]; -// Menu_SubMenu_Finish(item->super.parent); } for (j = 0; j < 2; j++) { NSint wmin, wmax; -/* if (Input.mouse[j] < item->subwindow.pos[j]+inh->addpos[j] || Input.mouse[j] > item->subwindow.pos[j]+inh->addpos[j] + item->subwindow.size[j]) - { - item->indrag = false; - return; - } -*/ wmin = inh->addpos[j] + item->super.pos[j]; wmax = wmin + item->super.size[j]; @@ -773,12 +785,11 @@ ninh.window.pos[j] = wmin; ninh.window.size[j] = wmax-wmin; + + ninh.addpos[j] = inh->addpos[j] + item->subwindow.pos[j] + wmin; } - ninh.addpos[0] = inh->addpos[0] + item->subwindow.pos[0]; - ninh.addpos[1] = inh->addpos[1] + item->subwindow.pos[1]; - if (item->super.parent) item->super.parent->selecteditem = &item->super; //mouse is in us. @@ -799,9 +810,6 @@ item->selecteditem = NULL; } - ninh.addpos[0] = inh->addpos[0] + item->subwindow.pos[0]; - ninh.addpos[1] = inh->addpos[1] + item->subwindow.pos[1]; - for (j = 0; j < 2; j++) { NSint wmin, wmax; @@ -813,6 +821,8 @@ if (wmax > inh->window.pos[j] + inh->window.size[j]) wmax = inh->window.pos[j] + inh->window.size[j]; ninh.window.size[j] = wmax-wmin; + + ninh.addpos[j] = item->subwindow.pos[j] + wmin; } @@ -922,25 +932,34 @@ { Menu_Item *subitem; NSint maxpos[2]; + NSint minpos[2]; assert( menu != NULL ); maxpos[0] = 0; maxpos[1] = 0; + minpos[0] = 0x32767; + minpos[1] = 0x32767; + for (subitem = menu->subitems; subitem; subitem = subitem->next) { if (maxpos[0] < subitem->pos[0] + subitem->size[0]) maxpos[0] = subitem->pos[0] + subitem->size[0]; if (maxpos[1] < subitem->pos[1] + subitem->size[1]) maxpos[1] = subitem->pos[1] + subitem->size[1]; + + if (minpos[0] > subitem->pos[0]) + minpos[0] = subitem->pos[0]; + if (minpos[1] > subitem->pos[1]) + minpos[1] = subitem->pos[1]; } menu->super.size[0] = maxpos[0]; menu->super.size[1] = maxpos[1]; - menu->subwindow.size[0] = maxpos[0]; - menu->subwindow.size[1] = maxpos[1]; + menu->subwindow.size[0] = maxpos[0] - minpos[0]; + menu->subwindow.size[1] = maxpos[1] - minpos[1]; } void Menu_SubMenu_Arrange(Menu_SubMenu *menu, Nbool horizontal, NSint pad, Menu_ArrangeStyle arrange) @@ -1049,26 +1068,26 @@ Nfloat sliderscale = 8; Nfloat imagesize = 512; Nfloat windowsize = 128; -void MoveMenuH(Menu_SliderItem *it) +void MoveMenuH(Menu_SliderItem *it, void *cookie) { - Menu_SubMenu *menu = it->data; + Menu_SubMenu *menu = cookie; // it->value = 16*(NSint)(it->value/16); menu->subwindow.pos[0] = it->value; } -void UpdateMoveMenuH(Menu_SliderItem *it) +void UpdateMoveMenuH(Menu_SliderItem *it, void *cookie) { - Menu_SubMenu *menu = it->data; + Menu_SubMenu *menu = cookie; it->value = menu->subwindow.pos[0]; } -void MoveMenuV(Menu_SliderItem *it) +void MoveMenuV(Menu_SliderItem *it, void *cookie) { - Menu_SubMenu *menu = it->data; + Menu_SubMenu *menu = cookie; menu->subwindow.pos[1] = it->value; } -void UpdateMoveMenuV(Menu_SliderItem *it) +void UpdateMoveMenuV(Menu_SliderItem *it, void *cookie) { - Menu_SubMenu *menu = it->data; + Menu_SubMenu *menu = cookie; it->value = menu->subwindow.pos[1]; } void Menu_Menu_Test(void) @@ -1087,20 +1106,21 @@ Menu_HSlider_Create(menu, sliderscale, sliderscale+windowsize, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); Menu_VSlider_Create(menu, 0, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); Menu_VSlider_Create(menu, sliderscale+windowsize, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); - Menu_Picture_Create(child, 0, 0, imagesize, imagesize, "lhfont.tga", NULL); + Menu_Picture_Create(child, 0, 0, imagesize, imagesize, "lhfont.tga", NULL, NULL); - Menu_SubMenu_Finish(child); child->allowclose = false; - Menu_Picture_Create(child, 0, 0, child->super.size[0], child->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(child, 0, 0, child->super.size[0], child->super.size[1], "maps/test/skybox_ny.tga", NULL, NULL); + menu->dragable = true; child->super.size[0] = windowsize; child->super.size[1] = windowsize; Menu_SubMenu_Finish(menu); - Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); + + Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL, NULL); } static Shell_SymbolDecl Menu_Menu_Test_Decl = { "menu_test", @@ -1137,7 +1157,7 @@ Menu_SubMenu_Finish(menu); Menu_SubMenu_Arrange(menu, false, 0, MENU_ARRANGESTYLE_CENTER); Menu_SubMenu_Finish(menu); - Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL, NULL); Menu_MoveToCenter(menu); } @@ -1181,7 +1201,7 @@ Menu_SubMenu_Finish(menu); - Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL); + Menu_Picture_Create(menu, 0, 0, menu->super.size[0], menu->super.size[1], "maps/test/skybox_ny.tga", NULL, NULL); Menu_MoveToCenter(menu); } Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-13 20:59:04 UTC (rev 673) +++ trunk/game/m_menucore.h 2006-03-13 21:15:28 UTC (rev 674) @@ -53,9 +53,9 @@ Menu_Item super; char *text; //what to display (warning: it's a pointer, isn't freed, and isn't copied) - void *command; //command is a misnomer, it should be used as a cookie for the text item + void *cookie; //command is a misnomer, it should be used as a cookie for the text item - void (*UseTextItem) (struct Menu_TextItem *item); //called when the user uses this item + void (*UseItem) (struct Menu_TextItem *item, void *cookie); //called when the user uses (clicks) this item } Menu_TextItem; @@ -63,10 +63,13 @@ { Menu_Item super; + Nbool editable; //user may type into the control char *text; //what it currently says NUint cursorpos; //where the cursor is, set between 0 and strlen(text) NSint scrollpos; //fixme NUint maxchars; //0 for unlimited + + void (*ChangeEvent) (struct Menu_EditItem *item, char *newtext, void *cookie); } Menu_EditItem; @@ -80,18 +83,14 @@ typedef struct Menu_ComboItem { - Menu_Item super; + Menu_EditItem super; //this is one advantage of c++. - Nbool editable; //user may type into the control struct Menu_ComboOption *options; //a list of the current options struct Menu_ComboOption *selected; //set - char *text; - NSint cursorpos; - NUint scrollpos; - NUint maxchars; + struct Menu_SubMenu *popup; - struct Menu_SubMenu *popup; + void (*ChangeEvent) (struct Menu_EditItem *item, char *newtext, NSint optionident, void *cookie); //we use the ChangeEvent of the text item to set our 'selected' value } Menu_ComboItem; @@ -100,7 +99,9 @@ Menu_Item super; char *imagename; - char *command; //console command when clicked + void *cookie; //console command when clicked + + void (*UseItem) (struct Menu_PictureItem *item, void *cookie); //called when the user uses (clicks) this item } Menu_PictureItem; @@ -108,7 +109,7 @@ { Menu_Item super; - void *data; //for custom stuff + void *cookie; //for custom stuff Nfloat value;//set and used in the slider code Nfloat minv;//min value @@ -117,8 +118,8 @@ Nfloat scale;//size of slider, in pixels. //notification function - void (*SliderChanged) (struct Menu_SliderItem *slider); //the user just changed the slider->value - void (*SliderUpdate) (struct Menu_SliderItem *slider); //about to draw the slider's value, where you should feel free to update the value from external sources + void (*SliderChanged) (struct Menu_SliderItem *slider, void *cookie); //the user just changed the slider->value + void (*SliderUpdate) (struct Menu_SliderItem *slider, void *cookie); //about to draw the slider's value, where you should feel free to update the value from external sources //internal Nbool mousepressed; //adjust the slider with the mouse @@ -144,20 +145,25 @@ } MenuState; extern MenuState Menu; + + + +//Entry points central to the menu's workings void Menu_Draw(void); void Menu_Frame(void); void Menu_Main(void); void Menu_Init(void); Nbool Menu_IsVisible(void); -Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent); +Nbool Menu_KeyEvent(NUint mod, NUint sym, NUint character, Nbool downevent); +//Entry points for using the menu in other systems Menu_SubMenu *Menu_SubMenu_Create(Menu_SubMenu *parent); -Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//vertical scrolling bar -Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem*), void (*UpdateSlider)(Menu_SliderItem*), void *data);//horizontal scrolling bar -Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseTextItem) (struct Menu_TextItem *item)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. +Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);//vertical scrolling bar +Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);//horizontal scrolling bar +Menu_TextItem *Menu_Text_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text, void *command, void (*UseItem) (struct Menu_TextItem *item, void *cookie)); //if usetextitem == null, interpret as a console command. if not null, command can be used as a magic cookie. If both null, item is non-selectable. Menu_EditItem *Menu_Edit_Create(Menu_SubMenu *parent, NSint x, NSint y, char *text); //an item for editing text (fixme: needs callbacks and stuff) Menu_ComboItem *Menu_Combo_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, char *defalt, char *list);//a list of multiple choices. -Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, char *command); //just a simple picture. clicking it can give a console command (fixme: make like text) +Menu_PictureItem *Menu_Picture_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, char *imagename, void *command, void (*UseItem) (struct Menu_PictureItem *item, void *cookie)); //just a simple picture. clicking it can give a console command #endif From spike at icculus.org Mon Mar 13 16:28:38 2006 From: spike at icculus.org (spike at icculus.org) Date: 13 Mar 2006 16:28:38 -0500 Subject: r675 - trunk/game Message-ID: <20060313212838.4941.qmail@icculus.org> Author: spike Date: 2006-03-13 16:28:38 -0500 (Mon, 13 Mar 2006) New Revision: 675 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: Attempt two at sliders. The total code is smaller and shared between both sorts of slider (except the 3 actual calls to drawing functions). Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-13 21:15:28 UTC (rev 674) +++ trunk/game/m_menucore.c 2006-03-13 21:28:38 UTC (rev 675) @@ -579,7 +579,7 @@ //sliderh items -void Menu_HSlider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) +void Menu_Slider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) { Nfloat frac; @@ -591,14 +591,14 @@ if (Menu.grabs == &item->super) { { - item->value = Input.mouse[0] - (item->super.pos[0]+inh->addpos[0] + item->scale*1.5); + item->value = Input.mouse[item->axis] - (item->super.pos[item->axis]+inh->addpos[item->axis] + item->scale*1.5); if (item->value < 0) item->value = 0; - if (item->value > item->super.size[0] - item->scale*3) - item->value = item->super.size[0] - item->scale*3; + if (item->value > item->super.size[item->axis] - item->scale*3) + item->value = item->super.size[item->axis] - item->scale*3; item->value *= item->maxv - item->minv; - item->value /= item->super.size[0] - item->scale*3; + item->value /= item->super.size[item->axis] - item->scale*3; item->value += item->minv; item->SliderChanged(item, item->cookie); @@ -612,12 +612,19 @@ frac = (item->value-item->minv)/(item->maxv-item->minv); R_SetTexture(R.resource_font); -// snprintf(value, sizeof(value), "%f%%", frac); -// R_DrawString(value, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0] + item->scale + (item->super.size[0]-item->scale*3)*frac, item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("<", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString(">", 0, item->super.pos[0] + inh->addpos[0] - item->scale + (item->super.size[0]), item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + if (item->axis == 0) + { + R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0] + item->scale + (item->super.size[0]-item->scale*3)*frac, item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("<", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString(">", 0, item->super.pos[0] + inh->addpos[0] - item->scale + (item->super.size[0]), item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + } + else + { + R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] + item->scale + (item->super.size[1]-item->scale*3)*frac, item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("A", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("V", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + } } Nbool Menu_Slider_KeyPress (Menu_SliderItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) { @@ -649,20 +656,22 @@ } return false; } -Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie) +Menu_SliderItem *Menu_Slider_Create(Menu_SubMenu *parent, NUint axis, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie) { Menu_SliderItem *it; it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); - it->super.DrawMenu = Menu_HSlider_Draw; + it->super.DrawMenu = Menu_Slider_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Slider_KeyPress; it->super.size[0] = w; it->super.size[1] = h; - it->scale = h; + it->axis = axis; + it->scale = axis?w:h; + it->cookie = cookie; it->maxv = maxv; it->minv = minv; @@ -672,86 +681,25 @@ return it; } - - - - - - - -//sliderv items -void Menu_VSlider_Draw(Menu_SliderItem *item, Menu_Inheritance *inh) +Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie) { - Nfloat frac; - -// R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -// R_SetColor(1, 1, 1, 1); -// R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); -// R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); - - if (Menu.grabs == &item->super) - { - { - item->value = Input.mouse[1] - ((item->super.pos[1]+inh->addpos[1]) + item->scale*1.5); - if (item->value < 0) - item->value = 0; - if (item->value > item->super.size[1] - item->scale*3) - item->value = item->super.size[1] - item->scale*3; - - item->value *= item->maxv - item->minv; - item->value /= item->super.size[1] - item->scale*3; - item->value += item->minv; - - item->SliderChanged(item, item->cookie); - } - } - - if (item->SliderUpdate) - item->SliderUpdate(item, item->cookie); - - R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - frac = (item->value-item->minv)/(item->maxv-item->minv); - R_SetTexture(R.resource_font); -// snprintf(value, sizeof(value), "%f%%", frac); -// R_DrawString(value, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - - R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] + item->scale + (item->super.size[1]-item->scale*3)*frac, item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("A", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("V", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + return Menu_Slider_Create(parent, 0, x, y, w, h, minv, maxv, defaultv, ChangeNotification, UpdateSlider, cookie); } Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie) { - Menu_SliderItem *it; - it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); + return Menu_Slider_Create(parent, 1, x, y, w, h, minv, maxv, defaultv, ChangeNotification, UpdateSlider, cookie); +} - it->super.DrawMenu = Menu_VSlider_Draw; - it->super.MouseMove = Menu_Generic_MouseMoveSelectable; - it->super.KeyEvent = Menu_Slider_KeyPress; - it->super.size[0] = w; - it->super.size[1] = h; - it->scale = w; - it->cookie = cookie; - it->maxv = maxv; - it->minv = minv; - it->value = defaultv; - it->SliderChanged = ChangeNotification; - it->SliderUpdate = UpdateSlider; - return it; -} - - - //submenus void Menu_SubMenu_MouseMove(Menu_SubMenu *item, Menu_Inheritance *inh) { @@ -1097,15 +1045,13 @@ Menu_SubMenu *child; child = Menu_SubMenu_Create(menu); - child->subwindow.pos[0] = sliderscale; - child->subwindow.pos[1] = sliderscale; child->super.pos[0] = sliderscale; child->super.pos[1] = sliderscale; - Menu_HSlider_Create(menu, sliderscale, 0, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); - Menu_HSlider_Create(menu, sliderscale, sliderscale+windowsize, windowsize, sliderscale, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); - Menu_VSlider_Create(menu, 0, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); - Menu_VSlider_Create(menu, sliderscale+windowsize, sliderscale, sliderscale, windowsize, sliderscale, sliderscale-imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); + Menu_HSlider_Create(menu, sliderscale, 0, windowsize, sliderscale, 0, -imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); + Menu_HSlider_Create(menu, sliderscale, sliderscale+windowsize, windowsize, sliderscale, 0, -imagesize + windowsize, 0, MoveMenuH, UpdateMoveMenuH, child); + Menu_VSlider_Create(menu, 0, sliderscale, sliderscale, windowsize, 0, -imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); + Menu_VSlider_Create(menu, sliderscale+windowsize, sliderscale, sliderscale, windowsize, 0, -imagesize + windowsize, 0, MoveMenuV, UpdateMoveMenuV, child); Menu_Picture_Create(child, 0, 0, imagesize, imagesize, "lhfont.tga", NULL, NULL); Menu_SubMenu_Finish(child); Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-13 21:15:28 UTC (rev 674) +++ trunk/game/m_menucore.h 2006-03-13 21:28:38 UTC (rev 675) @@ -108,6 +108,7 @@ typedef struct Menu_SliderItem { Menu_Item super; + NUint axis; void *cookie; //for custom stuff Nfloat value;//set and used in the slider code From black at icculus.org Mon Mar 13 17:08:52 2006 From: black at icculus.org (black at icculus.org) Date: 13 Mar 2006 17:08:52 -0500 Subject: r676 - trunk/game Message-ID: <20060313220852.10101.qmail@icculus.org> Author: black Date: 2006-03-13 17:08:52 -0500 (Mon, 13 Mar 2006) New Revision: 676 Modified: trunk/game/m_menucore.c trunk/game/m_menucore.h Log: Renamed addpos to origin. Renamed DrawMenu to Draw. Added a Frame callback to Menu_Item and added support for it to Menu_SubMenu. Modified: trunk/game/m_menucore.c =================================================================== --- trunk/game/m_menucore.c 2006-03-13 21:28:38 UTC (rev 675) +++ trunk/game/m_menucore.c 2006-03-13 22:08:52 UTC (rev 676) @@ -152,13 +152,17 @@ //generic items +void Menu_Generic_Frame(Menu_Item *item, Menu_Inheritance *inh, Ndouble elaspedtime) +{ +} + void Menu_Generic_MouseMoveSelectable(Menu_Item *item, Menu_Inheritance *inh) { NUint j; for (j = 0; j < 2; j++) { - if (Input.mouse[j] < item->pos[j]+inh->addpos[j] || item->pos[j]+inh->addpos[j] + item->size[j] < Input.mouse[j] ) + if (Input.mouse[j] < item->pos[j]+inh->origin[j] || item->pos[j]+inh->origin[j] + item->size[j] < Input.mouse[j] ) return; } @@ -192,6 +196,7 @@ item = Mem_Alloc(Menu.menu_zone, bytes); + item->Frame = Menu_Generic_Frame; item->MouseMove = Menu_Generic_MouseMoveNonSelectable; item->KeyEvent = Menu_Generic_KeyPressIgnore; item->Destroy = Menu_Generic_Destroy; @@ -218,7 +223,7 @@ { R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); - R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString(item->text, 0, item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } void Menu_Text_DefaultUse (struct Menu_TextItem *item, void *cookie) { @@ -240,7 +245,7 @@ Menu_TextItem *it; it = (Menu_TextItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_TextItem)); - it->super.DrawMenu = Menu_Text_Draw; + it->super.Draw = Menu_Text_Draw; if (command != NULL) { it->super.MouseMove = Menu_Generic_MouseMoveSelectable; @@ -269,9 +274,9 @@ { R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetTexture(R.resource_font); - R_DrawString(item->text, 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString(item->text, 0, item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); if (item->super.parent->selecteditem == &item->super) - R_DrawString("_", 0, item->super.pos[0] + inh->addpos[0] + item->cursorpos*8, item->super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, 0); + R_DrawString("_", 0, item->super.pos[0] + inh->origin[0] + item->cursorpos*8, item->super.pos[1] + inh->origin[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, 0); } Nbool Menu_Edit_KeyPress (Menu_EditItem *item, UNUSED NUint mod, NUint sym, NUint character, Nbool downevent) { @@ -349,7 +354,7 @@ Menu_EditItem *it; it = (Menu_EditItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_EditItem)); - it->super.DrawMenu = Menu_Edit_Draw; + it->super.Draw = Menu_Edit_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Edit_KeyPress; it->super.size[0] = 8*strlen(text); @@ -378,7 +383,7 @@ { item->super.super.size[0]-=8; Menu_Edit_Draw(&item->super, inh); - R_DrawString("V", 0, item->super.super.pos[0] + item->super.super.size[0] + inh->addpos[0], item->super.super.pos[1] + inh->addpos[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.super.parent->selecteditem == &item->super.super); + R_DrawString("V", 0, item->super.super.pos[0] + item->super.super.size[0] + inh->origin[0], item->super.super.pos[1] + inh->origin[1], 8, 8, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.super.parent->selecteditem == &item->super.super); item->super.super.size[0]+=8; } @@ -474,7 +479,7 @@ Menu_ComboItem *it; it = (Menu_ComboItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_ComboItem)); - it->super.super.DrawMenu = Menu_Combo_Draw; + it->super.super.Draw = Menu_Combo_Draw; it->super.super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.super.KeyEvent = Menu_Combo_KeyPress; it->super.super.Destroy = Menu_Combo_Destroy; @@ -527,7 +532,7 @@ R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); R_SetColor(1, 1, 1, 1); R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); - R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); + R_DrawPic(item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], item->super.size[0], item->super.size[1]); } void Menu_Picture_DefaultUse (struct Menu_PictureItem *item, void *cookie) { @@ -551,7 +556,7 @@ Menu_PictureItem *it; it = (Menu_PictureItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_PictureItem)); - it->super.DrawMenu = Menu_Picture_Draw; + it->super.Draw = Menu_Picture_Draw; if (command != NULL) { it->super.MouseMove = Menu_Generic_MouseMoveSelectable; @@ -586,12 +591,12 @@ // R_SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // R_SetColor(1, 1, 1, 1); // R_SetTexture(Resource_IndexForName(item->imagename, RESOURCETYPE_TEXTURE, 0, 0)); -// R_DrawPic(item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->super.size[0], item->super.size[1]); +// R_DrawPic(item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], item->super.size[0], item->super.size[1]); if (Menu.grabs == &item->super) { { - item->value = Input.mouse[item->axis] - (item->super.pos[item->axis]+inh->addpos[item->axis] + item->scale*1.5); + item->value = Input.mouse[item->axis] - (item->super.pos[item->axis]+inh->origin[item->axis] + item->scale*1.5); if (item->value < 0) item->value = 0; if (item->value > item->super.size[item->axis] - item->scale*3) @@ -615,15 +620,15 @@ if (item->axis == 0) { - R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0] + item->scale + (item->super.size[0]-item->scale*3)*frac, item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("<", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString(">", 0, item->super.pos[0] + inh->addpos[0] - item->scale + (item->super.size[0]), item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("x", 0, item->super.pos[0] + inh->origin[0] + item->scale + (item->super.size[0]-item->scale*3)*frac, item->super.pos[1] + inh->origin[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("<", 0, item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString(">", 0, item->super.pos[0] + inh->origin[0] - item->scale + (item->super.size[0]), item->super.pos[1] + inh->origin[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } else { - R_DrawString("x", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] + item->scale + (item->super.size[1]-item->scale*3)*frac, item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("A", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); - R_DrawString("V", 0, item->super.pos[0] + inh->addpos[0], item->super.pos[1] + inh->addpos[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("x", 0, item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1] + item->scale + (item->super.size[1]-item->scale*3)*frac, item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("A", 0, item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1], item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); + R_DrawString("V", 0, item->super.pos[0] + inh->origin[0], item->super.pos[1] + inh->origin[1] - item->scale + (item->super.size[1]), item->scale, item->scale, Console_DefaultColorTable, Console_DefaultColorTableSize, item->super.parent->selecteditem == &item->super); } } Nbool Menu_Slider_KeyPress (Menu_SliderItem *item, UNUSED NUint mod, NUint sym, UNUSED NUint character, Nbool downevent) @@ -661,7 +666,7 @@ Menu_SliderItem *it; it = (Menu_SliderItem*)Menu_Generic_Create(parent, x, y, sizeof(Menu_SliderItem)); - it->super.DrawMenu = Menu_Slider_Draw; + it->super.Draw = Menu_Slider_Draw; it->super.MouseMove = Menu_Generic_MouseMoveSelectable; it->super.KeyEvent = Menu_Slider_KeyPress; @@ -693,93 +698,95 @@ +//submenus +void Menu_SubMenu_SetupInheritance(Menu_SubMenu *menu, Menu_Inheritance *base, Menu_Inheritance *local) +{ + NUint j; + for (j = 0; j < 2; j++) + { + NSint wmin, wmax; + wmin = base->origin[j] + menu->super.pos[j]; + wmax = wmin + menu->super.size[j]; + if (wmin < base->window.pos[j]) + wmin = base->window.pos[j]; + local->window.pos[j] = wmin; + if (wmax > base->window.pos[j] + base->window.size[j]) + wmax = base->window.pos[j] + base->window.size[j]; + local->window.size[j] = wmax-wmin; + local->origin[j] = menu->subwindow.pos[j] + wmin; + } +} - - - - -//submenus -void Menu_SubMenu_MouseMove(Menu_SubMenu *item, Menu_Inheritance *inh) +void Menu_SubMenu_MouseMove(Menu_SubMenu *menu, Menu_Inheritance *inh) { Menu_Item *subitem; Menu_Inheritance ninh; NUint j; - if (Menu.grabs == &item->super && item->dragable) + if (Menu.grabs == &menu->super && menu->dragable) { - item->super.pos[0] += Input.mouse[0] - item->dragmousepos[0]; - item->super.pos[1] += Input.mouse[1] - item->dragmousepos[1]; - item->dragmousepos[0] = Input.mouse[0]; - item->dragmousepos[1] = Input.mouse[1]; + menu->super.pos[0] += Input.mouse[0] - menu->dragmousepos[0]; + menu->super.pos[1] += Input.mouse[1] - menu->dragmousepos[1]; + menu->dragmousepos[0] = Input.mouse[0]; + menu->dragmousepos[1] = Input.mouse[1]; } - for (j = 0; j < 2; j++) + Menu_SubMenu_SetupInheritance(menu, inh, &ninh); + + // TODO: add a function pointinrect? + for( j = 0 ; j < 2 ; j++ ) { - NSint wmin, wmax; - - wmin = inh->addpos[j] + item->super.pos[j]; - wmax = wmin + item->super.size[j]; - if (inh->window.pos[j] > wmin) - wmin = inh->window.pos[j]; - if (inh->window.pos[j] + inh->window.size[j] < wmax) - wmax = inh->window.pos[j] + inh->window.size[j]; - - if (Input.mouse[j] < wmin || Input.mouse[j] > wmax) + if (Input.mouse[j] < ninh.window.pos[j] || ninh.origin[j] + ninh.window.size[j] < Input.mouse[j]) { return; } - - ninh.window.pos[j] = wmin; - ninh.window.size[j] = wmax-wmin; - - ninh.addpos[j] = inh->addpos[j] + item->subwindow.pos[j] + wmin; } + if (menu->super.parent) + menu->super.parent->selecteditem = &menu->super; //mouse is in us. - if (item->super.parent) - item->super.parent->selecteditem = &item->super; //mouse is in us. + menu->selecteditem = NULL; - item->selecteditem = NULL; - - for (subitem = item->subitems; subitem; subitem = subitem->next) + for (subitem = menu->subitems; subitem; subitem = subitem->next) subitem->MouseMove(subitem, &ninh); } -void Menu_SubMenu_Draw(Menu_SubMenu *item, Menu_Inheritance *inh) + +void Menu_SubMenu_Frame(Menu_SubMenu *menu, Menu_Inheritance *inh, Ndouble elapsedtime) { Menu_Item *subitem, *next; Menu_Inheritance ninh; - NUint j; - if (item->super.parent) + if (menu->super.parent) { - if (item->super.parent->selecteditem != &item->super) - item->selecteditem = NULL; + if (menu->super.parent->selecteditem != &menu->super) + menu->selecteditem = NULL; } - for (j = 0; j < 2; j++) + Menu_SubMenu_SetupInheritance(menu, inh, &ninh); + + for (subitem = menu->subitems; subitem; subitem = next) { - NSint wmin, wmax; - wmin = inh->addpos[j] + item->super.pos[j]; - wmax = wmin + item->super.size[j]; - if (wmin < inh->window.pos[j]) - wmin = inh->window.pos[j]; - ninh.window.pos[j] = wmin; - if (wmax > inh->window.pos[j] + inh->window.size[j]) - wmax = inh->window.pos[j] + inh->window.size[j]; - ninh.window.size[j] = wmax-wmin; - - ninh.addpos[j] = item->subwindow.pos[j] + wmin; + next = subitem->next;//this funkyness is so that we can unlink and kill things in the draw function (if the need arises). + subitem->Frame(subitem, &ninh, elapsedtime); } +} +void Menu_SubMenu_Draw(Menu_SubMenu *menu, Menu_Inheritance *inh) +{ + Menu_Item *subitem, *next; + Menu_Inheritance ninh; + Menu_SubMenu_SetupInheritance(menu, inh, &ninh); + R_SetScissor(ninh.window.pos[0], ninh.window.pos[1], ninh.window.size[0], ninh.window.size[1]); - for (subitem = item->subitems; subitem; subitem = next) + for (subitem = menu->subitems; subitem; subitem = next) { + // TODO: remove this since we only accept Frame to delete items, Draw should just draw them and don't do any management work like deleting our beloved items next = subitem->next;//this funkyness is so that we can unlink and kill things in the draw function (if the need arises). - subitem->DrawMenu(subitem, &ninh); + subitem->Draw(subitem, &ninh); } R_SetScissor(inh->window.pos[0], inh->window.pos[1], inh->window.size[0], inh->window.size[1]); @@ -867,7 +874,8 @@ } menu->super.MouseMove = Menu_SubMenu_MouseMove; - menu->super.DrawMenu = Menu_SubMenu_Draw; + menu->super.Frame = Menu_SubMenu_Frame; + menu->super.Draw = Menu_SubMenu_Draw; menu->super.KeyEvent = Menu_SubMenu_KeyEvent; menu->super.Destroy = Menu_SubMenu_Destroy; @@ -995,7 +1003,9 @@ Menu.rootmenu.selecteditem = NULL; Menu.rootmenu.super.MouseMove(&Menu.rootmenu, &inh); - Menu.rootmenu.super.DrawMenu(&Menu.rootmenu, &inh); + // FIXME: add real frametime support + Menu.rootmenu.super.Frame(&Menu.rootmenu, &inh, 0.0); + Menu.rootmenu.super.Draw(&Menu.rootmenu, &inh); } @@ -1171,7 +1181,8 @@ // init the root menu // FIXME: create the rootmenu using the normal submenu creation function instead? + Menu.rootmenu.super.Frame = Menu_SubMenu_Frame; Menu.rootmenu.super.MouseMove = Menu_SubMenu_MouseMove; - Menu.rootmenu.super.DrawMenu = Menu_SubMenu_Draw; + Menu.rootmenu.super.Draw = Menu_SubMenu_Draw; Menu.rootmenu.super.KeyEvent = Menu_SubMenu_KeyEvent; } Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-13 21:28:38 UTC (rev 675) +++ trunk/game/m_menucore.h 2006-03-13 22:08:52 UTC (rev 676) @@ -11,7 +11,7 @@ typedef struct Menu_Inheritance { - NSint addpos[2]; + NSint origin[2]; Menu_Rect window; } @@ -19,7 +19,9 @@ typedef struct Menu_Item { - void (*DrawMenu) (void *item, Menu_Inheritance *inheritance); + // pass an elapsedtime parameter to make animation-speed changes, etc. possible + void (*Frame) (void *item, Menu_Inheritance *inheritance, Ndouble elapsedtime); + void (*Draw) (void *item, Menu_Inheritance *inheritance); Nbool (*KeyEvent) (void *item, NUint mod, NUint sym, NUint character, Nbool downevent); void (*MouseMove) (void *item, Menu_Inheritance *inheritance); void (*Destroy) (void *item); From black at icculus.org Mon Mar 13 17:27:57 2006 From: black at icculus.org (black at icculus.org) Date: 13 Mar 2006 17:27:57 -0500 Subject: r677 - trunk/game Message-ID: <20060313222757.12411.qmail@icculus.org> Author: black Date: 2006-03-13 17:27:57 -0500 (Mon, 13 Mar 2006) New Revision: 677 Modified: trunk/game/m_menucore.h Log: Updated the member comment style (now I see them all). Modified: trunk/game/m_menucore.h =================================================================== --- trunk/game/m_menucore.h 2006-03-13 22:08:52 UTC (rev 676) +++ trunk/game/m_menucore.h 2006-03-13 22:27:57 UTC (rev 677) @@ -54,10 +54,13 @@ { Menu_Item super; - char *text; //what to display (warning: it's a pointer, isn't freed, and isn't copied) - void *cookie; //command is a misnomer, it should be used as a cookie for the text item + // what to display (warning: it's a pointer, isn't freed, and isn't copied) + char *text; + // command is a misnomer, it should be used as a cookie for the text item + void *cookie; - void (*UseItem) (struct Menu_TextItem *item, void *cookie); //called when the user uses (clicks) this item + // called when the user uses (clicks) this item + void (*UseItem) (struct Menu_TextItem *item, void *cookie); } Menu_TextItem; @@ -65,11 +68,16 @@ { Menu_Item super; - Nbool editable; //user may type into the control - char *text; //what it currently says - NUint cursorpos; //where the cursor is, set between 0 and strlen(text) - NSint scrollpos; //fixme - NUint maxchars; //0 for unlimited + // user may type into the control + Nbool editable; + // what it currently says + char *text; + // where the cursor is, set between 0 and strlen(text) + NUint cursorpos; + // FIXME: this was empty (for VC7 task window use uppercase&':' please :-/) + NSint scrollpos; + // 0 for unlimited + NUint maxchars; void (*ChangeEvent) (struct Menu_EditItem *item, char *newtext, void *cookie); } @@ -77,22 +85,28 @@ typedef struct Menu_ComboOption { - char *text; //the text of the item - NSint ident; //if you wish to assosiate an int key with the item. + // the text of the item + char *text; + // if you wish to assosiate an int key with the item. + NSint ident; struct Menu_ComboOption *next; } Menu_ComboOption; typedef struct Menu_ComboItem { - Menu_EditItem super; //this is one advantage of c++. + // TODO: use composition instead and initialize it properly with Edit_Create? + Menu_EditItem super; - struct Menu_ComboOption *options; //a list of the current options - struct Menu_ComboOption *selected; //set + // a list of the current options + struct Menu_ComboOption *options; + // set + struct Menu_ComboOption *selected; struct Menu_SubMenu *popup; - void (*ChangeEvent) (struct Menu_EditItem *item, char *newtext, NSint optionident, void *cookie); //we use the ChangeEvent of the text item to set our 'selected' value + // we use the ChangeEvent of the text item to set our 'selected' value + void (*ChangeEvent) (struct Menu_EditItem *item, char *newtext, NSint optionident, void *cookie); } Menu_ComboItem; @@ -101,9 +115,11 @@ Menu_Item super; char *imagename; - void *cookie; //console command when clicked + // console command when clicked + void *cookie; - void (*UseItem) (struct Menu_PictureItem *item, void *cookie); //called when the user uses (clicks) this item + // called when the user uses (clicks) this item + void (*UseItem) (struct Menu_PictureItem *item, void *cookie); } Menu_PictureItem; @@ -112,20 +128,28 @@ Menu_Item super; NUint axis; - void *cookie; //for custom stuff - Nfloat value;//set and used in the slider code + // for custom stuff + void *cookie; + // set and used in the slider code + Nfloat value; - Nfloat minv;//min value - Nfloat maxv;//max (can be inverted) + // min value + Nfloat minv; + // max (can be inverted) + Nfloat maxv; - Nfloat scale;//size of slider, in pixels. + // size of slider, in pixels + Nfloat scale; - //notification function - void (*SliderChanged) (struct Menu_SliderItem *slider, void *cookie); //the user just changed the slider->value - void (*SliderUpdate) (struct Menu_SliderItem *slider, void *cookie); //about to draw the slider's value, where you should feel free to update the value from external sources + // notification functions + // the user just changed the slider->value + void (*SliderChanged) (struct Menu_SliderItem *slider, void *cookie); + // about to draw the slider's value, where you should feel free to update the value from external sources + void (*SliderUpdate) (struct Menu_SliderItem *slider, void *cookie); - //internal - Nbool mousepressed; //adjust the slider with the mouse + // internal + // adjust the slider with the mouse + Nbool mousepressed; } Menu_SliderItem; @@ -151,7 +175,7 @@ -//Entry points central to the menu's workings +// entry points central to the menu's workings void Menu_Draw(void); void Menu_Frame(void); void Menu_Main(void); @@ -160,7 +184,7 @@ Nbool Menu_KeyEvent(NUint mod, NUint sym, NUint character, Nbool downevent); -//Entry points for using the menu in other systems +// entry points for using the menu in other systems Menu_SubMenu *Menu_SubMenu_Create(Menu_SubMenu *parent); Menu_SliderItem *Menu_VSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);//vertical scrolling bar Menu_SliderItem *Menu_HSlider_Create(Menu_SubMenu *parent, NSint x, NSint y, NUint w, NUint h, Nfloat minv, Nfloat maxv, Nfloat defaultv, void (*ChangeNotification)(Menu_SliderItem *item, void *cookie), void (*UpdateSlider)(Menu_SliderItem *item, void *cookie), void *cookie);//horizontal scrolling bar From lordhavoc at icculus.org Sun Mar 26 03:40:05 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 26 Mar 2006 03:40:05 -0500 Subject: r678 - trunk Message-ID: <20060326084005.26580.qmail@icculus.org> Author: lordhavoc Date: 2006-03-26 03:40:05 -0500 (Sun, 26 Mar 2006) New Revision: 678 Modified: trunk/matrixlib.c trunk/matrixlib.h Log: added Matrix4x4_CreateFromDoom3Joint function Modified: trunk/matrixlib.c =================================================================== --- trunk/matrixlib.c 2006-03-13 22:27:57 UTC (rev 677) +++ trunk/matrixlib.c 2006-03-26 08:40:05 UTC (rev 678) @@ -467,3 +467,14 @@ return (double)sqrt(in->m[0][0] * in->m[0][0] + in->m[0][1] * in->m[0][1] + in->m[0][2] * in->m[0][2]); } +// LordHavoc: I got this code from: +//http://www.doom3world.org/phpbb2/viewtopic.php?t=2884 +void Matrix4x4_CreateFromDoom3Joint(matrix4x4_t *m, const double *joint) +{ + double x = joint[3], y = joint[4], z = joint[5], w = 1.0 - VectorLength2(joint + 3); + w = w > 0.0 ? -sqrt(w) : 0.0; + m->m[0][0]= 1-2*((y*y)+(z*z)) ;m->m[0][1]= 2*((x*y)-(z*w)) ;m->m[0][2]= 2*((x*z)+(y*w)) ;m->m[0][3]=joint[0]; + m->m[1][0]= 2*((x*y)+(z*w)) ;m->m[1][1]= 1-2*((x*x)+(z*z)) ;m->m[1][2]= 2*((y*z)-(x*w)) ;m->m[1][3]=joint[1]; + m->m[2][0]= 2*((x*z)-(y*w)) ;m->m[2][1]= 2*((y*z)+(x*w)) ;m->m[2][2]= 1-2*((x*x)+(y*y)) ;m->m[2][3]=joint[2]; + m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]= 1; +} Modified: trunk/matrixlib.h =================================================================== --- trunk/matrixlib.h 2006-03-13 22:27:57 UTC (rev 677) +++ trunk/matrixlib.h 2006-03-26 08:40:05 UTC (rev 678) @@ -55,6 +55,8 @@ void Matrix4x4_CreateScale3(matrix4x4_t *out, double x, double y, double z); // creates a matrix for a quake entity void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale); +// creates a matrix from a doom3 joint +void Matrix4x4_CreateFromDoom3Joint(matrix4x4_t *m, const double *joint); // converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate void Matrix4x4_ToVectors(const matrix4x4_t *in, double vx[3], double vy[3], double vz[3], double t[3]); From lordhavoc at icculus.org Mon Mar 27 04:07:19 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:07:19 -0500 Subject: r679 - trunk Message-ID: <20060327090719.26271.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:07:18 -0500 (Mon, 27 Mar 2006) New Revision: 679 Modified: trunk/lhsound.c trunk/sound.c Log: fix a couple warnings Modified: trunk/lhsound.c =================================================================== --- trunk/lhsound.c 2006-03-26 08:40:05 UTC (rev 678) +++ trunk/lhsound.c 2006-03-27 09:07:18 UTC (rev 679) @@ -462,7 +462,7 @@ while (lhsound_state.numsamples > 0) { - int number = --lhsound_state.numsamples; + unsigned int number = --lhsound_state.numsamples; lhsoundDeleteSamples(1, &number); } lhsoundClearMemory(&lhsound_state, 0, sizeof(lhsound_state)); @@ -510,7 +510,7 @@ LHSOUNDASSERT(bufferlength == lhsound_state.mixbufferlength, LHSOUND_ERROR_INVALID_VALUE); LHSOUNDASSERT(stride != 0, LHSOUND_ERROR_INVALID_VALUE); lhsound_state.mixbeginstate = LHSOUND_FALSE; - + swaptest.s = 1; switch (format) { @@ -635,6 +635,6 @@ default: break; } - } + } } Modified: trunk/sound.c =================================================================== --- trunk/sound.c 2006-03-26 08:40:05 UTC (rev 678) +++ trunk/sound.c 2006-03-27 09:07:18 UTC (rev 679) @@ -199,8 +199,8 @@ SoundInfo info; int channelcount; int channel; - int samplenumber[SOUND_MAX_CHANNEL_COUNT]; - + unsigned int samplenumber[SOUND_MAX_CHANNEL_COUNT]; + if (!Sound_LoadWaveFile(r->name, &info, r->memzone)) { Console_Printf("Sound_Load: failed to load \"%s\" - error: %s\n", r->name, info.errormessage); @@ -212,7 +212,7 @@ // bind the sounds and load them for( channel = 0 ; channel < channelcount ; channel++ ) { - void *channelStart = (NUint8*) info.data + channel * info.bytespersample; + void *channelStart = (NUint8*) info.data + channel * info.bytespersample; lhsoundBindSample(samplenumber[channel]); lhsoundSample(info.length, info.lhsoundformat, info.channels, channelStart); From lordhavoc at icculus.org Mon Mar 27 04:07:36 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:07:36 -0500 Subject: r680 - trunk Message-ID: <20060327090736.26323.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:07:36 -0500 (Mon, 27 Mar 2006) New Revision: 680 Modified: trunk/matrixlib.c trunk/matrixlib.h Log: changed parameters to Matrix4x4_CreateFromDoom3Joint Modified: trunk/matrixlib.c =================================================================== --- trunk/matrixlib.c 2006-03-27 09:07:18 UTC (rev 679) +++ trunk/matrixlib.c 2006-03-27 09:07:36 UTC (rev 680) @@ -469,12 +469,12 @@ // LordHavoc: I got this code from: //http://www.doom3world.org/phpbb2/viewtopic.php?t=2884 -void Matrix4x4_CreateFromDoom3Joint(matrix4x4_t *m, const double *joint) +void Matrix4x4_CreateFromDoom3Joint(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z) { - double x = joint[3], y = joint[4], z = joint[5], w = 1.0 - VectorLength2(joint + 3); + double w = 1.0 - (x*x+y*y+z*z); w = w > 0.0 ? -sqrt(w) : 0.0; - m->m[0][0]= 1-2*((y*y)+(z*z)) ;m->m[0][1]= 2*((x*y)-(z*w)) ;m->m[0][2]= 2*((x*z)+(y*w)) ;m->m[0][3]=joint[0]; - m->m[1][0]= 2*((x*y)+(z*w)) ;m->m[1][1]= 1-2*((x*x)+(z*z)) ;m->m[1][2]= 2*((y*z)-(x*w)) ;m->m[1][3]=joint[1]; - m->m[2][0]= 2*((x*z)-(y*w)) ;m->m[2][1]= 2*((y*z)+(x*w)) ;m->m[2][2]= 1-2*((x*x)+(y*y)) ;m->m[2][3]=joint[2]; - m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]= 1; + m->m[0][0]= 1-2*((y*y)+(z*z)) ;m->m[0][1]= 2*((x*y)-(z*w)) ;m->m[0][2]= 2*((x*z)+(y*w)) ;m->m[0][3]=ox; + m->m[1][0]= 2*((x*y)+(z*w)) ;m->m[1][1]= 1-2*((x*x)+(z*z)) ;m->m[1][2]= 2*((y*z)-(x*w)) ;m->m[1][3]=oy; + m->m[2][0]= 2*((x*z)-(y*w)) ;m->m[2][1]= 2*((y*z)+(x*w)) ;m->m[2][2]= 1-2*((x*x)+(y*y)) ;m->m[2][3]=oz; + m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]= 1; } Modified: trunk/matrixlib.h =================================================================== --- trunk/matrixlib.h 2006-03-27 09:07:18 UTC (rev 679) +++ trunk/matrixlib.h 2006-03-27 09:07:36 UTC (rev 680) @@ -56,7 +56,7 @@ // creates a matrix for a quake entity void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale); // creates a matrix from a doom3 joint -void Matrix4x4_CreateFromDoom3Joint(matrix4x4_t *m, const double *joint); +void Matrix4x4_CreateFromDoom3Joint(matrix4x4_t *m, double ox, double oy, double oz, double qx, double qy, double qz); // converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate void Matrix4x4_ToVectors(const matrix4x4_t *in, double vx[3], double vy[3], double vz[3], double t[3]); From lordhavoc at icculus.org Mon Mar 27 04:08:46 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:08:46 -0500 Subject: r681 - trunk Message-ID: <20060327090846.26551.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:08:46 -0500 (Mon, 27 Mar 2006) New Revision: 681 Modified: trunk/nstring.c trunk/nstring.h Log: added a StringKeys system which uses the minimum amount of memory to store a database of key/value pairs, NUL separated (so anything but NUL characters are allowed in them, unlike infostrings) added some String_ToDouble/Vector/etc functions for convenience Modified: trunk/nstring.c =================================================================== --- trunk/nstring.c 2006-03-27 09:07:36 UTC (rev 680) +++ trunk/nstring.c 2006-03-27 09:08:46 UTC (rev 681) @@ -353,5 +353,154 @@ return out; } +void StringKeys_Init(NStringKeys *s, Mem_Zone *zone, NUint32 initialsize) +{ + memset(s, 0, sizeof(*s)); + if (initialsize) + { + s->maxsize = initialsize; + s->keys = Mem_Alloc(zone, initialsize); + } +} +void StringKeys_FreeKeys(NStringKeys *s) +{ + s->cursize = 0; + s->maxsize = 0; + if (s->keys) + Mem_Free(&s->keys); +} +void StringKeys_Empty(NStringKeys *s) +{ + s->cursize = 0; +} + +void StringKeys_Clone(NStringKeys *dest, Mem_Zone *zone, NStringKeys *src) +{ + StringKeys_Init(dest, zone, src->cursize); + memcpy(dest->keys, src->keys, src->cursize); +} + +void StringKeys_SetKey(NStringKeys *s, Mem_Zone *zone, const char *key, const char *value) +{ + Nsize keysize; + Nsize valuesize; + Nsize l; + char *t, *k, *v; + if (!key || !key[0]) + return; + keysize = strlen(key) + 1; + valuesize = strlen(value) + 1; + if (s->maxsize < s->cursize + keysize + valuesize) + { + s->maxsize *= 2; + if (s->maxsize < 128) + s->maxsize = 128; + Mem_ReAlloc(zone, &s->keys, s->maxsize); + } + t = s->keys; + while (t < s->keys + s->cursize) + { + k = t; + t += strlen(t) + 1; + v = t; + t += strlen(t) + 1; + if (!String_Compare(k, key)) + { + if (value && value[0]) + { + // move the text that follows and replace the key + l = valuesize - (strlen(v) + 1); + memmove(t + l, t, (s->keys + s->cursize) - t); + s->cursize += l; + memcpy(k, key, keysize); + memcpy(k + keysize, value, valuesize); + } + else + { + // remove the key + l = 0 - (strlen(k) + 1) - (strlen(v) + 1); + memmove(t + l, t, (s->keys + s->cursize) - t); + s->cursize += l; + } + return; + } + } + // add the key + s->cursize += keysize + valuesize; + memcpy(t, key, keysize); + memcpy(t + keysize, value, valuesize); +} + +const char *StringKeys_GetValue(NStringKeys *s, const char *key) +{ + char *t; + t = s->keys; + while (t < s->keys + s->cursize) + { + if (!String_Compare(t, key)) + return t + strlen(t) + 1; + t += strlen(t) + 1; + t += strlen(t) + 1; + } + return NULL; +} + +Nbool StringKeys_GetByNumber(NStringKeys *s, NUint32 index, const char **key, const char **value) +{ + char *t; + t = s->keys; + while (t < s->keys + s->cursize) + { + if (index-- == 0) + { + if (key) + *key = t; + if (value) + *value = t + strlen(t) + 1; + return true; + } + t += strlen(t) + 1; + t += strlen(t) + 1; + } + return false; +} + +NSint32 String_ToInteger(const char *s) +{ + if (!s) + return 0; + while (*s && *s <= ' ') + s++; + return atoi(s); +} + +double String_ToDouble(const char *s) +{ + if (!s) + return 0; + while (*s && *s <= ' ') + s++; + return atof(s); +} + +NUint32 String_ToVector(const char *s, Nvec *v, NUint32 maxcomponents) +{ + NUint32 c; + for (c = 0;c < maxcomponents;c++) + v[c] = 0; + if (!s) + return 0; + for (c = 0;c < maxcomponents;c++) + { + while (*s && *s <= ' ') + s++; + if (!*s) + break; + v[c] = atof(s); + while (*s > ' ') + s++; + } + return c; +} Modified: trunk/nstring.h =================================================================== --- trunk/nstring.h 2006-03-27 09:07:36 UTC (rev 680) +++ trunk/nstring.h 2006-03-27 09:08:46 UTC (rev 681) @@ -44,4 +44,24 @@ #define String_SetCharacter(s, zone, c ) _String_SetCharacter((s), (zone), (c), __FILE__, __LINE__) #define String_Substring(s, zone, t, position, length) _String_Substring((s), (zone), (t),(position), (length), __FILE__, __LINE__) +typedef struct NStringKeys +{ + Nsize cursize; + Nsize maxsize; + char *keys; +} +NStringKeys; + +void StringKeys_Init(NStringKeys *s, Mem_Zone *zone, NUint32 initialsize); +void StringKeys_FreeKeys(NStringKeys *s); +void StringKeys_Empty(NStringKeys *s); +void StringKeys_Clone(NStringKeys *dest, Mem_Zone *zone, NStringKeys *src); +void StringKeys_SetKey(NStringKeys *s, Mem_Zone *zone, const char *key, const char *value); +const char *StringKeys_GetValue(NStringKeys *s, const char *key); +Nbool StringKeys_GetByNumber(NStringKeys *s, NUint32 index, const char **key, const char **value); + +NSint32 String_ToInteger(const char *s); +double String_ToDouble(const char *s); +NUint32 String_ToVector(const char *s, Nvec *v, NUint32 maxcomponents); + #endif From lordhavoc at icculus.org Mon Mar 27 04:13:17 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:13:17 -0500 Subject: r682 - trunk Message-ID: <20060327091317.27455.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:13:17 -0500 (Mon, 27 Mar 2006) New Revision: 682 Modified: trunk/systemfallbacks.c Log: fix a warning Modified: trunk/systemfallbacks.c =================================================================== --- trunk/systemfallbacks.c 2006-03-27 09:08:46 UTC (rev 681) +++ trunk/systemfallbacks.c 2006-03-27 09:13:17 UTC (rev 682) @@ -57,4 +57,4 @@ return ret; } -#endif \ No newline at end of file +#endif From lordhavoc at icculus.org Mon Mar 27 04:14:03 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:14:03 -0500 Subject: r683 - trunk Message-ID: <20060327091403.27615.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:14:03 -0500 (Mon, 27 Mar 2006) New Revision: 683 Modified: trunk/r_main.c Log: fix bugs with loc_ values for uniforms (it was checking if they were not 0, it should be checking if they are >= 0), and moved eyeorigin calculation to R_SetEntity rather than light interaction related Modified: trunk/r_main.c =================================================================== --- trunk/r_main.c 2006-03-27 09:13:17 UTC (rev 682) +++ trunk/r_main.c 2006-03-27 09:14:03 UTC (rev 683) @@ -324,15 +324,15 @@ s->loc_Texture_FogMask = qglGetUniformLocationARB(s->programobject, "Texture_FogMask"); // set static uniforms - if (s->loc_Texture_Normal) + if (s->loc_Texture_Normal >= 0) qglUniform1iARB(s->loc_Texture_Normal, 0); - if (s->loc_Texture_Color) + if (s->loc_Texture_Color >= 0) qglUniform1iARB(s->loc_Texture_Color, 1); - if (s->loc_Texture_Gloss) + if (s->loc_Texture_Gloss >= 0) qglUniform1iARB(s->loc_Texture_Gloss, 2); - if (s->loc_Texture_Cube) + if (s->loc_Texture_Cube >= 0) qglUniform1iARB(s->loc_Texture_Cube, 3); - if (s->loc_Texture_FogMask) + if (s->loc_Texture_FogMask >= 0) qglUniform1iARB(s->loc_Texture_FogMask, 4); R_CheckError(); @@ -353,6 +353,7 @@ NUint32 i; if (R.active) return; + memset(&R, 0, sizeof(R)); R.active = true; // start out paranoid until the first frame @@ -405,6 +406,7 @@ R_CheckError(); R.active = false; Mem_FreeZone(&R.zone); + memset(&R, 0, sizeof(R)); } void R_Screenshot (void) @@ -1304,7 +1306,6 @@ // (needed for per-vertex tangentspace transforms) Matrix4x4_Transform(&R.worldtoentity, R.lightorigin, R.entitylightorigin4f); R.entitylightorigin4f[3] = -1; // for DotProduct4 with planes - Matrix4x4_Transform(&R.worldtoentity, R.eyeorigin, R.entityeyeorigin); // calculate entity to light matrix for cubemap filter and attenuation Matrix4x4_Concat(&R.entitytolight, &R.worldtolight, &R.entitytoworld); Matrix4x4_Concat(&R.lighttoentity, &R.lighttoworld, &R.worldtoentity); @@ -1366,6 +1367,8 @@ // derived properties Matrix4x4_Invert_Simple(&R.worldtoentity, &R.entitytoworld); + Matrix4x4_Transform(&R.worldtoentity, R.eyeorigin, R.entityeyeorigin); + R_UpdateEntityLightInteraction(); } @@ -2165,32 +2168,28 @@ s = R.shader_light + perm; qglUseProgramObjectARB(s->programobject); - if (s->loc_LightPosition) + if (s->loc_LightPosition >= 0) qglUniform3fARB(s->loc_LightPosition, R.entitylightorigin4f[0], R.entitylightorigin4f[1], R.entitylightorigin4f[2]); - if (s->loc_EyePosition) + if (s->loc_EyePosition >= 0) qglUniform3fARB(s->loc_EyePosition, R.entityeyeorigin[0], R.entityeyeorigin[1], R.entityeyeorigin[2]); - if (s->loc_LightColor) + if (s->loc_LightColor >= 0) qglUniform3fARB(s->loc_LightColor, R.lightcolor[0], R.lightcolor[1], R.lightcolor[2]); - if (s->loc_OffsetMapping_Scale) + if (s->loc_OffsetMapping_Scale >= 0) qglUniform1fARB(s->loc_OffsetMapping_Scale, material->offsetmapping_scale); - if (s->loc_OffsetMapping_Bias) + if (s->loc_OffsetMapping_Bias >= 0) qglUniform1fARB(s->loc_OffsetMapping_Scale, material->offsetmapping_bias); - if (s->loc_SpecularPower) + if (s->loc_SpecularPower >= 0) qglUniform1fARB(s->loc_SpecularPower, material->specularpower); - if (s->loc_FogRangeRecip) + if (s->loc_FogRangeRecip >= 0) qglUniform1fARB(s->loc_FogRangeRecip, R.fog_rangerecip); - if (s->loc_AmbientScale) + if (s->loc_AmbientScale >= 0) qglUniform1fARB(s->loc_AmbientScale, ambientintensity); - if (s->loc_DiffuseScale) + if (s->loc_DiffuseScale >= 0) qglUniform1fARB(s->loc_DiffuseScale, diffuseintensity); - if (s->loc_SpecularScale) + if (s->loc_SpecularScale >= 0) qglUniform1fARB(s->loc_SpecularScale, specularintensity); R_DrawTriangles(0, mesh->numvertices, mesh->numtriangles, mesh->element3i); - // LordHavoc: FIXME: HACK HACK HACK: NASTY trick to stop a lockup in nvidia 66.29 driver - qglUseProgramObjectARB(0); - qglBegin(GL_TRIANGLES); - qglEnd(); R_CheckError(); break; case R_DRAWMODE_LIT_FINISH: From lordhavoc at icculus.org Mon Mar 27 04:14:49 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:14:49 -0500 Subject: r684 - trunk/base/maps Message-ID: <20060327091449.27761.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:14:49 -0500 (Mon, 27 Mar 2006) New Revision: 684 Modified: trunk/base/maps/test.ent Log: make sun bigger Modified: trunk/base/maps/test.ent =================================================================== --- trunk/base/maps/test.ent 2006-03-27 09:14:03 UTC (rev 683) +++ trunk/base/maps/test.ent 2006-03-27 09:14:49 UTC (rev 684) @@ -10,8 +10,8 @@ { "light" "5000" "color" "1 1 1" - "origin" "-5000 0 10000" - "scale" "40000 40000 40000" + "origin" "-5000 0 40000" + "scale" "1000000 1000000 1000000" "classname" "light" } { From lordhavoc at icculus.org Mon Mar 27 04:16:28 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 04:16:28 -0500 Subject: r685 - in trunk: . base/gamedefs game Message-ID: <20060327091628.28116.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 04:16:27 -0500 (Mon, 27 Mar 2006) New Revision: 685 Added: trunk/modelanim.c trunk/modelanim.h Modified: trunk/Makefile trunk/base/gamedefs/entities.csv trunk/game/g_entity.c trunk/game/g_entity.h trunk/game/g_entityclass.c trunk/game/g_main.c trunk/game/g_main.h trunk/game/g_network.c trunk/game/g_packetbuffer.c trunk/game/g_packetbuffer.h trunk/game/g_render.c trunk/game/g_world.c trunk/mathlib.h trunk/model.c trunk/model.h trunk/resource.c trunk/resource.h trunk/system.c trunk/todo Log: some preparation work toward physics and animations Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/Makefile 2006-03-27 09:16:27 UTC (rev 685) @@ -25,7 +25,7 @@ ##### Common variables ##### GAMEOBJECTS= game/g_main.o game/g_render.o game/g_audio.o game/g_network.o game/g_packetbuffer.o game/g_util.o game/particle.o game/g_rain.o game/g_explosion.o game/g_commands.o game/g_entity.o game/g_entityclass.o game/g_world.o game/m_menucore.o -ENGINEOBJECTS= polygon.o crc.o hash.o system.o console.o collision.o util.o nmemory.o nstring.o nfile.o matrixlib.o resource.o material.o model.o sound.o texture.o video.o dwmesh.o r_dyngl.o r_dynglstubs.o r_main.o fs/dir.o fs/dir_posix.o fs/fs.o fs/pak.o fs/zip.o fs/rw_ops.o s_main.o lhnet.o shell.o shell_lang.o cvar.o lhsound.o systemfallbacks.o +ENGINEOBJECTS= polygon.o crc.o hash.o system.o console.o collision.o util.o nmemory.o nstring.o nfile.o matrixlib.o resource.o material.o model.o modelanim.o sound.o texture.o video.o dwmesh.o r_dyngl.o r_dynglstubs.o r_main.o fs/dir.o fs/dir_posix.o fs/fs.o fs/pak.o fs/zip.o fs/rw_ops.o s_main.o lhnet.o shell.o shell_lang.o cvar.o lhsound.o systemfallbacks.o OBJECTS = $(GAMEOBJECTS) $(ENGINEOBJECTS) CC=gcc Modified: trunk/base/gamedefs/entities.csv =================================================================== --- trunk/base/gamedefs/entities.csv 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/base/gamedefs/entities.csv 2006-03-27 09:16:27 UTC (rev 685) @@ -1,56 +1,66 @@ -CodeName ParentCodeName EnglishName Class Model Mass Health Heal NoRemove I0Q I0R I0C I0A I0AR I0B I1Q I1R I1C I1A I1AR I1B I2Q I2R I2C I2A I2AR I2B I3Q I3R I3C I3A I3AR I3B I4Q I4R I4C I4A I4AR I4B I5Q I5R I5C I5A I5AR I5B I6Q I6R I6C I6A I6AR I6B I7Q I7R I7C I7A I7AR I7B I8Q I8R I8C I8A I8AR I8B I9Q I9R I9C I9A I9AR I9B AmmoMax AmmoRegen Projectile SemiRefire AutoRefire Physics StepHeight JumpVelocity Speed TopSpeed Acceleration Friction StopSpeed AirSpeed AirAcceleration AirFriction AirStopSpeed HoverThrust HoverAltitude Cloaking JumpFlight CrouchShield CrouchTurret LifeTime ImpactDelay FleshDamage ArmorDamage Force DamageRadius Shake ShakeRadius IdleAnim IdleFPS -light Light light -model Model model default -model_sky Sky Model model_sky default -room Room room -infantry Infantry infantry infantry/infantry 90 200 10 1 weaponmachinegun 400 weapon 1 weaponpistol 60 pistol 1 weaponhandgrenade grenade1 1 weaponhandgrenade grenade2 1 weaponhandgrenade grenade3 infantry 0.3 4 5 10 2 10 20 0.02 0.1 0 -infscout Scout infantry infantry/scout 90 200 10 1 weaponplasmarifle 50 weapon 1 weaponpistol 60 pistol 1 weaponhandgrenade grenade1 1 weaponhandgrenade grenade2 1 weaponhandgrenade grenade3 infantry 0.3 4 5 10 2 10 20 0.02 0.1 0 TRUE -infhellion Hellion infantry infantry/hellion 90 200 10 1 weaponmachinegun 400 weapon 1 weaponpistol 60 pistol 1 weaponhandgrenade grenade1 1 weaponhandgrenade grenade2 1 weaponhandgrenade grenade3 infantry 0.3 8 6 10 2 10 20 1 0.03 1 TRUE -infmarauder Marauder infantry infantry/marauder 200 1000 40 1 weaponminigun 400 weapon 1 weaponpistol 60 pistol 1 weaponhandgrenade grenade1 1 weaponhandgrenade grenade2 1 weaponhandgrenade grenade3 1 weaponhandgrenade grenade4 1 weaponhandgrenade grenade5 infantry 0.3 6 5 10 2 10 20 0.2 0.03 0 TRUE -infgranite Granite infantry infantry/granite 400 2000 80 1 weaponplasmacannon 30 10 weapon infantry 0.3 12 4 10 2 10 20 0.01 0.03 0 TRUE -vehapc APC vehicle_apc vehicle/apc 3000 2000 50 weapon hover 0 0 0.2 1 20 0 0.01 5 20 0.5 -vehtankrailgun Railgun Hover Tank vehicle_tank vehicle/tankrailgun 3000 2000 50 1 weapontankrailgun 10 1 weapon hover 0 0 0.2 1 20 0 0.01 5 20 0.5 -vehdropship Drop Ship vehicle_dropship vehicle/dropship 2000 2000 50 weapon vtol 0 0 0.5 2 40 1 0.01 5 -turretrailgun Railgun Turret turret turret/turretrail 1000 3000 150 1 weaponturretrailgun 2 2 weapon default -turretvulcan Vulcan Turret turret turret/turretvulcan 1000 3000 150 1 weaponturretvulcan 20 20 weapon default -turretartillery Artillery Turret turret turret/turretartillery 1000 3000 150 1 weaponturretartillery 1 0.2 weapon default -spawninfantry Infantry Spawn Pad spawnpad spawn/infantry 500 500 25 TRUE 1 1 infantry -spawninfscout Scout Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 1 0.1 infscout -spawninfhellion Hellion Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 1 0.1 infhellion -spawninfmarauder Marauder Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 1 0.1 infmarauder -spawninfgranite Granite Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 1 0.1 infgranite -spawnvehapc APC Spawn Pad vehiclepad spawn/vehicle 10000 2000 100 TRUE 1 0.02 vehapc -spawnvehtankrailgun Railgun Hover Tank Spawn Pad vehiclepad spawn/vehicle 10000 2000 100 TRUE 1 0.04 vehtankrailgun -spawnvehdropship Drop Ship Spawn Pad vehiclepad spawn/vehicle 10000 2000 100 TRUE 1 0.02 vehdropship -spawnturretrailgun Railgun Turret Spawn Pad vehiclepad spawn/turret 10000 2000 100 TRUE 1 0.02 turretrailgun -spawnturretvulcan Vulcan Turret Spawn Pad vehiclepad spawn/turret 10000 2000 100 TRUE 1 0.02 turretvulcan -spawnturretartillery Artillery Turret Spawn Pad vehiclepad spawn/turret 10000 2000 100 TRUE 1 0.02 turretartillery -weaponhandgrenade Hand Grenade weapon weapon/handgrenade/body 0.2 1 projhandgrenade 0.5 0.5 -weaponpistol Pistol weapon weapon/pistol/body 1 60 projpistol 0.2 0.5 -weaponmachinegun Machinegun weapon weapon/machinegun/body 5 400 projmachinegun 0.06 0.13 -weaponminigun Minigun weapon weapon/minigun/body 20 1200 projminigun 0.05 0.05 -weaponsniperrifle Sniper Rifle weapon weapon/sniperrifle/body 4 25 projsniperrifle 0.5 1 -weaponrocketlauncher Rocket Launcher weapon weapon/rocketlauncher/body 10 20 projrocketlauncher 0.3 0.3 -weaponplasmacannon Plasma Cannon weapon weapon/plasmacannon/body 50 30 10 projplasmacannon 1 1 -weapontankrailgun Railgun weapon weapon/tankrailgun/body 50 10 2 projtankrailgun 1 1 -weaponturretrailgun Railgun weapon weapon/turretrailgun/body 50 2 1 projturretrailgun 1 1 -weaponturretvulcan Vulcan Cannon weapon weapon/turretvulcan/body 200 20 20 projturretvulcan 0.06 0.06 -weaponturretartillery Artillery Cannon weapon weapon/turretartillery/body 200 1 0.2 projturretartillery 5 5 -projhandgrenade Live Hand Grenade projectile weapon/handgrenade/projectile 0.2 default 10 3 4 -projpistol Pistol Bullet projectile weapon/pistol/projectile 0 default 1300 60 0 -projmachinegun Machinegun Bullet projectile weapon/machinegun/projectile 0 default 800 60 0 -projminigun Minigun Bullet projectile weapon/minigun/projectile 0 default 800 60 0 -projplasmacannon Plasma Cannon Ball projectile weapon/plasmacannon/projectile 0 default 10 0 -projtankrailgun Railgun Bolt projectile weapon/tankrailgun/projectile 0.5 default 60 0 -projturretrailgun Railgun Bolt projectile weapon/turretrailgun/projectile 0.1 default 60 0 -projturretvulcan Vulcan Turret Bullet projectile weapon/turretvulcan/projectile 0.01 default 60 0 -projturretartillery Artillery Cannon Shell projectile weapon/turretartillery/projectile 5 default 60 2 -expprojhandgrenade Hand Grenade Explosion explosion weapon/handgrenade/projectileexplosion 400 100 400 10 2 30 -expprojpistol Pistol Bullet Impact explosion weapon/pistol/projectileexplosion 50 30 0.1 0.01 0 0 -expprojmachinegun Machinegun Bullet Impact explosion weapon/machinegun/projectileexplosion 30 15 0.05 0.01 0 0 -expprojminigun Minigun Bullet Impact explosion weapon/minigun/projectileexplosion 30 15 0.05 0.01 0 0 -expprojplasmacannon Plasma Cannon Shell Explosion explosion weapon/plasmacannon/projectileexplosion 150 400 10 2 0 0 -expprojtankrailgun Railgun Bolt Impact explosion weapon/tankrailgun/projectileexplosion 200 900 50 0.5 1 10 -expprojturretrailgun Railgun Bolt Impact explosion weapon/turretrailgun/projectileexplosion 200 900 50 0.5 1 10 -expprojturretvulcan Vulcan Turret Bullet Impact explosion weapon/turretvulcan/projectileexplosion 20 30 1 0.01 0 0 -expprojturretartillery Artillery Cannon Shell Explosion explosion weapon/turretartillery/projectileexplosion 200 400 200 10 2 30 +CodeName ParentCodeName EnglishName Class Model Mass Health Heal NoRemove Respawn I0C I0B I1C I1B I2C I2B I3C I3B I4C I4B I5C I5B I6C I6B I7C I7B I8C I8B I9C I9B AmmoMax AmmoRegen Projectile Shots Spread SemiRefire AutoRefire Physics StepHeight JumpVelocity Speed TopSpeed Acceleration Friction StopSpeed AirSpeed AirAcceleration AirFriction AirStopSpeed HoverThrust HoverAltitude Cloaking JumpFlight CrouchShield CrouchTurret LifeTime ImpactDelay FleshDamage ArmorDamage Force DamageRadius Shake ShakeRadius IdleAnim IdleFPS +light Light light +model Model model default +model_sky Sky Model model_sky default +room Room room +infantry Infantry infantry infantry/infantry 90 200 10 itemmachinegun weapon itempistol pistol itemhandgrenade grenade1 itemhandgrenade grenade2 itemhandgrenade grenade3 infantry 0.3 4 5 10 2 10 20 0.02 0.1 0 +infscout Scout infantry infantry/scout 90 200 10 itemsniperrifle weapon itempistol pistol itemhandgrenade grenade1 itemhandgrenade grenade2 itemhandgrenade grenade3 infantry 0.3 4 5 10 2 10 20 0.02 0.1 0 TRUE +infhellion Hellion infantry infantry/hellion 90 200 10 itemmachinegun weapon itempistol pistol itemhandgrenade grenade1 itemhandgrenade grenade2 itemhandgrenade grenade3 infantry 0.3 8 6 10 2 10 20 1 0.03 1 TRUE +infmarauder Marauder infantry infantry/marauder 200 1000 40 itemminigun weapon itempistol pistol itemhandgrenade grenade1 itemhandgrenade grenade2 itemhandgrenade grenade3 itemhandgrenade grenade4 itemhandgrenade grenade5 infantry 0.3 6 5 10 2 10 20 0.2 0.03 0 TRUE +infgranite Granite infantry infantry/granite 400 2000 80 itemplasmacannon weapon infantry 0.3 12 4 10 2 10 20 0.01 0.03 0 TRUE +vehapc APC vehicle_apc vehicle/apc 3000 2000 50 weapon hover 0 0 0.2 1 20 0 0.01 5 20 0.5 +vehtankrailgun Railgun Hover Tank vehicle_tank vehicle/tankrailgun 3000 2000 50 weapontankrailgun weapon hover 0 0 0.2 1 20 0 0.01 5 20 0.5 +vehdropship Drop Ship vehicle_dropship vehicle/dropship 2000 2000 50 weapon vtol 0 0 0.5 2 40 1 0.01 5 +turretrailgun Railgun Turret turret turret/turretrail 1000 3000 150 weaponturretrailgun weapon default +turretvulcan Vulcan Turret turret turret/turretvulcan 1000 3000 150 weaponturretvulcan weapon default +turretartillery Artillery Turret turret turret/turretartillery 1000 3000 150 weaponturretartillery weapon default +spawninfantry Infantry Spawn Pad spawnpad spawn/infantry 500 500 25 TRUE 1 infantry spawn +spawninfscout Scout Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 10 infscout spawn +spawninfhellion Hellion Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 10 infhellion spawn +spawninfmarauder Marauder Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 10 infmarauder spawn +spawninfgranite Granite Spawn Pad spawnpad spawn/infantry 2000 1000 50 TRUE 10 infgranite spawn +spawnvehapc APC Spawn Pad vehiclepad spawn/vehicle 10000 2000 100 TRUE 50 vehapc spawn +spawnvehtankrailgun Railgun Hover Tank Spawn Pad vehiclepad spawn/vehicle 10000 2000 100 TRUE 50 vehtankrailgun spawn +spawnvehdropship Drop Ship Spawn Pad vehiclepad spawn/vehicle 10000 2000 100 TRUE 50 vehdropship spawn +spawnturretrailgun Railgun Turret Spawn Pad vehiclepad spawn/turret 10000 2000 100 TRUE 50 turretrailgun spawn +spawnturretvulcan Vulcan Turret Spawn Pad vehiclepad spawn/turret 10000 2000 100 TRUE 50 turretvulcan spawn +spawnturretartillery Artillery Turret Spawn Pad vehiclepad spawn/turret 10000 2000 100 TRUE 50 turretartillery spawn +itemhandgrenade Hand Grenade item weapon/handgrenade/body 0.2 projhandgrenade 1 0.1 0.5 0.5 +itempistol Pistol item weapon/pistol/body 1 60 projpistol 1 0.01 0.2 0.5 +itemmachinegun Machinegun item weapon/machinegun/body 5 400 projmachinegun 1 0.01 0.06 0.13 +itemshotgun Flechette Shotgun item weapon/shotgun/body 5 50 projshotgun 8 0.03 0.2 0.5 +itemminigun Minigun item weapon/minigun/body 20 1200 projminigun 1 0.02 0.05 0.05 +itemsniperrifle Sniper Rifle item weapon/sniperrifle/body 4 25 projsniperrifle 1 0.0001 0.5 1 +itemgrenadelauncher Grenade Launcher item weapon/grenadelauncher/body 3 50 projgrenadelauncher 1 0.02 0.5 0.5 +itemrocketlauncher Rocket Launcher item weapon/rocketlauncher/body 10 20 projrocketlauncher 1 0.001 0.3 0.3 +itemplasmacannon Plasma Cannon item weapon/plasmacannon/body 50 30 10 projplasmacannon 1 0.01 1 1 +weapontankrailgun Railgun weapon weapon/tankrailgun/body 50 10 2 projtankrailgun 1 0.0001 1 1 +weaponturretrailgun Railgun weapon weapon/turretrailgun/body 50 2 1 projturretrailgun 1 0.01 1 1 +weaponturretvulcan Vulcan Cannon weapon weapon/turretvulcan/body 200 20 20 projturretvulcan 1 0.03 0.06 0.06 +weaponturretartillery Artillery Cannon weapon weapon/turretartillery/body 200 1 0.2 projturretartillery 1 0.01 5 5 +projhandgrenade Live Hand Grenade projectile weapon/handgrenade/projectile 0.2 default 10 1 0.1 3 4 +projpistol Pistol Bullet projectile weapon/pistol/projectile 0.01 default 1300 1 0.1 60 0 +projmachinegun Machinegun Bullet projectile weapon/machinegun/projectile 0.005 default 800 1 0.1 60 0 +projshotgun Shotgun Flechette projectile weapon/shotgun/projectile 0.02 default 1100 1 0.1 60 0 +projminigun Minigun Bullet projectile weapon/minigun/projectile 0.01 default 800 1 0.1 60 0 +projsniperrifle Sniper Rifle Flechette projectile weapon/sniperrifle/projectile 0.01 default 4000 1 0.1 60 0 +projgrenadelauncher Grenade Launcher Grenade projectile weapon/grenadelauncher/projectile 0.5 default 100 1 0.1 60 2 +projrocketlauncher Rocket Launcher Rocket projectile weapon/rocketlauncher/projectile 1 default 100 5000 1000 1 0.1 60 0 +projplasmacannon Plasma Cannon Ball projectile weapon/plasmacannon/projectile 0.005 default 400 1 0.1 10 0 +projtankrailgun Railgun Bolt projectile weapon/tankrailgun/projectile 0.5 default 4000 1 0.1 60 0 +projturretrailgun Railgun Bolt projectile weapon/turretrailgun/projectile 0.1 default 4000 1 0.1 60 0 +projturretvulcan Vulcan Turret Bullet projectile weapon/turretvulcan/projectile 0.01 default 1000 1 0.1 60 0 +projturretartillery Artillery Cannon Shell projectile weapon/turretartillery/projectile 5 default 300 1 0.01 60 2 +expprojhandgrenade Hand Grenade Explosion explosion weapon/handgrenade/projectileexplosion 400 100 400 10 2 30 +expprojpistol Pistol Bullet Impact explosion weapon/pistol/projectileexplosion 50 30 0.1 0.01 0 0 +expprojmachinegun Machinegun Bullet Impact explosion weapon/machinegun/projectileexplosion 30 15 0.05 0.01 0 0 +expprojshotgun Shotgun Flechette Impact explosion weapon/shotgun/projectileexplosion 20 20 0.05 0.01 0 0 +expprojminigun Minigun Bullet Impact explosion weapon/minigun/projectileexplosion 30 15 0.05 0.01 0 0 +expprojsniperrifle Sniper Rifle Flechette Impact explosion weapon/sniperrifle/projectileexplosion 150 150 0.05 0.01 0 0 +expprojgrenadelauncher Grenade Launcher Grenade Explosion explosion weapon/grenadelauncher/projectileexplosion 300 100 300 10 2 30 +expprojrocketlauncher Rocket Launcher Rocket Explosion explosion weapon/rocketlauncher/projectileexplosion 300 100 300 10 2 30 +expprojplasmacannon Plasma Cannon Shell Explosion explosion weapon/plasmacannon/projectileexplosion 150 400 10 2 0 0 +expprojtankrailgun Railgun Bolt Impact explosion weapon/tankrailgun/projectileexplosion 200 900 50 0.5 1 10 +expprojturretrailgun Railgun Bolt Impact explosion weapon/turretrailgun/projectileexplosion 200 900 50 0.5 1 10 +expprojturretvulcan Vulcan Turret Bullet Impact explosion weapon/turretvulcan/projectileexplosion 20 30 1 0.01 0 0 +expprojturretartillery Artillery Cannon Shell Explosion explosion weapon/turretartillery/projectileexplosion 200 400 200 10 2 30 Modified: trunk/game/g_entity.c =================================================================== --- trunk/game/g_entity.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_entity.c 2006-03-27 09:16:27 UTC (rev 685) @@ -5,12 +5,20 @@ #include "game/g_world.h" #include "model.h" -G_Entity *G_Entity_New(G_Entity *parent, const G_Entity_Class *eclass) +G_Entity *G_Entity_New(G_Entity *parent, const G_Entity_Class *eclass, const G_Entity_Position *position) { G_Entity *entity; NUint32 childindex = 0; if (!eclass) return NULL; + if (!eclass->codeclass->name) + { + Console_Printf("G_Entity_New: no code class found for classname \"%s\"\n", eclass->classname); + // if editing, we should keep the unrecognized entities so that the + // user can change them to something else + if (!G.editing) + return NULL; + } if (parent) { for (childindex = 0;childindex < G_ENTITY_CHILDREN;childindex++) @@ -23,6 +31,8 @@ return NULL; } } + if (!position) + position = &GS.identityposition; // TODO: add a timeout after freeing an entity before it will be reused? (if so this will need to scan twice if it can't find one with the timeout) for (entity = G.entities + G.allocentity;G.allocentity < G_MAX_ENTITIES;G.allocentity++, entity++) { @@ -40,9 +50,10 @@ entity->owner = parent; parent->children[childindex] = entity; } - // now set up basic things that are generally wanted, to save code in the spawn functions + entity->position = *position; if (entity->eclass->modelname && entity->eclass->modelname[0]) G_Entity_SetModel(entity, entity->eclass->modelname); + entity->lifetime = entity->eclass->lifetime; return entity; } } @@ -52,13 +63,6 @@ void G_Entity_Spawn(G_Entity *entity) { - if (!entity->eclass) - { - Console_Printf("G_Entity_Spawn: NULL eclass\n"); - entity->eclass = G_EntityClass_ByNumber(0); - } - if (!entity->modelindex && entity->eclass->modelname) - G_Entity_SetModel(entity, entity->eclass->modelname); if (entity->eclass->codeclass->spawn) { entity->eclass->codeclass->spawn(entity); @@ -69,38 +73,6 @@ G_Entity_Relink(entity); } -void G_Entity_SpawnFromFields(G_Entity *entity) -{ - char *classname, *model, *cubemapname; - Nvec3 origin, angles; - Nvec scale; - classname = G_Entity_FieldValue_String(entity, "classname"); - entity->eclass = G_EntityClass_ByName(classname); - // set up the most general fields to save code in spawn functions - G_Entity_FieldValue_Vector(entity, "origin", origin); - G_Entity_FieldValue_Vector(entity, "angles", angles); - scale = G_Entity_FieldValue_Double(entity, "scale"); - if (!scale) - scale = 1; - Matrix4x4_CreateFromQuakeEntity(&entity->matrix, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], scale); - G_Entity_FieldValue_Vector(entity, "color", entity->lightcolor); - cubemapname = G_Entity_FieldValue_String(entity, "cubemap"); - if (cubemapname) - entity->lightcubemap = Resource_IndexForName(cubemapname, RESOURCETYPE_TEXTURE, 0, 0); - model = G_Entity_FieldValue_String(entity, "model"); - if (model) - G_Entity_SetModel(entity, model); - if (!G.editing) - G_Entity_RemoveFields(entity); - G_Entity_Spawn(entity); - if (!entity->eclass->codeclass->name) - { - Console_Printf("G_Entity_SpawnFromFields: no class found for classname \"%s\"\n", classname ? classname : ""); - if (!G.editing) - G_Entity_Remove(entity); - } -} - static void G_Entity_Unlink(G_Entity *entity); void G_Entity_Remove(G_Entity *entity) { @@ -138,7 +110,7 @@ if (entity->transforms) Mem_Free(&entity->transforms); // remove attached fields (which only exist in editing mode) - G_Entity_RemoveFields(entity); + StringKeys_FreeKeys(&entity->keys); // clear the entity completely memset(entity, 0, sizeof(*entity)); // reset allocentity to a level that will find this freshly freed entity @@ -153,40 +125,46 @@ G_Entity_Remove(entity->children[childindex]); } -void G_Entity_RemoveFields(G_Entity *entity) -{ - G_Entity_Field *field, *fieldnext; - for (field = entity->fields;field;field = fieldnext) - { - fieldnext = field->next; - String_Free(&field->key); - String_Free(&field->value); - Mem_Free(&field); - } - entity->fields = NULL; -} - void G_Entity_SpawnInventoryChildren(G_Entity *entity) { NUint32 i; for (i = 0;i < G_ENTITYCLASS_INVENTORY_MAX;i++) { - if (entity->eclass->inventory[i].quantity > 0) + if (entity->eclass->inventory[i].codename) { const G_Entity_Class *itemeclass = G_EntityClass_ByName(entity->eclass->inventory[i].codename); if (itemeclass) { - G_Entity *item = G_Entity_New(entity, itemeclass); - item->quantity = entity->eclass->inventory[i].quantity; + G_Entity *item = G_Entity_New(entity, itemeclass, &entity->position); + item->attachment_entity = entity; + item->attachment_transformindex = Model_GetTransformNumberForName(entity->modelindex, entity->eclass->inventory[i].transformname) + 1; + item->attachment_matrix = GS.identityposition.m; G_Entity_Spawn(item); } else Console_Printf("G_Entity_SpawnInventoryChildren: Can't find entity class for %s.I%iC\n", entity->eclass->codename, i + 1); } } - // TODO; spawn inventory entities and attach to player model } +void G_Entity_GetTransformMatrix(G_Entity *entity, NUint32 transformindex, matrix4x4_t *result) +{ + if (index >= 1 && index <= entity->numtransforms) + Matrix4x4_Concat(result, &entity->position.m, entity->transforms + (transformindex - 1)); + else + *result = entity->position.m; +} + +void G_Entity_UpdateAttachment(G_Entity *entity) +{ + matrix4x4_t parentmatrix; + if (!entity->attachment_entity) + return; + G_Entity_GetMatrix(entity->attachment_entity, entity->attachment_index, &parentmatrix); + Matrix4x4_Concat(&entity->position.m, &parentmatrix, &entity->attachment_matrix); + G_Entity_Relink(entity); +} + void G_World_UnlinkSurface(G_Entity_Surface *surface); void G_World_LinkSurface(G_Entity_Surface *surface); @@ -236,6 +214,18 @@ G_Entity_SetModelIndex(entity, Resource_IndexForName(modelname, RESOURCETYPE_MODEL, 0, 0)); } +void G_Entity_SetAnimation(G_Entity *entity, G_Entity_AnimationState *state, G_Entity_AnimationType type, const char *modelanimname) +{ + state->type = type; + state->time = 0; + state->resourceindex = Resource_IndexForName(modelanimname, RESOURCETYPE_MODELANIM, 0, 0); +} + +void G_Entity_Animation(G_Entity *entity, G_Entity_AnimationState *state) +{ + state->time += G.frametime; +} + // FIXME: move these to g_world.c void G_World_UnlinkSurface(G_Entity_Surface *surface) { @@ -284,10 +274,13 @@ G_Entity_Unlink(entity); + // update the inverse matrix + Matrix4x4_Invert_Simple(&entity->position.inversem, &entity->position.m); + if (entity->eclass->codeclass->scopeflags & G_SCOPE_RENDER_LIGHTSOURCE) { - Matrix4x4_OriginFromMatrix(&entity->matrix, entity->cullorigin); - entity->cullradius = Matrix4x4_ScaleFromMatrix(&entity->matrix); + Matrix4x4_OriginFromMatrix(&entity->position.m, entity->cullorigin); + entity->cullradius = Matrix4x4_ScaleFromMatrix(&entity->position.m); entity->cullmins[0] = entity->cullorigin[0] - entity->cullradius; entity->cullmins[1] = entity->cullorigin[1] - entity->cullradius; entity->cullmins[2] = entity->cullorigin[2] - entity->cullradius; @@ -310,9 +303,9 @@ meshlocalcullorigin[0] = (meshlocalmins[0] + meshlocalmaxs[0]) * 0.5; meshlocalcullorigin[1] = (meshlocalmins[1] + meshlocalmaxs[1]) * 0.5; meshlocalcullorigin[2] = (meshlocalmins[2] + meshlocalmaxs[2]) * 0.5; - Matrix4x4_Transform(&entity->matrix, meshlocalcullorigin, surface->cullorigin); - // TODO: scale radius based on longest vector in entity->matrix? - surface->cullradius = Matrix4x4_ScaleFromMatrix(&entity->matrix) * VectorDistance(meshlocalcullorigin, meshlocalmaxs); + Matrix4x4_Transform(&entity->position.m, meshlocalcullorigin, surface->cullorigin); + // TODO: scale radius based on longest vector in entity->position.m? + surface->cullradius = Matrix4x4_ScaleFromMatrix(&entity->position.m) * VectorDistance(meshlocalcullorigin, meshlocalmaxs); VectorCopy(surface->cullorigin, surface->cullmins); VectorCopy(surface->cullorigin, surface->cullmaxs); // TODO: optimize unrotated case @@ -322,7 +315,7 @@ localpoint[0] = i & 1 ? meshlocalmaxs[0] : meshlocalmins[0]; localpoint[1] = i & 2 ? meshlocalmaxs[1] : meshlocalmins[1]; localpoint[2] = i & 4 ? meshlocalmaxs[2] : meshlocalmins[2]; - Matrix4x4_Transform(&entity->matrix, localpoint, point); + Matrix4x4_Transform(&entity->position.m, localpoint, point); surface->cullmins[0] = Min(surface->cullmins[0], point[0]); surface->cullmins[1] = Min(surface->cullmins[1], point[1]); surface->cullmins[2] = Min(surface->cullmins[2], point[2]); @@ -362,18 +355,18 @@ cullorigin[0] = (entitylocalmins[0] + entitylocalmaxs[0]) * 0.5; cullorigin[1] = (entitylocalmins[1] + entitylocalmaxs[1]) * 0.5; cullorigin[2] = (entitylocalmins[2] + entitylocalmaxs[2]) * 0.5; - Matrix4x4_Transform(&entity->matrix, cullorigin, entity->cullorigin); - // TODO: scale radius based on longest vector in entity->matrix? - entity->cullradius = Matrix4x4_ScaleFromMatrix(&entity->matrix) * VectorDistance(cullorigin, entitylocalmaxs); + Matrix4x4_Transform(&entity->position.m, cullorigin, entity->cullorigin); + // TODO: scale radius based on longest vector in entity->position.m? + entity->cullradius = Matrix4x4_ScaleFromMatrix(&entity->position.m) * VectorDistance(cullorigin, entitylocalmaxs); // TODO: link into culling grid for collision detection } else { // no surfaces, so culling box is just a point - entity->cullorigin[0] = entity->matrix.m[0][3]; - entity->cullorigin[1] = entity->matrix.m[1][3]; - entity->cullorigin[2] = entity->matrix.m[2][3]; + entity->cullorigin[0] = entity->position.m.m[0][3]; + entity->cullorigin[1] = entity->position.m.m[1][3]; + entity->cullorigin[2] = entity->position.m.m[2][3]; entity->cullradius = 0; VectorCopy(entity->cullorigin, entity->cullmins); VectorCopy(entity->cullorigin, entity->cullmaxs); @@ -388,7 +381,7 @@ matrix4x4_t newmatrix; G_Trace trace; - if (VectorLength2(self->velocity) < (1.0 / 1024.0)) + if (VectorLength2(self->position.velocity) < (1.0 / 1024.0)) { // no movement return; @@ -400,24 +393,24 @@ if (!scope) { // noclip - self->matrix.m[0][3] = self->matrix.m[0][3] + G.frametime * self->velocity[0]; - self->matrix.m[1][3] = self->matrix.m[1][3] + G.frametime * self->velocity[1]; - self->matrix.m[2][3] = self->matrix.m[2][3] + G.frametime * self->velocity[2]; + self->position.m.m[0][3] = self->position.m.m[0][3] + G.frametime * self->position.velocity[0]; + self->position.m.m[1][3] = self->position.m.m[1][3] + G.frametime * self->position.velocity[1]; + self->position.m.m[2][3] = self->position.m.m[2][3] + G.frametime * self->position.velocity[2]; G_Entity_Relink(self); return; } for (bump = 0, t = 1;bump < 16 && t >= (1.0 / 128.0);bump++) { - newmatrix = self->matrix; - newmatrix.m[0][3] = self->matrix.m[0][3] + t * G.frametime * self->velocity[0]; - newmatrix.m[1][3] = self->matrix.m[1][3] + t * G.frametime * self->velocity[1]; - newmatrix.m[2][3] = self->matrix.m[2][3] + t * G.frametime * self->velocity[2]; + newmatrix = self->position.m; + newmatrix.m[0][3] = self->position.m.m[0][3] + t * G.frametime * self->position.velocity[0]; + newmatrix.m[1][3] = self->position.m.m[1][3] + t * G.frametime * self->position.velocity[1]; + newmatrix.m[2][3] = self->position.m.m[2][3] + t * G.frametime * self->position.velocity[2]; - G_World_Trace_Brush(&trace, &self->collisionbrush, &self->matrix, &newmatrix, self, scope); + G_World_Trace_Brush(&trace, &self->collisionbrush, &self->position.m, &newmatrix, self, scope); if (trace.impact_fraction == 1) { - self->matrix = trace.impact_matrix; + self->position.m = trace.impact_matrix; break; } @@ -429,7 +422,7 @@ matrix4x4_t matrix2; matrix4x4_t newmatrix2; // trace again, but higher - matrix2 = self->matrix; + matrix2 = self->position.m; matrix2.m[2][3] += stepheight; newmatrix2 = newmatrix; newmatrix2.m[2][3] += stepheight; @@ -451,8 +444,8 @@ VectorCopy(trace.impact_normal, self->groundnormal); } - self->matrix = trace.impact_matrix; - VectorReflect(self->velocity, bounce, trace.impact_normal, self->velocity); + self->position.m = trace.impact_matrix; + VectorReflect(self->position.velocity, bounce, trace.impact_normal, self->position.velocity); t -= t * trace.impact_fraction; } @@ -463,12 +456,12 @@ G_Trace trace2; matrix4x4_t matrix2; matrix4x4_t newmatrix2; - matrix2 = self->matrix; + matrix2 = self->position.m; newmatrix2 = matrix2; newmatrix2.m[2][3] -= stepheight; G_World_Trace_Brush(&trace2, &self->collisionbrush, &matrix2, &newmatrix2, self, scope); if (trace2.impact_fraction < 1) - self->matrix = trace2.impact_matrix; + self->position.m = trace2.impact_matrix; } */ @@ -486,15 +479,15 @@ if (!jumpspeed) { // apply stopspeed - VectorReflect(self->velocity, 0, self->groundnormal, groundwishdir); + VectorReflect(self->position.velocity, 0, self->groundnormal, groundwishdir); VectorNormalize(groundwishdir); - f = DotProduct(self->velocity, groundwishdir); + f = DotProduct(self->position.velocity, groundwishdir); f = Min(f, groundstopspeed * G.frametime); if (f > 0) - VectorMA(self->velocity, -f, groundwishdir, self->velocity); + VectorMA(self->position.velocity, -f, groundwishdir, self->position.velocity); // apply friction f = Bound(0, G.frametime * groundfriction, 1); - VectorLerp(self->velocity, f, self->groundentity->velocity, self->velocity); + VectorLerp(self->position.velocity, f, self->groundentity->position.velocity, self->position.velocity); } if (wishvel) { @@ -505,47 +498,47 @@ // normalize the groundwishdir, we only wanted the direction VectorNormalize(groundwishdir); wishspeed = VectorLength(wishvel); - f = Min(wishspeed * groundaccel * G.frametime, wishspeed - DotProduct(self->velocity, groundwishdir)); + f = Min(wishspeed * groundaccel * G.frametime, wishspeed - DotProduct(self->position.velocity, groundwishdir)); if (f > 0) { // apply acceleration - VectorMA(self->velocity, f, groundwishdir, self->velocity); + VectorMA(self->position.velocity, f, groundwishdir, self->position.velocity); } } // add jump impulse along ground normal if (jumpspeed) - VectorMA(self->velocity, jumpspeed, self->groundnormal, self->velocity); + VectorMA(self->position.velocity, jumpspeed, self->groundnormal, self->position.velocity); // apply gravity acceleration - VectorAdd(self->velocity, gravityimpulse, self->velocity); + VectorAdd(self->position.velocity, gravityimpulse, self->position.velocity); // add another impulse to counteract the sliding that results from gravity VectorReflect(gravityimpulse, 0, self->groundnormal, countergravityimpulse); - VectorSubtract(self->velocity, countergravityimpulse, self->velocity); + VectorSubtract(self->position.velocity, countergravityimpulse, self->position.velocity); } else { // apply stopspeed - f = VectorLength(self->velocity); + f = VectorLength(self->position.velocity); if (f > airstopspeed) { f = 1 - airstopspeed * G.frametime / f; - VectorScale(self->velocity, f, self->velocity); + VectorScale(self->position.velocity, f, self->position.velocity); } else - VectorClear(self->velocity); + VectorClear(self->position.velocity); // apply friction f = Bound(0, 1 - G.frametime * airfriction, 1); - VectorScale(self->velocity, f, self->velocity); + VectorScale(self->position.velocity, f, self->position.velocity); if (wishvel) { // apply acceleration f = Bound(-1, G.frametime * airaccel, 1); - VectorMA(self->velocity, f, wishvel, self->velocity); + VectorMA(self->position.velocity, f, wishvel, self->position.velocity); } // apply gravity acceleration - VectorAdd(self->velocity, gravityimpulse, self->velocity); + VectorAdd(self->position.velocity, gravityimpulse, self->position.velocity); } if (thrustvel) - VectorMA(self->velocity, G.frametime, thrustvel, self->velocity); + VectorMA(self->position.velocity, G.frametime, thrustvel, self->position.velocity); } static Collision_Brush boxbrush; @@ -613,98 +606,6 @@ Collision_Brush_UpdateCullingData(&entity->collisionbrush); } -void G_Entity_SetField(G_Entity *entity, const char *key, const char *value) -{ - G_Entity_Field *field, **nextpointer; - if (!String_ICompare(value, "")) - { - // remove a field - for (nextpointer = &entity->fields, field = *nextpointer;field;nextpointer = &field->next, field = *nextpointer) - { - if (!String_ICompare(field->key, key)) - { - String_Free(&field->key); - String_Free(&field->value); - Mem_Free(&field); - // unlink the field by updating the previous field's next - // pointer to point to the next field after the removed field - *nextpointer = field->next; - return; - } - } - // no field found - } - else - { - // add or update a field - for (nextpointer = &entity->fields, field = *nextpointer;field;nextpointer = &field->next, field = *nextpointer) - { - if (!String_ICompare(field->key, key)) - { - // update the existing field - String_Set(&field->key, GS.memzone, key); - String_Set(&field->value, GS.memzone, value); - return; - } - } - // add the field - *nextpointer = field = Mem_Alloc(GS.memzone, sizeof(G_Entity_Field)); - String_Set(&field->key, GS.memzone, key); - String_Set(&field->value, GS.memzone, value); - } -} - -char *G_Entity_FieldValue_String(G_Entity *entity, const char *key) -{ - G_Entity_Field *field; - for (field = entity->fields;field;field = field->next) - if (!String_ICompare(field->key, key)) - return field->value; - return NULL; -} - -NSint32 G_Entity_FieldValue_Integer(G_Entity *entity, const char *key) -{ - char *value = G_Entity_FieldValue_String(entity, key); - if (value) - { - while (*value && *value <= ' ') - value++; - return atoi(value); - } - return 0; -} - -Ndouble G_Entity_FieldValue_Double(G_Entity *entity, const char *key) -{ - char *value = G_Entity_FieldValue_String(entity, key); - if (value) - { - while (*value && *value <= ' ') - value++; - return atof(value); - } - return 0; -} - -void G_Entity_FieldValue_Vector(G_Entity *entity, const char *key, Nvec3 vector) -{ - NUint32 i; - char *value = G_Entity_FieldValue_String(entity, key); - VectorClear(vector); - if (value) - { - for (i = 0;i < 3;i++) - { - while (*value && *value <= ' ') - value++; - vector[i] = atof(value); - while (*value > ' ') - value++; - } - } -} - Nbool G_Entity_ReadPacket(G_PacketBuffer *buffer, NUint32 entityclassnumber) { // read 16bit entitynum @@ -749,7 +650,7 @@ if (G.client_networkentityindex[entitynum] < 0) { // create a new entity - entity = G_Entity_New(NULL, eclass); + entity = G_Entity_New(NULL, eclass, &GS.identityposition); // network index this local entity represents entity->networkindex = entitynum; // backwards index from the network index to this local entity @@ -781,8 +682,8 @@ NUint32 clientindex; GS_Client *client; for (clientindex = 0, client = GS.clients;clientindex < G_MAX_CLIENTS;clientindex++, client++) - if (client->netconnection) - client->netconnection->entitypriority[entitynumber] = Max(client->netconnection->entitypriority[entitynumber], 1); + if (client->netconnection && client->netconnection->entitypriority[entitynumber] < 1) + client->netconnection->entitypriority[entitynumber] = 1; } G_Entity *G_Entity_Find_CodeName(G_Entity *previous, const char *value) Modified: trunk/game/g_entity.h =================================================================== --- trunk/game/g_entity.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_entity.h 2006-03-27 09:16:27 UTC (rev 685) @@ -6,30 +6,27 @@ // G_Entity member functions: // creation/destruction of entities -G_Entity *G_Entity_New(G_Entity *parent, const G_Entity_Class *eclass); +G_Entity *G_Entity_New(G_Entity *parent, const G_Entity_Class *eclass, const G_Entity_Position *position); void G_Entity_Spawn(G_Entity *entity); -void G_Entity_SpawnFromFields(G_Entity *entity); void G_Entity_Remove(G_Entity *entity); void G_Entity_RemoveChildren(G_Entity *entity); -void G_Entity_RemoveFields(G_Entity *entity); void G_Entity_SpawnInventoryChildren(G_Entity *entity); +// attaching entities to eachother +void G_Entity_GetMatrix(G_Entity *entity, NUint32 index, matrix4x4_t *result); +void G_Entity_UpdateAttachment(G_Entity *entity); // changing an entity's model G_Entity_Surface *G_Entity_AddSurface(G_Entity *entity, NUint32 meshindex); void G_Entity_RemoveSurface(G_Entity *entity, G_Entity_Surface *surface); void G_Entity_SetModelIndex(G_Entity *entity, NUint32 modelindex); void G_Entity_SetModel(G_Entity *entity, const char *modelname); +// animation of an entity's model +void G_Entity_Animation(G_Entity *entity, G_Entity_AnimationState *state); // entity physics void G_Entity_Relink(G_Entity *entity); void G_Entity_Move(G_Entity *self, NUint32 scope, Nvec stepheight, Nvec bounce); void G_Entity_PlayerPhysics(G_Entity *self, Nvec3 wishvel, Nvec groundfriction, Nvec groundaccel, Nvec stopspeed, Nvec airfriction, Nvec airaccel, Nvec airstopspeed, Nvec jumpspeed, Nvec gravityscale, Nvec3 thrustvel); void G_Entity_SetBrush_Box(G_Entity *entity, const Nvec3 boxmins, const Nvec3 boxmaxs); void G_Entity_SetBrush_Point(G_Entity *entity, const Nvec3 point); -// editing -void G_Entity_SetField(G_Entity *entity, const char *key, const char *value); -Ndouble G_Entity_FieldValue_Double(G_Entity *entity, const char *key); -NSint32 G_Entity_FieldValue_Integer(G_Entity *entity, const char *key); -char *G_Entity_FieldValue_String(G_Entity *entity, const char *key); -void G_Entity_FieldValue_Vector(G_Entity *entity, const char *key, Nvec3 vector); // networking Nbool G_Entity_ReadPacket(G_PacketBuffer *buffer, NUint32 entityclassnumber); void G_Entity_SendNetworkUpdate(G_Entity *entity); Modified: trunk/game/g_entityclass.c =================================================================== --- trunk/game/g_entityclass.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_entityclass.c 2006-03-27 09:16:27 UTC (rev 685) @@ -27,7 +27,7 @@ static void G_Object_Light_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { - G_PacketBuffer_WriteMatrix(buffer, &self->matrix, true, true, true); + G_PacketBuffer_WritePosition(buffer, &self->position, true, true, true, false, false); G_PacketBuffer_WriteColorVector16(buffer, self->lightcolor); G_PacketBuffer_WriteResourceIndex_NoCache(buffer, self->lightcubemap); G_PacketBuffer_WriteBool(buffer, self->lightcastshadows); @@ -38,7 +38,7 @@ static void G_Object_Light_ReadPacket(G_Entity *self, G_PacketBuffer *buffer, Nbool reset) { - G_PacketBuffer_ReadMatrix(buffer, &self->matrix, true, true, true); + G_PacketBuffer_ReadPosition(buffer, &self->position, true, true, true, false, false); G_PacketBuffer_ReadColorVector16(buffer, self->lightcolor); self->lightcubemap = G_PacketBuffer_ReadResourceIndex_NoCache(buffer, RESOURCETYPE_TEXTURE); self->lightcastshadows = G_PacketBuffer_ReadBool(buffer); @@ -61,13 +61,13 @@ static void G_Object_Model_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { - G_PacketBuffer_WriteMatrix(buffer, &self->matrix, true, true, true); + G_PacketBuffer_WritePosition(buffer, &self->position, true, true, true, false, false); G_PacketBuffer_WriteResourceIndex_NoCache(buffer, self->modelindex); } static void G_Object_Model_ReadPacket(G_Entity *self, G_PacketBuffer *buffer, Nbool reset) { - G_PacketBuffer_ReadMatrix(buffer, &self->matrix, true, true, true); + G_PacketBuffer_ReadPosition(buffer, &self->position, true, true, true, false, false); G_Entity_SetModelIndex(self, G_PacketBuffer_ReadResourceIndex_NoCache(buffer, RESOURCETYPE_MODEL)); } @@ -125,6 +125,8 @@ user->localinput_pressedbuttonbits = 0; VectorClear(user->localinput_relativeviewangles); + self->buttons = buttonbits; + speed = (user->flymode || user->noclipmode) ? 100 : self->eclass->speed; VectorAdd(self->viewangles, relativeviewangles, self->viewangles); @@ -132,17 +134,20 @@ self->viewangles[1] -= 360 * floor(self->viewangles[1] / 360); self->viewangles[2] = 0; + G_Entity_Animation(self, &self->anim_head); + G_Entity_Animation(self, &self->anim_torso); + G_Entity_Animation(self, &self->anim_legs); + VectorClear(movement); - if (buttonbits & G_BUTTON_MOVEFORWARD) - {movement[0] += 1;} - if (buttonbits & G_BUTTON_MOVEBACKWARD) {movement[0] -= 1;} - if (buttonbits & G_BUTTON_MOVELEFT) {movement[1] += 1;} - if (buttonbits & G_BUTTON_MOVERIGHT) {movement[1] -= 1;} + if (buttonbits & G_BUTTON_MOVEFORWARD) movement[0] += 1; + if (buttonbits & G_BUTTON_MOVEBACKWARD) movement[0] -= 1; + if (buttonbits & G_BUTTON_MOVELEFT) movement[1] += 1; + if (buttonbits & G_BUTTON_MOVERIGHT) movement[1] -= 1; if (user->flymode || user->noclipmode) { - if (buttonbits & G_BUTTON_MOVEUP) {movement[2] += 1;} - if (buttonbits & G_BUTTON_MOVEDOWN) {movement[2] -= 1;} - Matrix4x4_CreateFromQuakeEntity(&newmatrix, self->matrix.m[0][3], self->matrix.m[1][3], self->matrix.m[2][3] + 0.7, self->viewangles[0], self->viewangles[1], self->viewangles[2], speed); + if (buttonbits & G_BUTTON_MOVEUP) movement[2] += 1; + if (buttonbits & G_BUTTON_MOVEDOWN) movement[2] -= 1; + Matrix4x4_CreateFromQuakeEntity(&newmatrix, self->position.m.m[0][3], self->position.m.m[1][3], self->position.m.m[2][3] + 0.7, self->viewangles[0], self->viewangles[1], self->viewangles[2], speed); } else Matrix4x4_CreateFromQuakeEntity(&newmatrix, 0, 0, 0, 0, self->viewangles[1], 0, speed); @@ -162,21 +167,21 @@ int j; for (j = 0; j < 3; j++) { - if (IsNAN(self->velocity[j])) - self->velocity[j] = 0; + if (IsNAN(self->position.velocity[j])) + self->position.velocity[j] = 0; } } G_Entity_Move(self, user->noclipmode ? 0 : G_SCOPE_BLOCK_PLAYER, self->eclass->stepheight, 0); - //Matrix4x4_ConcatQuakeEntity(&self->matrix, movement[0], movement[1], movement[2], turn[0], turn[1], turn[2], 1); - //Matrix4x4_Normalize(&self->matrix, &self->matrix); + //Matrix4x4_ConcatQuakeEntity(&self->position.m, movement[0], movement[1], movement[2], turn[0], turn[1], turn[2], 1); + //Matrix4x4_Normalize(&self->position.m, &self->position.m); if (user->client) { if (user->client->netconnection) { - Matrix4x4_OriginFromMatrix(&self->matrix, user->client->netconnection->eyeorigin); + Matrix4x4_OriginFromMatrix(&self->position.m, user->client->netconnection->eyeorigin); user->client->netconnection->eyeradius = 1000000; // 1000km } else @@ -187,7 +192,7 @@ if (GS.localuserindex == self->localuserindex) { // set up the view matrix for the player - Matrix4x4_CreateFromQuakeEntity(&G.cameramatrix, self->matrix.m[0][3], self->matrix.m[1][3], self->matrix.m[2][3] + 0.7, self->viewangles[0], self->viewangles[1], self->viewangles[2], 1); + Matrix4x4_CreateFromQuakeEntity(&G.cameramatrix, self->position.m.m[0][3], self->position.m.m[1][3], self->position.m.m[2][3] + 0.7, self->viewangles[0], self->viewangles[1], self->viewangles[2], 1); } } } @@ -200,7 +205,7 @@ static void G_Object_Infantry_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { G_PacketBuffer_Write16(buffer, GS.client_remotefromlocaluserindex[self->localuserindex]); - G_PacketBuffer_WriteMatrix(buffer, &self->matrix, true, false, false); + G_PacketBuffer_WritePosition(buffer, &self->position, true, false, false, false, false); G_PacketBuffer_WriteAngles16(buffer, self->viewangles); } @@ -208,7 +213,7 @@ { // TODO: bounds check userindex self->localuserindex = GS.client_localfromremoteuserindex[G_PacketBuffer_Read16(buffer)]; - G_PacketBuffer_ReadMatrix(buffer, &self->matrix, true, false, false); + G_PacketBuffer_ReadPosition(buffer, &self->position, true, false, false, false, false); G_PacketBuffer_ReadAngles16(buffer, self->viewangles); if (reset) G_Entity_SetBrush_Box(self, playermins, playermaxs); @@ -342,16 +347,63 @@ { } +static void G_Object_Weapon_LaunchProjectile(G_Entity *self) +{ + G_Entity_Position position; + G_Entity *projectile; + const G_Entity_Class *projectileclass; + Nvec3 speedvec; + position = self->position; + projectileclass = G_EntityClass_ByName(self->eclass->projectilecodename); + VectorSet(speedvec, projectileclass->speed, 0, 0); + Matrix4x4_Transform3x3(&position.m, speedvec, position.velocity); + // TODO: rifled bullet spin? + projectile = G_Entity_New(NULL, projectileclass, &position); + //if (!projectile) + // return; +} + static void G_Object_Weapon_Frame(G_Entity *self) { + if (self->attachment_entity) + G_Entity_UpdateAttachment(self); + self->attackdelay -= G.frametime; + if (self->attackdelay <= 0) + { + if (self->owner->buttons & G_BUTTON_FIRE1) + { + G_Object_Weapon_LaunchProjectile(self); + self->attackdelay += self->eclass->autorefire; + G_Entity_SendNetworkUpdate(self); + } + else + self->attackdelay = 0; + } } static void G_Object_Weapon_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { + if (self->owner) + { + G_PacketBuffer_WriteBool(buffer, true); + G_PacketBuffer_WriteEntityAsIndex(buffer, self->owner); + G_PacketBuffer_Write16(buffer, self->attachment_index); + } + else + G_PacketBuffer_WriteBool(buffer, false); + // we don't need much precision on how recently the gun was fired, so use + // an 8bit fraction-of-refire-time byte to save space + G_PacketBuffer_WriteClamped8(buffer, self->attackdelay, 255.0f / self->eclass->autorefire); } static void G_Object_Weapon_ReadPacket(G_Entity *self, G_PacketBuffer *buffer, Nbool reset) { + if (G_PacketBuffer_ReadBool(buffer)) + { + self->owner = G_PacketBuffer_ReadEntityAsIndex(buffer); + self->attachment_index = G_PacketBuffer_Read16(buffer); + } + G_PacketBuffer_ReadClamped8(buffer, 255.0f / self->eclass->autorefire); } static void G_Object_Ammo_Spawn(G_Entity *self) @@ -384,18 +436,33 @@ static void G_Object_Projectile_Frame(G_Entity *self) { + // TODO: use a better physics function (one that handles spin) + G_Entity_PlayerPhysics(self, NULL, self->eclass->friction, self->eclass->acceleration, self->eclass->stopspeed, self->eclass->airfriction, self->eclass->airacceleration, self->eclass->airstopspeed, 0, 1, NULL); + + G_Entity_Move(self, G_SCOPE_BLOCK_PROJECTILE, 0, 0); + + self->lifetime -= G.frametime; + if (self->lifetime <= 0) + G_Entity_Remove(self); } static void G_Object_Projectile_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { + // TODO: should we send only origin and velocity and try to guess the rest + // to save space, or be accurate and send origin rotation velocity spin? + G_PacketBuffer_WritePosition(buffer, &self->position, true, true, false, true, true); + G_PacketBuffer_WriteClamped8(buffer, self->lifetime, 255.0f / self->eclass->lifetime); } static void G_Object_Projectile_ReadPacket(G_Entity *self, G_PacketBuffer *buffer, Nbool reset) { + G_PacketBuffer_ReadPosition(buffer, &self->position, true, true, false, true, true); + self->lifetime = G_PacketBuffer_ReadClamped8(buffer, 255.0f / self->eclass->lifetime); } static void G_Object_Explosion_Spawn(G_Entity *self) { + // TODO: do damage } static void G_Object_Explosion_Remove(G_Entity *self) @@ -404,14 +471,21 @@ static void G_Object_Explosion_Frame(G_Entity *self) { + self->lifetime -= G.frametime; + if (self->lifetime <= 0) + G_Entity_Remove(self); } static void G_Object_Explosion_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { + G_PacketBuffer_WritePosition(buffer, &self->position, true, false, false, false, false); + G_PacketBuffer_WriteClamped8(buffer, self->lifetime, 255.0f / self->eclass->lifetime); } static void G_Object_Explosion_ReadPacket(G_Entity *self, G_PacketBuffer *buffer, Nbool reset) { + G_PacketBuffer_ReadPosition(buffer, &self->position, true, false, false, false, false); + self->lifetime = G_PacketBuffer_ReadClamped8(buffer, 255.0f / self->eclass->lifetime); } static void G_Object_Light_Attached_Spawn(G_Entity *self) @@ -429,7 +503,7 @@ G_Entity_Remove(self); return; } - Matrix4x4_Concat(&self->matrix, &self->owner->matrix, &self->lightmatrix); + Matrix4x4_Concat(&self->position.m, &self->owner->position.m, &self->lightmatrix); G_Entity_Relink(self); } @@ -451,7 +525,7 @@ model = Resource_GetData(self->modelindex); if (model) G_Entity_SetBrush_Box(self, model->basecullmins, model->basecullmaxs); - light = G_Entity_New(self, G_EntityClass_ByName("light_attached")); + light = G_Entity_New(self, G_EntityClass_ByName("light_attached"), &self->position); Matrix4x4_CreateFromQuakeEntity(&light->lightmatrix, 0, 3.5, 4, 0, 0, 0, 30); VectorSet(light->lightcolor, 1, 0.9, 0.2); light->lightcastshadows = true; @@ -474,21 +548,21 @@ static void G_Object_Vehicle_RockBore_WritePacket(G_Entity *self, G_PacketBuffer *buffer) { - G_PacketBuffer_WriteMatrix(buffer, &self->matrix, true, true, true); + G_PacketBuffer_WritePosition(buffer, &self->position, true, true, true, true, true); } static void G_Object_Vehicle_RockBore_ReadPacket(G_Entity *self, G_PacketBuffer *buffer, Nbool reset) { Model *model; G_Entity *light; - G_PacketBuffer_ReadMatrix(buffer, &self->matrix, true, true, true); + G_PacketBuffer_ReadPosition(buffer, &self->position, true, true, true, true, true); if (reset) { model = Resource_GetData(self->modelindex); if (model) G_Entity_SetBrush_Box(self, model->basecullmins, model->basecullmaxs); G_Entity_RemoveChildren(self); - light = G_Entity_New(self, G_EntityClass_ByName("light_attached")); + light = G_Entity_New(self, G_EntityClass_ByName("light_attached"), &self->position); Matrix4x4_CreateFromQuakeEntity(&light->lightmatrix, 0, 3.5, 4, 0, 0, 0, 30); VectorSet(light->lightcolor, 1, 0.9, 0.2); light->lightcastshadows = true; @@ -510,7 +584,7 @@ G_Entity_Remove(self); return; } - Matrix4x4_Concat(&self->matrix, &self->owner->matrix, &self->lightmatrix); + Matrix4x4_Concat(&self->position.m, &self->owner->position.m, &self->lightmatrix); G_Entity_Relink(self); } #endif @@ -701,103 +775,6 @@ G_Entity_Class G_EntityClasses[G_ENTITYCLASS_MAX]; -#if 0 -enum G_CSVColumn -{ - CSVCOLUMN_CodeName, - CSVCOLUMN_EnglishName, - CSVCOLUMN_Class, - CSVCOLUMN_Model, - CSVCOLUMN_Mass, - CSVCOLUMN_Health, - CSVCOLUMN_Heal, - CSVCOLUMN_NoRemove, - CSVCOLUMN_I1Q, - CSVCOLUMN_I1R, - CSVCOLUMN_I1C, - CSVCOLUMN_I2Q, - CSVCOLUMN_I2R, - CSVCOLUMN_I2C, - CSVCOLUMN_I3Q, - CSVCOLUMN_I3R, - CSVCOLUMN_I3C, - CSVCOLUMN_I4Q, - CSVCOLUMN_I4R, - CSVCOLUMN_I4C, - CSVCOLUMN_I5Q, - CSVCOLUMN_I5R, - CSVCOLUMN_I5C, - CSVCOLUMN_I6Q, - CSVCOLUMN_I6R, - CSVCOLUMN_I6C, - CSVCOLUMN_Projectile, - CSVCOLUMN_SemiRefire, - CSVCOLUMN_AutoRefire, - CSVCOLUMN_Speed, - CSVCOLUMN_Acceleration, - CSVCOLUMN_TopSpeed, - CSVCOLUMN_LifeTime, - CSVCOLUMN_ImpactDelay, - CSVCOLUMN_FleshDamage, - CSVCOLUMN_ArmorDamage, - CSVCOLUMN_Force, - CSVCOLUMN_DamageRadius, - CSVCOLUMN_Shake, - CSVCOLUMN_ShakeRadius, - CSVCOLUMN_IdleAnim, - CSVCOLUMN_IdleFPS, - CSVCOLUMN_END -}; - -static const char *csv_columnnames[CSVCOLUMN_END] = -{ - "CodeName", - "EnglishName", - "Class", - "Model", - "Mass", - "Health", - "Heal", - "NoRemove", - "I1Q", - "I1R", - "I1C", - "I2Q", - "I2R", - "I2C", - "I3Q", - "I3R", - "I3C", - "I4Q", - "I4R", - "I4C", - "I5Q", - "I5R", - "I5C", - "I6Q", - "I6R", - "I6C", - "Projectile", - "SemiRefire", - "AutoRefire", - "Speed", - "Acceleration", - "TopSpeed", - "LifeTime", - "ImpactDelay", - "FleshDamage", - "ArmorDamage", - "Force", - "DamageRadius", - "Shake", - "ShakeRadius", - "IdleAnim", - "IdleFPS", -}; - -static CSVColumn csv_columnremap[64]; -#endif - typedef enum CSVColumnFieldType { CSVCOLUMNFIELDTYPE_CHARPOINTER, @@ -828,24 +805,29 @@ CSVCOLUMNINFO("Health", health, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("Heal", heal, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("NoRemove", noremove, CSVCOLUMNFIELDTYPE_BOOL), - CSVCOLUMNINFO("I1Q", inventory[0].quantity, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I1R", inventory[0].regen, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I1C", inventory[0].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I2Q", inventory[1].quantity, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I2R", inventory[1].regen, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I2C", inventory[1].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I3Q", inventory[2].quantity, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I3R", inventory[2].regen, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I3C", inventory[2].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I4Q", inventory[3].quantity, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I4R", inventory[3].regen, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I4C", inventory[3].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I5Q", inventory[4].quantity, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I5R", inventory[4].regen, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I5C", inventory[4].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I6Q", inventory[5].quantity, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I6R", inventory[5].regen, CSVCOLUMNFIELDTYPE_NVEC), - CSVCOLUMNINFO("I6C", inventory[5].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("Respawn", respawn, CSVCOLUMNFIELDTYPE_NVEC), + CSVCOLUMNINFO("I0C", inventory[0].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I0B", inventory[0].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I1C", inventory[1].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I1B", inventory[1].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I2C", inventory[2].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I2B", inventory[2].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I3C", inventory[3].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I3B", inventory[3].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I4C", inventory[4].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I4B", inventory[4].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I5C", inventory[5].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I5B", inventory[5].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I6C", inventory[6].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I6B", inventory[6].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I7C", inventory[7].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I7B", inventory[7].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I8C", inventory[8].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I8B", inventory[8].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I9C", inventory[9].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I9B", inventory[9].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("AmmoMax", ammomax, CSVCOLUMNFIELDTYPE_NVEC), + CSVCOLUMNINFO("AmmoRegen", ammoregen, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("Projectile", projectilecodename, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("SemiRefire", semirefire, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("AutoRefire", autorefire, CSVCOLUMNFIELDTYPE_NVEC), @@ -863,6 +845,10 @@ CSVCOLUMNINFO("AirStopSpeed", airstopspeed, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("HoverThrust", hoverthrust, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("HoverAltitude", hoveraltitude, CSVCOLUMNFIELDTYPE_NVEC), + CSVCOLUMNINFO("Cloaking", cloaking, CSVCOLUMNFIELDTYPE_BOOL), + CSVCOLUMNINFO("JumpFlight", jumpflight, CSVCOLUMNFIELDTYPE_BOOL), + CSVCOLUMNINFO("CrouchShield", crouchshield, CSVCOLUMNFIELDTYPE_BOOL), + CSVCOLUMNINFO("CrouchTurret", crouchturret, CSVCOLUMNFIELDTYPE_BOOL), CSVCOLUMNINFO("LifeTime", lifetime, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("ImpactDelay", impactdelay, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("FleshDamage", fleshdamage, CSVCOLUMNFIELDTYPE_NVEC), @@ -871,8 +857,8 @@ CSVCOLUMNINFO("DamageRadius", damageradius, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("Shake", shake, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("ShakeRadius", shakeradius, CSVCOLUMNFIELDTYPE_NVEC), - //CSVCOLUMNINFO("IdleAnim", idleanim, CSVCOLUMNFIELDTYPE_CHARPOINTER), - //CSVCOLUMNINFO("IdleFPS", idlefps, CSVCOLUMNFIELDTYPE_NVEC), + CSVCOLUMNINFO("IdleAnim", idleanim, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("IdleFPS", idlefps, CSVCOLUMNFIELDTYPE_NVEC), {NULL, 0, CSVCOLUMNFIELDTYPE_END} }; @@ -952,10 +938,7 @@ switch(info->fieldtype) { case CSVCOLUMNFIELDTYPE_CHARPOINTER: - if (token[0]) - String_Set(&fieldpointer->p, GS.memzone, token); - else - fieldpointer->p = NULL; + String_Set(&fieldpointer->p, GS.memzone, token); break; case CSVCOLUMNFIELDTYPE_NVEC: fieldpointer->f = atof(token); @@ -966,39 +949,6 @@ default: break; } -#if 0 - case CSVCOLUMN_CodeName: String_Set(&eclass->codename, token);break; - case CSVCOLUMN_EnglishName: String_Set(&eclass->codename, token);break; - case CSVCOLUMN_Class: String_Set(&eclass->codename, token);break; - case CSVCOLUMN_Model: String_Set(&eclass->codename, token);break; - case CSVCOLUMN_Mass: eclass->mass = atof(token);break; - case CSVCOLUMN_Health: eclass->health = atof(token);break; - case CSVCOLUMN_Heal: eclass->heal = atof(token);break; - case CSVCOLUMN_NoRemove: eclass->noremove = !String_ICompare(token, "TRUE");break; - case CSVCOLUMN_I1Q: String_Set(&eclass->codename, token);break; - case CSVCOLUMN_Projectile: String_Set(&eclass->projectilename, token);break; - case CSVCOLUMN_SemiRefire: eclass->semirefire = atof(token);break; - case CSVCOLUMN_AutoRefire: eclass->autorefire = atof(token);break; - case CSVCOLUMN_Speed: eclass-> = atof(token);break; - case CSVCOLUMN_Acceleration: eclass-> = atof(token);break; - case CSVCOLUMN_TopSpeed: eclass-> = atof(token);break; - case CSVCOLUMN_LifeTime: eclass-> = atof(token);break; - case CSVCOLUMN_ImpactDelay: eclass-> = atof(token);break; - case CSVCOLUMN_FleshDamage: eclass-> = atof(token);break; - case CSVCOLUMN_ArmorDAmage: eclass-> = atof(token);break; - case CSVCOLUMN_Force: eclass-> = atof(token);break; - case CSVCOLUMN_damageRadius: eclass-> = atof(token);break; - case CSVCOLUMN_Shake: eclass-> = atof(token);break; - case CSVCOLUMN_ShakeRadius: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - case CSVCOLUMN_: eclass-> = atof(token);break; - } -#endif column++; } if (tokentype == G_CSV_TOKENTYPE_EOF) Modified: trunk/game/g_main.c =================================================================== --- trunk/game/g_main.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_main.c 2006-03-27 09:16:27 UTC (rev 685) @@ -154,7 +154,7 @@ if (!Video_SetMode(Cvar_GetValue("vid_width")->ival, Cvar_GetValue("vid_height")->ival, 32, Cvar_GetValue("vid_fullscreen")->ival, true)) if (!Video.width || !Video_SetMode(Video.width, Video.height, Video.bpp, Video.fullscreen, Video.openglmode)) if (!Video_SetMode(640, 480, 32, false, true)) - if (!Video_SetMode(640, 480, 32, false, false)) + //if (!Video_SetMode(640, 480, 32, false, false)) { Console_Printf("Unable to open video!\n"); GS.quit = true; @@ -200,6 +200,11 @@ GS.realtime = GS.oldrealtime = System_Time(); GS.protocolname = "DarkWar1"; + Matrix4x4_CreateIdentity(&GS.identityposition.m); + Matrix4x4_CreateIdentity(&GS.identityposition.inversem); + VectorClear(GS.identityposition.velocity); + Vector4Set(GS.identityposition.spin, 1, 0, 0, 0); + Menu_Init(); G_InitCommands(); G_World_Init(); Modified: trunk/game/g_main.h =================================================================== --- trunk/game/g_main.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_main.h 2006-03-27 09:16:27 UTC (rev 685) @@ -2,6 +2,15 @@ #ifndef G_MAIN_H #define G_MAIN_H +typedef struct G_Entity_Position +{ + matrix4x4_t m; + matrix4x4_t inversem; + Nvec3 velocity; + Nvec4 spin; +} +G_Entity_Position; + #include "game/g_network.h" #include "collision.h" @@ -205,6 +214,9 @@ NUint8 *server_networkresource_sent; NUint32 client_networkresource_maxindices; NUint32 *client_networkresource_remapindex; + // reference values for initializing structs + matrix4x4_t identitymatrix; + G_Entity_Position identityposition; } G_Static; @@ -277,23 +289,14 @@ #define G_SCOPE_NETWORK_HEARABLE (1<<24) #define G_SCOPE_AUDIO_SOUNDSOURCE (1<<25) -typedef struct G_Entity_Field -{ - struct G_Entity_Field *next; - char *key; - char *value; -} -G_Entity_Field; - // the protocol only supports up to 128 #define G_ENTITYCLASS_MAX 128 #define G_ENTITYCLASS_INVENTORY_MAX 6 typedef struct G_Entity_Class_InventoryEntry { - Nvec quantity; - Nvec regen; char *codename; + char *transformname; } G_Entity_Class_InventoryEntry; @@ -331,7 +334,10 @@ Nvec health; Nvec heal; Nbool noremove; + Nvec respawn; G_Entity_Class_InventoryEntry inventory[G_ENTITYCLASS_INVENTORY_MAX]; + Nvec ammomax; + Nvec ammoregen; char *projectilecodename; Nvec semirefire; Nvec autorefire; @@ -349,6 +355,10 @@ Nvec airstopspeed; Nvec hoverthrust; Nvec hoveraltitude; + Nbool cloaking; + Nbool jumpflight; + Nbool crouchshield; + Nbool crouchturret; Nvec lifetime; Nvec impactdelay; Nvec fleshdamage; @@ -357,6 +367,8 @@ Nvec damageradius; Nvec shake; Nvec shakeradius; + char *idleanim; + Nvec idlefps; } G_Entity_Class; @@ -414,6 +426,52 @@ #define G_ENTITY_CHILDREN 16 +typedef enum G_Entity_AnimationType +{ + G_ANIM_IDLE, + G_ANIM_FIRE1, + G_ANIM_FIRE2, + G_ANIM_RELOAD, + G_ANIM_THROW, + G_ANIM_GET, + G_ANIM_PUT, + G_ANIM_RUNFORWARD, + G_ANIM_RUNBACKWARD, + G_ANIM_RUNLEFT, + G_ANIM_RUNRIGHT, + G_ANIM_WALKFORWARD, + G_ANIM_WALKBACKWARD, + G_ANIM_WALKLEFT, + G_ANIM_WALKRIGHT, + G_ANIM_ROLLFORWARD, + G_ANIM_ROLLBACKWARD, + G_ANIM_ROLLLEFT, + G_ANIM_ROLLRIGHT, + G_ANIM_JUMP, + G_ANIM_FALL, + G_ANIM_LAND, + G_ANIM_DYING, + G_ANIM_DEAD, + G_ANIM_SIGNAL_FORWARD, + G_ANIM_SIGNAL_STOP, + G_ANIM_SIGNAL_RETREAT, + G_ANIM_SIGNAL_ATTACK, + G_ANIM_SIGNAL_DEFEND, + G_ANIM_SIGNAL_HOLDPOSITION, +} +G_Entity_AnimationType; + +typedef struct G_Entity_AnimationState +{ + // type of animation (for comparison purposes) + G_Entity_AnimationType type; + // time since animation started + float time; + // the ModelAnim resource being shownf + NUint32 resourceindex; +} +G_Entity_AnimationState; + typedef struct G_Entity { // class this entity uses @@ -422,24 +480,29 @@ // owner of this entity (used by projectiles mainly) struct G_Entity *owner; struct G_Entity *children[G_ENTITY_CHILDREN]; + struct G_Entity *attachment_entity; + NUint32 attachment_transformindex; + matrix4x4_t attachment_matrix; G_Entity_Surface *surfacelist; G_Entity_Sound sound; + G_Entity_AnimationState anim_head; + G_Entity_AnimationState anim_torso; + G_Entity_AnimationState anim_legs; // if >= 0 this is the index in the G.client_networkentityindex array that // contains a pointer to this entity NSint32 networkindex; // index of associated user if this is a player entity NUint32 localuserindex; + // pressed buttons as of last Infantry_Frame call, causes weapons to fire + NUint32 buttons; // TODO: rendering // index of model this entity is using NUint32 modelindex; // set of skeletal transforms for rendering the model, or NULL for static + NUint32 numtransforms; matrix4x4_t *transforms; - // entity transform (skeletal is relative to this) - matrix4x4_t matrix; - // velocity (second order position) - Nvec3 velocity; - // axis and angle - Nvec4 spinvelocity; + // entity transform (skeletal is relative to this) and velocity + G_Entity_Position position; // builtin collision brush buffers (to avoid alloc/free) Collision_Brush collisionbrush; Collision_Point collisionbrushpoints[16]; @@ -470,7 +533,14 @@ Nvec quantity; // fields (classname and origin and so on), only present in editing mode // and during loading - G_Entity_Field *fields; + NStringKeys keys; + // animation + G_Entity_AnimationState anim; + Nvec animframe; + // projectiles + Nvec lifetime; + // weapons + Nvec attackdelay; } G_Entity; Modified: trunk/game/g_network.c =================================================================== --- trunk/game/g_network.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_network.c 2006-03-27 09:16:27 UTC (rev 685) @@ -278,9 +278,9 @@ if (netconnection->entitypriority[i] < (G_NET_ENTITYPRIORITYLEVELS-1)) { Nvec3 relativeorigin; - relativeorigin[0] = G.entities[i].matrix.m[0][3] - netconnection->eyeorigin[0]; - relativeorigin[1] = G.entities[i].matrix.m[1][3] - netconnection->eyeorigin[1]; - relativeorigin[2] = G.entities[i].matrix.m[2][3] - netconnection->eyeorigin[2]; + relativeorigin[0] = G.entities[i].position.m.m[0][3] - netconnection->eyeorigin[0]; + relativeorigin[1] = G.entities[i].position.m.m[1][3] - netconnection->eyeorigin[1]; + relativeorigin[2] = G.entities[i].position.m.m[2][3] - netconnection->eyeorigin[2]; newpriority = (int)(G_NET_ENTITYPRIORITYMAX - VectorLength(relativeorigin) * G_NET_ENTITYPRIORITYDISTANCESCALE); newpriority = netconnection->entitypriority[i] + Max(G_NET_ENTITYPRIORITYMIN, newpriority); netconnection->entitypriority[i] = (NUint8)Min(newpriority, G_NET_ENTITYPRIORITYLEVELS-1); Modified: trunk/game/g_packetbuffer.c =================================================================== --- trunk/game/g_packetbuffer.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_packetbuffer.c 2006-03-27 09:16:27 UTC (rev 685) @@ -194,56 +194,81 @@ // functions for more specialized data types -void G_PacketBuffer_WriteMatrix(G_PacketBuffer *buf, matrix4x4_t *matrix, Nbool sendorigin, Nbool sendrotation, Nbool sendscale) +void G_PacketBuffer_WritePosition(G_PacketBuffer *buf, G_Entity_Position *p, Nbool sendorigin, Nbool sendrotation, Nbool sendscale, Nbool sendvelocity, Nbool sendspin) { + // location if (sendorigin) { - G_PacketBuffer_WriteFloat(buf, matrix->m[0][3]); - G_PacketBuffer_WriteFloat(buf, matrix->m[1][3]); - G_PacketBuffer_WriteFloat(buf, matrix->m[2][3]); + G_PacketBuffer_WriteFloat(buf, p->m.m[0][3]); + G_PacketBuffer_WriteFloat(buf, p->m.m[1][3]); + G_PacketBuffer_WriteFloat(buf, p->m.m[2][3]); } // TODO: optimize rotation/scale sending, rotation can be sent as a 3 // component version of a normalized quat, scale can be sent as a float if (sendrotation || sendscale) { - G_PacketBuffer_WriteFloat(buf, matrix->m[0][0]); - G_PacketBuffer_WriteFloat(buf, matrix->m[0][1]); - G_PacketBuffer_WriteFloat(buf, matrix->m[0][2]); - G_PacketBuffer_WriteFloat(buf, matrix->m[1][0]); - G_PacketBuffer_WriteFloat(buf, matrix->m[1][1]); - G_PacketBuffer_WriteFloat(buf, matrix->m[1][2]); - G_PacketBuffer_WriteFloat(buf, matrix->m[2][0]); - G_PacketBuffer_WriteFloat(buf, matrix->m[2][1]); - G_PacketBuffer_WriteFloat(buf, matrix->m[2][2]); + G_PacketBuffer_WriteFloat(buf, p->m.m[0][0]); + G_PacketBuffer_WriteFloat(buf, p->m.m[1][0]); + G_PacketBuffer_WriteFloat(buf, p->m.m[2][0]); + G_PacketBuffer_WriteFloat(buf, p->m.m[0][1]); + G_PacketBuffer_WriteFloat(buf, p->m.m[1][1]); + G_PacketBuffer_WriteFloat(buf, p->m.m[2][1]); + G_PacketBuffer_WriteFloat(buf, p->m.m[0][2]); + G_PacketBuffer_WriteFloat(buf, p->m.m[1][2]); + G_PacketBuffer_WriteFloat(buf, p->m.m[2][2]); } + // second order location (velocity) + if (sendvelocity) + { + G_PacketBuffer_WriteFloat(buf, p->velocity[0]); + G_PacketBuffer_WriteFloat(buf, p->velocity[1]); + G_PacketBuffer_WriteFloat(buf, p->velocity[2]); + } + // second order rotation (spin) + // this is a rodrigues vector (axis plus angle of rotation around it) + if (sendspin) + { + G_PacketBuffer_WriteFloat(buf, p->spin[0]); + G_PacketBuffer_WriteFloat(buf, p->spin[1]); + G_PacketBuffer_WriteFloat(buf, p->spin[2]); + G_PacketBuffer_WriteFloat(buf, p->spin[3]); + } } -void G_PacketBuffer_ReadMatrix(G_PacketBuffer *buf, matrix4x4_t *matrix, Nbool sendorigin, Nbool sendrotation, Nbool sendscale) +void G_PacketBuffer_ReadPosition(G_PacketBuffer *buf, G_Entity_Position *p, Nbool sendorigin, Nbool sendrotation, Nbool sendscale, Nbool sendvelocity, Nbool sendspin) { + *p = GS.identityposition; if (sendorigin) { - matrix->m[0][3] = G_PacketBuffer_ReadFloat(buf); - matrix->m[1][3] = G_PacketBuffer_ReadFloat(buf); - matrix->m[2][3] = G_PacketBuffer_ReadFloat(buf); + p->m.m[0][3] = G_PacketBuffer_ReadFloat(buf); + p->m.m[1][3] = G_PacketBuffer_ReadFloat(buf); + p->m.m[2][3] = G_PacketBuffer_ReadFloat(buf); } if (sendrotation || sendscale) { - matrix->m[0][0] = G_PacketBuffer_ReadFloat(buf); - matrix->m[0][1] = G_PacketBuffer_ReadFloat(buf); - matrix->m[0][2] = G_PacketBuffer_ReadFloat(buf); - matrix->m[1][0] = G_PacketBuffer_ReadFloat(buf); - matrix->m[1][1] = G_PacketBuffer_ReadFloat(buf); - matrix->m[1][2] = G_PacketBuffer_ReadFloat(buf); - matrix->m[2][0] = G_PacketBuffer_ReadFloat(buf); - matrix->m[2][1] = G_PacketBuffer_ReadFloat(buf); - matrix->m[2][2] = G_PacketBuffer_ReadFloat(buf); + p->m.m[0][0] = G_PacketBuffer_ReadFloat(buf); + p->m.m[0][1] = G_PacketBuffer_ReadFloat(buf); + p->m.m[0][2] = G_PacketBuffer_ReadFloat(buf); + p->m.m[1][0] = G_PacketBuffer_ReadFloat(buf); + p->m.m[1][1] = G_PacketBuffer_ReadFloat(buf); + p->m.m[1][2] = G_PacketBuffer_ReadFloat(buf); + p->m.m[2][0] = G_PacketBuffer_ReadFloat(buf); + p->m.m[2][1] = G_PacketBuffer_ReadFloat(buf); + p->m.m[2][2] = G_PacketBuffer_ReadFloat(buf); } - // LordHavoc: for a good time, comment out these lines; it took me a long - // time to figure out the resulting rendering bug. - matrix->m[3][0] = 0; - matrix->m[3][1] = 0; - matrix->m[3][2] = 0; - matrix->m[3][3] = 1; + if (sendvelocity) + { + p->velocity[0] = G_PacketBuffer_ReadFloat(buf); + p->velocity[1] = G_PacketBuffer_ReadFloat(buf); + p->velocity[2] = G_PacketBuffer_ReadFloat(buf); + } + if (sendspin) + { + p->spin[0] = G_PacketBuffer_ReadFloat(buf); + p->spin[1] = G_PacketBuffer_ReadFloat(buf); + p->spin[2] = G_PacketBuffer_ReadFloat(buf); + p->spin[3] = G_PacketBuffer_ReadFloat(buf); + } } void G_PacketBuffer_WriteColorVector16(G_PacketBuffer *buf, Nvec3 color) @@ -322,3 +347,18 @@ return G_World_ResourceIndex_FromNetwork(G_PacketBuffer_Read32(buf)); } +void G_PacketBuffer_WriteEntityAsIndex(G_PacketBuffer *buf, G_Entity *entity) +{ + G_PacketBuffer_Write16(buf, entity - G.entities); +} + +G_Entity *G_PacketBuffer_ReadEntityAsIndex(G_PacketBuffer *buf) +{ + NUint32 index; + index = G_PacketBuffer_Read16(buf); + if (index >= G_MAX_ENTITIES) + return NULL; + if (G.client_networkentityindex[index] < 0) + return NULL; + return G.entities + G.client_networkentityindex[index]; +} Modified: trunk/game/g_packetbuffer.h =================================================================== --- trunk/game/g_packetbuffer.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_packetbuffer.h 2006-03-27 09:16:27 UTC (rev 685) @@ -51,8 +51,10 @@ Nsize G_PacketBuffer_ReadBytes(G_PacketBuffer *buf, NUint8 *buffer, Nsize buffersize); // functions for more specialized data types: -void G_PacketBuffer_WriteMatrix(G_PacketBuffer *buf, matrix4x4_t *matrix, Nbool sendorigin, Nbool sendrotation, Nbool sendscale); -void G_PacketBuffer_ReadMatrix(G_PacketBuffer *buf, matrix4x4_t *matrix, Nbool sendorigin, Nbool sendrotation, Nbool sendscale); +struct G_Entity_Position; +struct G_Entity; +void G_PacketBuffer_WritePosition(G_PacketBuffer *buf, struct G_Entity_Position *p, Nbool sendorigin, Nbool sendrotation, Nbool sendscale, Nbool sendvelocity, Nbool sendspin); +void G_PacketBuffer_ReadPosition(G_PacketBuffer *buf, struct G_Entity_Position *p, Nbool sendorigin, Nbool sendrotation, Nbool sendscale, Nbool sendvelocity, Nbool sendspin); void G_PacketBuffer_WriteColorVector16(G_PacketBuffer *buf, Nvec3 color); void G_PacketBuffer_ReadColorVector16(G_PacketBuffer *buf, Nvec3 color); void G_PacketBuffer_WriteClamped8(G_PacketBuffer *buf, Nvec f, Nvec scale); @@ -61,6 +63,8 @@ void G_PacketBuffer_ReadAngles16(G_PacketBuffer *buf, Nvec3 angles); void G_PacketBuffer_WriteBool(G_PacketBuffer *buf, NUint32 i); Nbool G_PacketBuffer_ReadBool(G_PacketBuffer *buf); +void G_PacketBuffer_WriteEntityAsIndex(G_PacketBuffer *buf, struct G_Entity *entity); +struct G_Entity *G_PacketBuffer_ReadEntityAsIndex(G_PacketBuffer *buf); // nocache versions send the actual name string (type has to be known by the reader) void G_PacketBuffer_WriteResourceIndex_NoCache(G_PacketBuffer *buf, NUint32 i); NUint32 G_PacketBuffer_ReadResourceIndex_NoCache(G_PacketBuffer *buf, NUint32 type); Modified: trunk/game/g_render.c =================================================================== --- trunk/game/g_render.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_render.c 2006-03-27 09:16:27 UTC (rev 685) @@ -29,7 +29,7 @@ // TODO: verify the resource type is RESOURCETYPE_MODEL model = Resource_GetData(entity->modelindex); if (model) - R_SetEntity(&entity->matrix, entity->cullradius, entity->modelindex); + R_SetEntity(&entity->position.m, entity->cullradius, entity->modelindex); } if (!model) continue; @@ -64,7 +64,7 @@ if (currententity != entity) { currententity = entity; - R_SetEntity(&entity->matrix, entity->cullradius, entity->modelindex); + R_SetEntity(&entity->position.m, entity->cullradius, entity->modelindex); } mesh = model->meshes + surface->meshindex; material = Resource_GetData(mesh->resource_material); @@ -89,7 +89,7 @@ mode = R_DRAWMODE_LIT_LIGHTING; R_SetDrawMode(R_DRAWMODE_LIT_LIGHTING); } - R_SetLight(&light->matrix, light->lightcolor, light->lightcubemap, light->lightambientintensity, light->lightdiffuseintensity, light->lightspecularintensity); + R_SetLight(&light->position.m, light->lightcolor, light->lightcubemap, light->lightambientintensity, light->lightdiffuseintensity, light->lightspecularintensity); R_DrawMesh(mesh->resource_material, surface->meshindex, entity->transforms); } } @@ -389,11 +389,11 @@ light = G.drawview_lights[lnum]; // tell the renderer to prepare for light rendering - R_SetLight(&light->matrix, light->lightcolor, light->lightcubemap, light->lightambientintensity, light->lightdiffuseintensity, light->lightspecularintensity); + R_SetLight(&light->position.m, light->lightcolor, light->lightcubemap, light->lightambientintensity, light->lightdiffuseintensity, light->lightspecularintensity); // find all surfaces visible to the light - Matrix4x4_OriginFromMatrix(&light->matrix, lightorigin); - lightradius = Matrix4x4_ScaleFromMatrix(&light->matrix); + Matrix4x4_OriginFromMatrix(&light->position.m, lightorigin); + lightradius = Matrix4x4_ScaleFromMatrix(&light->position.m); G_Scope_VisibleSurfacesAndLights(G_SCOPE_RENDER_OPAQUE, lightorigin, lightradius, G_DRAWVIEW_SURFACES, G.drawview_light_surfaces, &G.drawview_light_numsurfaces, 0, NULL, NULL, false); // make lists by type from the visible surfaces Modified: trunk/game/g_world.c =================================================================== --- trunk/game/g_world.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/game/g_world.c 2006-03-27 09:16:27 UTC (rev 685) @@ -225,13 +225,18 @@ { NUint32 j; Util_ParseC_Thread thread; + NStringKeys keys; + G_Entity *entity; + const G_Entity_Class *eclass; char *key[2]; - G_Entity *entity; + Nvec3 origin, angles; + Nvec scale; + G_Entity_Position position; + Util_ParseC_SetUpThread(&thread, filedata, filesize); + StringKeys_Init(&keys, GS.memzone, 65536); key[0] = NULL; key[1] = NULL; - - Util_ParseC_SetUpThread(&thread, filedata, filesize); while (thread.type != UTIL_PARSEC_TOKENTYPE_EOF) { if (!Util_ParseC_MatchName(&thread, "{")) @@ -239,7 +244,12 @@ Console_Printf("G_SpawnFromEntityFile: expected {\n"); break; } - entity = G_Entity_New(NULL, G_EntityClass_ByNumber(0)); + StringKeys_Empty(&keys); + position = GS.identityposition; + eclass = NULL; + VectorClear(origin); + VectorClear(angles); + scale = 1; for (;;) { for (j = 0;j < 2;j++) @@ -265,21 +275,56 @@ } if (j < 2) break; - G_Entity_SetField(entity, key[0], key[1]); + if (!String_Compare(key[0], "classname")) + { + if (eclass) + Console_Printf("G_SpawnFromEntityFile: entity with multiple classnames\n"); + eclass = G_EntityClass_ByName(key[1]); + } + else if (!String_Compare(key[0], "origin")) + String_ToVector(key[1], origin, 3); + else if (!String_Compare(key[0], "angles")) + String_ToVector(key[1], angles, 3); + else if (!String_Compare(key[0], "scale")) + scale = String_ToDouble(key[1]); + else if (!String_Compare(key[0], "velocity")) + String_ToVector(key[1], position.velocity, 3); + else if (!String_Compare(key[0], "spin")) + String_ToVector(key[1], position.spin, 4); + StringKeys_SetKey(&keys, GS.memzone, key[0], key[1]); } + if (eclass) + { + const char *s; + Matrix4x4_CreateFromQuakeEntity(&position.m, origin[0], origin[1], origin[2], angles[0], angles[1], angles[2], scale); + // TODO: parse keys here? + entity = G_Entity_New(NULL, eclass, &position); + // set up the most general fields to save code in spawn functions + String_ToVector(StringKeys_GetValue(&keys, "color"), entity->lightcolor, 3); + if ((s = StringKeys_GetValue(&keys, "cubemap"))) + entity->lightcubemap = Resource_IndexForName(s, RESOURCETYPE_TEXTURE, 0, 0); + if ((s = StringKeys_GetValue(&keys, "model"))) + G_Entity_SetModel(entity, s); + // only keep keys if in editing mode + if (G.editing) + StringKeys_Clone(&entity->keys, GS.memzone, &keys); + } + else + Console_Printf("G_SpawnFromEntityFile: entity with no classname\n"); } - Util_ParseC_CleanUpThread(&thread); String_Free(&key[0]); String_Free(&key[1]); + StringKeys_FreeKeys(&keys); + Util_ParseC_CleanUpThread(&thread); } void G_World_SaveEntities(const char *filename) { - NUint32 i, j; + NUint32 i, j, keyindex; Nsize filesize; G_Entity *entity; - G_Entity_Field *field; char *filedata; + const char *key, *value; if (!G.editing) { // we can't save because the entity fields were destroyed at load, and @@ -294,15 +339,16 @@ { // TODO: optimize this to buffer a bit rather than using String_Append? String_Append(&filedata, GS.memzone, "{\n"); - for (field = entity->fields;field;field = field->next) + keyindex = 0; + for (keyindex = 0;StringKeys_GetByNumber(&entity->keys, keyindex, &key, &value);keyindex++) { // FIXME: field->key is pretty safe but key->value may contain // control characters like \n, these need to be converted to // escape sequences. String_Append(&filedata, GS.memzone, "\t\""); - String_Append(&filedata, GS.memzone, field->key); + String_Append(&filedata, GS.memzone, key); String_Append(&filedata, GS.memzone, "\" \""); - String_Append(&filedata, GS.memzone, field->value); + String_Append(&filedata, GS.memzone, value); String_Append(&filedata, GS.memzone, "\"\n"); } String_Append(&filedata, GS.memzone, "}\n"); @@ -336,8 +382,8 @@ Mem_Free(&filedata); for (i = 0;i < G_MAX_ENTITIES;i++) - if (G.entities[i].eclass && G.entities[i].fields) - G_Entity_SpawnFromFields(G.entities + i); + if (G.entities[i].eclass) + G_Entity_Spawn(G.entities + i); // TODO: add team entities // if no teams were defined by entities, set up default teams @@ -438,7 +484,7 @@ G.time += G.frametime; // execute entity think code for (i = 0, entity = G.entities;i < G.numentities;i++, entity++) - if (entity->eclass && entity->eclass->codeclass && entity->eclass->codeclass->framecallback) + if (entity->eclass && entity->eclass->codeclass->framecallback) entity->eclass->codeclass->framecallback(entity); // TODO: call physics #if 0 @@ -459,18 +505,19 @@ { G_Entity *player; G_Entity *spot; + G_Entity_Position position; + // TODO: better spawn point selection + spot = G_Entity_Find_CodeName(NULL, "spawninfantry"); + if (spot) + position = spot->position; + else + position = GS.identityposition; // set up player entity for this user - player = G_Entity_New(NULL, G_EntityClass_ByName("infantry")); + player = G_Entity_New(NULL, G_EntityClass_ByName("infantry"), &position); player->localuserindex = user - GS.users; G.users[player->localuserindex].teamindex = 1; G.users[player->localuserindex].score = 0; //G.users[player->localuserindex].entityindex = player - G.entities; - // TODO: better spawn point selection - spot = G_Entity_Find_CodeName(NULL, "spawninfantry"); - if (spot) - player->matrix = spot->matrix; - else - Matrix4x4_CreateIdentity(&player->matrix); G_Entity_Spawn(player); } @@ -546,8 +593,8 @@ continue; if (e == trace->moveentity) continue; - Matrix4x4_Invert_Simple(&imatrix, &e->matrix); - Collision_Trace_Begin(&collisiontrace, &e->matrix, &imatrix, &startbrush, &endbrush, 1.0/32.0); + Matrix4x4_Invert_Simple(&imatrix, &e->position.m); + Collision_Trace_Begin(&collisiontrace, &e->position.m, &imatrix, &startbrush, &endbrush, 1.0/32.0); if (e->collisionbrush.numpoints) Collision_Trace_CheckBrushes(&collisiontrace, 1, &e->collisionbrush, &e->collisionbrush); else if (e->surfacelist) Modified: trunk/mathlib.h =================================================================== --- trunk/mathlib.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/mathlib.h 2006-03-27 09:16:27 UTC (rev 685) @@ -16,31 +16,69 @@ #define RAD2DEG(a) ((a) * (180.0 / M_PI)) #define VectorNegate(a,b) ((b)[0]=-((a)[0]),(b)[1]=-((a)[1]),(b)[2]=-((a)[2])) +#define Vector2Negate(a,b) ((b)[0]=-((a)[0]),(b)[1]=-((a)[1])) +#define Vector4Negate(a,b) ((b)[0]=-((a)[0]),(b)[1]=-((a)[1]),(b)[2]=-((a)[2]),(b)[3]=-((a)[3])) #define VectorSet(a,b,c,d) ((a)[0]=(b),(a)[1]=(c),(a)[2]=(d)) +#define Vector2Set(a,b,c) ((a)[0]=(b),(a)[1]=(c)) +#define Vector4Set(a,b,c,d,e) ((a)[0]=(b),(a)[1]=(c),(a)[2]=(d),(a)[3]=(e)) #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0) -#define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]) -#define DotProduct4(a,b) ((a)[0] * (b)[0] + (a)[1] * (b)[1] + (a)[2] * (b)[2] + (a)[3] * (b)[3]) +#define Vector2Clear(a) ((a)[0]=(a)[1]=0) +#define Vector4Clear(a) ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0) #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2]) +#define Vector2Subtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1]) +#define Vector4Subtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2],(c)[3]=(a)[3]-(b)[3]) #define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2]) +#define Vector2Add(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1]) +#define Vector4Add(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2],(c)[2]=(a)[3]+(b)[3]) #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2]) +#define Vector2Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1]) +#define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3]) #define VectorMultiply(a,b,c) ((c)[0]=(a)[0]*(b)[0],(c)[1]=(a)[1]*(b)[1],(c)[2]=(a)[2]*(b)[2]) -#define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0]) -#define VectorNormalize(v) do{float ilength = (float) sqrt(DotProduct(v,v));if (ilength) {ilength = 1.0f / ilength;VectorScale(v, ilength, v);}}while(0) -#define VectorNormalizeDouble(v) do{double ilength = sqrt(DotProduct(v,v));if (ilength) {ilength = 1.0 / ilength;VectorScale(v, ilength, v);}}while(0) +#define Vector2Multiply(a,b,c) ((c)[0]=(a)[0]*(b)[0],(c)[1]=(a)[1]*(b)[1]) +#define Vector4Multiply(a,b,c) ((c)[0]=(a)[0]*(b)[0],(c)[1]=(a)[1]*(b)[1],(c)[2]=(a)[2]*(b)[2],(c)[3]=(a)[3]*(b)[3]) +#define VectorNormalize(v) do{double ilength = sqrt(DotProduct(v,v));if (ilength) {ilength = 1.0 / ilength;VectorScale(v, ilength, v);}}while(0) +#define Vector2Normalize(v) do{double ilength = sqrt(DotProduct2(v,v));if (ilength) {ilength = 1.0 / ilength;Vector2Scale(v, ilength, v);}}while(0) +#define Vector4Normalize(v) do{double ilength = sqrt(DotProduct4(v,v));if (ilength) {ilength = 1.0 / ilength;Vector4Scale(v, ilength, v);}}while(0) #define VectorDistance2(a, b) (((a)[0] - (b)[0]) * ((a)[0] - (b)[0]) + ((a)[1] - (b)[1]) * ((a)[1] - (b)[1]) + ((a)[2] - (b)[2]) * ((a)[2] - (b)[2])) +#define Vector2Distance2(a, b) (((a)[0] - (b)[0]) * ((a)[0] - (b)[0]) + ((a)[1] - (b)[1]) * ((a)[1] - (b)[1])) +#define Vector4Distance2(a, b) (((a)[0] - (b)[0]) * ((a)[0] - (b)[0]) + ((a)[1] - (b)[1]) * ((a)[1] - (b)[1]) + ((a)[2] - (b)[2]) * ((a)[2] - (b)[2]) + ((a)[3] - (b)[3]) * ((a)[3] - (b)[3])) #define VectorDistance(a, b) (sqrt(VectorDistance2(a,b))) -#define VectorLength(a) (sqrt(DotProduct(a, a))) +#define Vector2Distance(a, b) (sqrt(Vector2Distance2(a,b))) +#define Vector4Distance(a, b) (sqrt(Vector4Distance2(a,b))) #define VectorLength2(a) (DotProduct(a, a)) +#define Vector2Length2(a) (DotProduct2(a, a)) +#define Vector4Length2(a) (DotProduct4(a, a)) +#define VectorLength(a) (sqrt(VectorLength2(a))) +#define Vector2Length(a) (sqrt(Vector2Length2(a))) +#define Vector4Length(a) (sqrt(Vector4Length2(a))) #define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale)) +#define Vector2Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale)) +#define Vector4Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale),(out)[3] = (in)[3] * (scale)) #define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2])) +#define Vector2Compare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])) +#define Vector4Compare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2])&&((a)[3]==(b)[3])) #define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2]) +#define Vector2MA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1]) +#define Vector4MA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2],(c)[3] = (a)[3] + (scale) * (b)[3]) #define VectorRandom(v) do{(v)[0] = Random(-1, 1);(v)[1] = Random(-1, 1);(v)[2] = Random(-1, 1);}while(DotProduct(v, v) > 1) +#define Vector2Random(v) do{(v)[0] = Random(-1, 1);(v)[1] = Random(-1, 1);}while(DotProduct2(v, v) > 1) +#define Vector4Random(v) do{(v)[0] = Random(-1, 1);(v)[1] = Random(-1, 1);(v)[2] = Random(-1, 1);(v)[3] = Random(-1, 1);}while(DotProduct4(v, v) > 1) #define VectorLerp(v1,lerp,v2,c) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (c)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2])) +#define Vector2Lerp(v1,lerp,v2,c) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1])) +#define Vector4Lerp(v1,lerp,v2,c) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (c)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2]), (c)[3] = (v1)[3] + (lerp) * ((v2)[3] - (v1)[3])) +#define VectorReflect(a,r,b,c) do{Nvec d;d = DotProduct((a), (b)) * -(1.0 + (r));VectorMA((a), (d), (b), (c));}while(0) +#define Vector2Reflect(a,r,b,c) do{Nvec d;d = DotProduct2((a), (b)) * -(1.0 + (r));Vector2MA((a), (d), (b), (c));}while(0) + +#define DotProduct(a,b) ((a)[0] * (b)[0] + (a)[1] * (b)[1] + (a)[2] * (b)[2]) +#define DotProduct2(a,b) ((a)[0] * (b)[0] + (a)[1] * (b)[1]) +#define DotProduct4(a,b) ((a)[0] * (b)[0] + (a)[1] * (b)[1] + (a)[2] * (b)[2] + (a)[3] * (b)[3]) +#define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0]) #define BoxesOverlap(a,b,c,d) ((a)[0] <= (d)[0] && (b)[0] >= (c)[0] && (a)[1] <= (d)[1] && (b)[1] >= (c)[1] && (a)[2] <= (d)[2] && (b)[2] >= (c)[2]) +#define BoxesOverlap2(a,b,c,d) ((a)[0] <= (d)[0] && (b)[0] >= (c)[0] && (a)[1] <= (d)[1] && (b)[1] >= (c)[1]) #define SpheresOverlap(a,b,c,d) (VectorDistance2(a,c) < (b*b+d*d)) +#define CirclesOverlap(a,b,c,d) (Vector2Distance2(a,c) < (b*b+d*d)) #define TriangleNormal(a,b,c,n) ((n)[0] = ((a)[2] - (b)[2]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[2] - (b)[2]), (n)[1] = ((a)[0] - (b)[0]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[0] - (b)[0]), (n)[2] = ((a)[1] - (b)[1]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[1] - (b)[1])) #define PointInfrontOfTriangle(p,a,b,c) (((p)[0] - (a)[0]) * (((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1])) + ((p)[1] - (a)[1]) * (((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2])) + ((p)[2] - (a)[2]) * (((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0])) > 0) -#define VectorReflect(a,r,b,c) do{Nvec d;d = DotProduct((a), (b)) * -(1.0 + (r));VectorMA((a), (d), (b), (c));}while(0) // conversion of a quaternion to 3 components by making it canonical (there are two equivilant representations of any quaternion depending on the sign of w, negative or positive w can be eliminated by negating xyz, thus reducing a normalized quaternion to xyz with an easily calculated w) #define Quat4ToQuat3(a,b) ((a)[3] > 0 ? VectorNegate((a),(b)) : VectorCopy((a),(b))) Modified: trunk/model.c =================================================================== --- trunk/model.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/model.c 2006-03-27 09:16:27 UTC (rev 685) @@ -212,18 +212,6 @@ } Model_MD5_Weight; -// LordHavoc: I got this code from: -//http://www.doom3world.org/phpbb2/viewtopic.php?t=2884 -static void Model_Doom3Joint6ToMatrix(double *b, matrix4x4_t *m) -{ - double x = b[3], y = b[4], z = b[5], w = 1.0 - DotProduct(b + 3, b + 3); - w = w > 0.0 ? -sqrt(w) : 0.0; - m->m[0][0]= 1-2*((y*y)+(z*z)) ;m->m[0][1]= 2*((x*y)-(z*w)) ;m->m[0][2]= 2*((x*z)+(y*w)) ;m->m[0][3]=b[0]; - m->m[1][0]= 2*((x*y)+(z*w)) ;m->m[1][1]= 1-2*((x*x)+(z*z)) ;m->m[1][2]= 2*((y*z)-(x*w)) ;m->m[1][3]=b[1]; - m->m[2][0]= 2*((x*z)-(y*w)) ;m->m[2][1]= 2*((y*z)+(x*w)) ;m->m[2][2]= 1-2*((x*x)+(y*y)) ;m->m[2][3]=b[2]; - m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]= 1; -} - void Model_Load(ResourceEntry *r) { Util_ParseC_Thread thread; @@ -296,6 +284,7 @@ model->transformnames = Mem_Alloc(r->memzone, model->numtransforms * sizeof(*model->transformnames)); model->transformradius = Mem_Alloc(r->memzone, model->numtransforms * sizeof(*model->transformradius)); model->basetransforms = Mem_Alloc(r->memzone, model->numtransforms * sizeof(*model->basetransforms)); + model->baseinversetransforms = Mem_Alloc(r->memzone, model->numtransforms * sizeof(*model->baseinversetransforms)); } //numMeshes 1 else if (Util_ParseC_MatchKeyword(&thread, "numMeshes")) @@ -334,7 +323,8 @@ LoadValue(joint6[4], "(joint 4)"); LoadValue(joint6[5], "(joint 5)"); ExpectKeyword(")", "after second joint data list"); - Model_Doom3Joint6ToMatrix(joint6, &model->basetransforms[jointnum]); + Matrix4x4_CreateFromDoom3Joint(&model->basetransforms[jointnum], joint6[0], joint6[1], joint6[2], joint6[3], joint6[4], joint6[5]); + Matrix4x4_Invert_Simple(&model->baseinversetransforms[jointnum], &model->basetransforms[jointnum]); if (parent >= (NSint32)jointnum) { Console_Printf("Model_Load: joint.parent (%i) >= joint (%i)\n", parent, jointnum); @@ -343,7 +333,7 @@ } if (jointnum != model->numtransforms) { - Console_Printf("Model_Load: final jointnum (%i) != numjuoints (%i)\n", jointnum, model->numtransforms); + Console_Printf("Model_Load: final jointnum (%i) != numJoints (%i)\n", jointnum, model->numtransforms); Abort(); } } @@ -814,6 +804,19 @@ } } +NSint32 Model_GetTransformNumberForName(NUint32 modelresource, const char *name) +{ + NUint32 i; + Model *model; + model = Resource_GetData(modelresource); + if (!model) + return -1; // no model + for (i = 0;i < model->numtransforms;i++) + if (!String_Compare(model->transformnames[i], name)) + return i; + return -1; +} + /* // TODO: data hiding or not? Modified: trunk/model.h =================================================================== --- trunk/model.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/model.h 2006-03-27 09:16:27 UTC (rev 685) @@ -84,6 +84,7 @@ char **transformnames; float *transformradius; matrix4x4_t *basetransforms; + matrix4x4_t *baseinversetransforms; Nvec3 basecullmins; Nvec3 basecullmaxs; @@ -98,6 +99,7 @@ void Model_GetVertices(Model_Mesh *mesh, const matrix4x4_t *transforms, float *outvertex3f, float *outsvector3f, float *outtvector3f, float *outnormal3f, float *outplane4f); void Model_GetCullBox(NUint32 modelresource, const matrix4x4_t *transforms, Nvec3 cullmins, Nvec3 cullmaxs); void Model_GetMeshCullBox(NUint32 modelresource, NUint32 meshindex, const matrix4x4_t *transforms, Nvec3 cullmins, Nvec3 cullmaxs); +NSint32 Model_GetTransformNumberForName(NUint32 modelresource, const char *name); #endif Added: trunk/modelanim.c =================================================================== --- trunk/modelanim.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/modelanim.c 2006-03-27 09:16:27 UTC (rev 685) @@ -0,0 +1,352 @@ + +#include "ncommon.h" +#include "model.h" +#include "modelanim.h" +#include "util.h" + +/* example clips of an MD5 anim +MD5Version 10 +commandline "" +numFrames 21 +numJoints 3 +frameRate 30 +numAnimatedComponents 18 +hierarchy { + "root" -1 63 0 // + "weapon_link" 0 63 6 // root ( Tx Ty Tz Qx Qy Qz ) + "weapon_main" 1 63 12 // weapon_link ( Tx Ty Tz Qx Qy Qz ) +} +bounds { + ( -1.145777 -2.429096 -13.948964 ) ( 19.801897 4.962530 -5.251172 ) + ( -0.687599 -2.425639 -13.722960 ) ( 20.277922 5.083089 -4.994154 ) +... +} +baseframe { + ( 0.000000 0.000000 0.000000 ) ( -0.707107 0.000000 -0.000000 ) + ( 0.000000 0.000000 -1.200000 ) ( 0.375011 0.599472 0.375011 ) + ( -0.000000 0.000000 -12.343824 ) ( -0.681099 -0.000000 -0.000000 ) +} +frame 0 { + 0.000000 0.000000 0.000000 -0.707107 0.000000 -0.000000 + 0.000000 0.000000 -1.200000 0.375011 0.599472 0.375011 + -0.000000 0.000000 -12.343824 -0.681099 -0.000000 -0.000000 +} +... +*/ + +void ModelAnim_Load(ResourceEntry *r) +{ + Util_ParseC_Thread thread; + NUint32 meshnum, version; + Nbool error; + Nsize filesize; + ModelAnim *modelanim; + char *filedata; + + modelanim = Mem_Alloc(r->memzone, sizeof(ModelAnim)); + + filedata = File_LoadFile(r->name, &filesize); + if (!filedata) + return; + + Util_ParseC_SetUpThread(&thread, filedata, filesize); + +#define Abort() { error = true; break; } +#define LoadValue(var, errstr) if (thread.type != UTIL_PARSEC_TOKENTYPE_VALUE) { \ + Console_Printf("ModelAnim_Load: Expected value " errstr "\n"); Abort(); \ + } else \ + (var) = thread.value, Util_ParseC_Lex(&thread) + +#define LoadInt(var, errstr) if (thread.type != UTIL_PARSEC_TOKENTYPE_VALUE) { \ + Console_Printf("ModelAnim_Load: Expected integer " errstr "\n"); Abort(); \ + } else \ + (var) = thread.value, Util_ParseC_Lex(&thread) + +#define LoadString(var, errstr) if (thread.type != UTIL_PARSEC_TOKENTYPE_STRING) { \ + Console_Printf("ModelAnim_Load: Expected string " errstr "\n"); Abort(); \ + } else \ + String_Set( &(var), r->memzone, thread.token), Util_ParseC_Lex(&thread) + +#define ExpectKeyword(str, errstr) if (!Util_ParseC_MatchName(&thread, (str))) { \ + Console_Printf("ModelAnim_Load: Expected '" str "' " errstr "\n"); Abort(); } + + version = 0; + meshnum = 0; + error = false; + + while (!error && thread.type != UTIL_PARSEC_TOKENTYPE_EOF) + { + //MD5Version 10 + if (Util_ParseC_MatchKeyword(&thread, "MD5Version")) + { + LoadInt(version, "after 'MD5Version'"); + if (version != 10) + { + Console_Printf("ModelAnim_Load: MD5Version %i not supported\n", version); + Abort(); + } + } + //commandline "" + else if (Util_ParseC_MatchKeyword(&thread, "commandline")) + { + Util_ParseC_Lex(&thread); + } + //numFrames 21 + else if (Util_ParseC_MatchKeyword(&thread, "numFrames")) + { + LoadInt(modelanim->numframes, "after 'numFrames'"); + if (modelanim->numframes < 1) + { + Console_Printf("ModelAnim_Load: numFrames %i < 1\n", modelanim->numframes); + Abort(); + } + } + //numJoints 3 + else if (Util_ParseC_MatchKeyword(&thread, "numJoints")) + { + LoadInt(modelanim->numtransforms, "after 'numJoints'"); + if (modelanim->numtransforms < 1) + { + Console_Printf("ModelAnim_Load: numJoints %i < 1\n", modelanim->numtransforms); + Abort(); + } + } + //frameRate 30 + else if (Util_ParseC_MatchKeyword(&thread, "frameRate")) + { + LoadValue(modelanim->framerate, "after 'frameRate'"); + if (modelanim->framerate <= 0) + { + Console_Printf("ModelAnim_Load: frameRate %f <= 0\n", modelanim->framerate); + Abort(); + } + } + //numAnimatedComponents 18 + else if (Util_ParseC_MatchKeyword(&thread, "numAnimatedComponents")) + { + LoadInt(modelanim->numvaluesperframe, "after 'numAnimatedComponents'"); + if (modelanim->numvaluesperframe < 0) + { + Console_Printf("ModelAnim_Load: numAnimatedComponents %i < 0\n", modelanim->numvaluesperframe); + Abort(); + } + if (modelanim->numvaluesperframe > modelanim->numtransforms * 6) + { + Console_Printf("ModelAnim_Load: numAnimatedComponents %i > numJoints * 6\n", modelanim->numvaluesperframe); + Abort(); + } + } + //hierarchy { + else if (Util_ParseC_MatchKeyword(&thread, "hierarchy")) + { + NUint32 jointnum; + ExpectKeyword("{", "after 'hierarchy'"); + modelanim->transforminfo = Mem_Alloc(r->memzone, modelanim->numtransforms * sizeof(*modelanim->transforminfo)); + for (jointnum = 0; !Util_ParseC_MatchKeyword(&thread, "}");jointnum++) + { + NSint32 parent; + NUint32 componentflags; + NUint32 numcomponents; + NUint32 firstcomponent; + NUint32 componentindex; + // "weapon_link" 0 63 6 // root ( Tx Ty Tz Qx Qy Qz ) + LoadString(modelanim->transforminfo[jointnum].name, "for joint name"); + LoadInt(parent, "as parent"); + LoadInt(componentflags, "component flags"); + LoadInt(firstcomponent, "first component index"); + if (parent >= (NSint32)jointnum) + { + Console_Printf("ModelAnim_Load: joint.parent (%i) >= joint (%i)\n", parent, jointnum); + Abort(); + } + if (componentflags & ~63) + { + Console_Printf("ModelAnim_Load: joint[%i].componentflags < 0 || componentflags > 63\n", jointnum); + Abort(); + } + numcomponents = 0; + for (componentindex = 0;componentindex < 6;componentindex++) + if (componentflags & (1< modelanim->numvaluesperframe) + { + Console_Printf("ModelAnim_Load: joint[%i].firstcomponent < 0 || firstcomponent + numcomponents > numAnimatedComponents\n", jointnum); + Abort(); + } + modelanim->transforminfo[jointnum].parentindex = parent; + modelanim->transforminfo[jointnum].valueflags = componentflags; + modelanim->transforminfo[jointnum].firstvalue = firstcomponent; + modelanim->transforminfo[jointnum].numvalues = numcomponents; + } + if (jointnum != modelanim->numtransforms) + { + Console_Printf("ModelAnim_Load: final jointnum (%i) != numJoints (%i)\n", jointnum, modelanim->numtransforms); + Abort(); + } + } + //bounds { + else if (Util_ParseC_MatchKeyword(&thread, "bounds")) + { + NUint32 framenum; + ExpectKeyword("{", "after 'bounds'"); + for (framenum = 0; !Util_ParseC_MatchKeyword(&thread, "}");framenum++) + { + Nvec3 mins, maxs; + // ( -1.145777 -2.429096 -13.948964 ) ( 19.801897 4.962530 -5.251172 ) + ExpectKeyword("(", "before minimum corner of frame box"); + LoadValue(mins[0], "(mins[0])"); + LoadValue(mins[1], "(mins[1])"); + LoadValue(mins[2], "(mins[2])"); + ExpectKeyword(")", "after minimum corner of frame box"); + ExpectKeyword("(", "before maximum corner of frame box"); + LoadValue(maxs[0], "(maxs[0])"); + LoadValue(maxs[1], "(maxs[1])"); + LoadValue(maxs[2], "(maxs[2])"); + ExpectKeyword(")", "after maximum corner of frame box"); + } + if (framenum != modelanim->numframes) + { + Console_Printf("ModelAnim_Load: final framenum (%i) != numFrames (%i)\n", framenum, modelanim->numframes); + Abort(); + } + } + //baseframe { + else if (Util_ParseC_MatchKeyword(&thread, "baseframe")) + { + NUint32 jointnum; + ExpectKeyword("{", "after 'baseframe'"); + modelanim->basevalues = Mem_Alloc(r->memzone, modelanim->numtransforms * 6 * sizeof(*modelanim->basevalues)); + modelanim->values = Mem_Alloc(r->memzone, modelanim->numframes * modelanim->numvaluesperframe * sizeof(*modelanim->values)); + for (jointnum = 0; !Util_ParseC_MatchKeyword(&thread, "}");jointnum++) + { + // ( 0.000000 0.000000 0.000000 ) ( -0.707107 0.000000 -0.000000 ) + ExpectKeyword("(", "before first joint data list"); + LoadValue(modelanim->basevalues[jointnum*6+0], "(joint 0)"); + LoadValue(modelanim->basevalues[jointnum*6+1], "(joint 1)"); + LoadValue(modelanim->basevalues[jointnum*6+2], "(joint 2)"); + ExpectKeyword(")", "after first joint data list"); + ExpectKeyword("(", "before second joint data list"); + LoadValue(modelanim->basevalues[jointnum*6+3], "(joint 3)"); + LoadValue(modelanim->basevalues[jointnum*6+4], "(joint 4)"); + LoadValue(modelanim->basevalues[jointnum*6+5], "(joint 5)"); + ExpectKeyword(")", "after second joint data list"); + } + if (jointnum != modelanim->numtransforms) + { + Console_Printf("ModelAnim_Load: final jointnum (%i) != numJoints (%i)\n", jointnum, modelanim->numtransforms); + Abort(); + } + } + //frame 0 { + else if (Util_ParseC_MatchKeyword(&thread, "frame")) + { + NUint32 framenum; + NUint32 valuenum; + float *values; + LoadInt(framenum, "number of frames"); + if (framenum < 0 || framenum >= modelanim->numframes) + { + Console_Printf("ModelAnim_Load: frame number %i < 0 || frame number %i >= numFrames (%i)\n", framenum, framenum, modelanim->numframes); + Abort(); + } + ExpectKeyword("{", "after 'frame'"); + values = modelanim->values + framenum * modelanim->numvaluesperframe; + for (valuenum = 0; !Util_ParseC_MatchKeyword(&thread, "}");valuenum++) + { + if (valuenum >= modelanim->numvaluesperframe) + { + Console_Printf("ModelAnim_Load: too many components in frame %i\n", framenum); + Abort(); + } + LoadValue(values[valuenum], "component value"); + } + if (valuenum != modelanim->numvaluesperframe) + { + Console_Printf("ModelAnim_Load: final component (%i) != numAnimatedComponents (%i)\n", valuenum, modelanim->numvaluesperframe); + Abort(); + } + } + } + Util_ParseC_CleanUpThread(&thread); + Mem_Free(&filedata); + // if there was a load error, don't point to the Model so nothing will try + // to use the incomplete data + if (!error) + r->data = modelanim; +#undef Abort +#undef LoadInt +#undef LoadValue +#undef LoadString +#undef ExpectKeyword +} + +void ModelAnim_Unload(ResourceEntry *r) +{ + // freeing of the memzone will get rid of the modelanim +} + +NUint32 ModelAnim_GetNumTransforms(NUint32 resourceindex) +{ + ModelAnim *modelanim; + modelanim = Resource_GetData(resourceindex); + if (!modelanim) + return 0; // no modelanim + return modelanim->numtransforms; +} + +NUint32 ModelAnim_GetNumFrames(NUint32 resourceindex) +{ + ModelAnim *modelanim; + modelanim = Resource_GetData(resourceindex); + if (!modelanim) + return 0; // no modelanim + return modelanim->numframes; +} + +double ModelAnim_GetFrameRate(NUint32 resourceindex) +{ + ModelAnim *modelanim; + modelanim = Resource_GetData(resourceindex); + if (!modelanim) + return 0; // no modelanim + return modelanim->framerate; +} + +void ModelAnim_BlendPoses(NUint32 modelanimresource, NUint32 modelresource, NUint32 frame1, NUint32 frame2, float framelerp, matrix4x4_t *transforms, Nbool clearfirst) +{ + NUint32 transformnum; + float iframelerp = 1 - framelerp; + const float *v1, *v2, *b; + Model *model; + ModelAnim *modelanim; + ModelAnim_TransformInfo *info; + modelanim = Resource_GetData(modelanimresource); + if (!modelanim) + return; // no modelanim + model = Resource_GetData(modelresource); + if (!model) + return; // no model + if (model->numtransforms != modelanim->numtransforms) + return; // error + v1 = modelanim->values + frame1 * modelanim->numvaluesperframe; + v2 = modelanim->values + frame2 * modelanim->numvaluesperframe; + b = modelanim->basevalues; + for (transformnum = 0, info = modelanim->transforminfo;transformnum < modelanim->numtransforms;transformnum++, info++, b += 6) + { + NUint32 component; + NUint32 valueflags = info->valueflags; + const float *f1 = v1 + info->firstvalue; + const float *f2 = v2 + info->firstvalue; + float pose[6]; + matrix4x4_t posematrix, relativematrix; + for (component = 0;component < 6;component++) + { + if (valueflags & (1<baseinversetransforms[transformnum]); + } +} Added: trunk/modelanim.h =================================================================== --- trunk/modelanim.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/modelanim.h 2006-03-27 09:16:27 UTC (rev 685) @@ -0,0 +1,35 @@ + +typedef struct ModelAnim_TransformInfo +{ + char *name; + NUint32 parentindex; + NUint32 valueflags; + NUint32 firstvalue; + NUint32 numvalues; +} +ModelAnim_TransformInfo; + +typedef struct ModelAnim +{ + // md5anim files store a baseline (default values) of the entire joint set, + // and then flags for which values are animated, since most of the joint + // set is unchanging in most animations + // each joint is 6 values (3 location, 3 quaternion) + // the quaternions are stored as canonical unit vectors in which w is + // assumed to be negative (it is easy to regenerate any one component of a + // unit vector if you know its sign) + NUint32 numtransforms; + NUint32 numvaluesperframe; + NUint32 numframes; + float framerate; + ModelAnim_TransformInfo *transforminfo; // [numtransforms] + float *values; // [numframes*numvaluesperframe] + float *basevalues; // [numtransforms*6] +} +ModelAnim; + +void ModelAnim_Load(ResourceEntry *r); +void ModelAnim_Unload(ResourceEntry *r); + +NUint32 ModelAnim_GetNumTransforms(NUint32 resourceindex); +void ModelAnim_GetTransforms(NUint32 resourceindex, NUint32 frame1, NUint32 frame2, float framelerp, matrix4x4_t *transforms); Modified: trunk/resource.c =================================================================== --- trunk/resource.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/resource.c 2006-03-27 09:16:27 UTC (rev 685) @@ -2,6 +2,7 @@ #include "ncommon.h" #include "material.h" #include "model.h" +#include "modelanim.h" #include "sound.h" #include "texture.h" #include "video.h" @@ -182,6 +183,9 @@ case RESOURCETYPE_MODEL: Model_Load(r); break; + case RESOURCETYPE_MODELANIM: + ModelAnim_Load(r); + break; case RESOURCETYPE_SOUND: Sound_Load(r); break; @@ -221,6 +225,9 @@ case RESOURCETYPE_MODEL: Model_Unload(r); break; + case RESOURCETYPE_MODELANIM: + ModelAnim_Unload(r); + break; case RESOURCETYPE_SOUND: Sound_Unload(r); break; Modified: trunk/resource.h =================================================================== --- trunk/resource.h 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/resource.h 2006-03-27 09:16:27 UTC (rev 685) @@ -28,6 +28,7 @@ { RESOURCETYPE_INVALID = 0, RESOURCETYPE_MODEL, + RESOURCETYPE_MODELANIM, RESOURCETYPE_SOUND, RESOURCETYPE_MATERIAL, RESOURCETYPE_TEXTURE, Modified: trunk/system.c =================================================================== --- trunk/system.c 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/system.c 2006-03-27 09:16:27 UTC (rev 685) @@ -30,6 +30,20 @@ R_Quit(); if (openglmode) { + // hack to work around SDL not resetting the SDL_GL_SetAttribute stuff + // until we open a non-GL window + if (Video.running) + { + if (Video.openglmode) + DynGL_CloseLibrary(); + SDL_WM_SetCaption ("DarkWar", "DarkWar"); + Video_Surface = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0)); + if (!Video_Surface) + { + Console_Printf("Could not open video: %s.\n", SDL_GetError()); + return false; + } + } if (!DynGL_LoadLibrary(NULL)) { char *error = SDL_GetError(); @@ -71,7 +85,8 @@ Video.fullscreen = fullscreen; Video.openglmode = openglmode; Video.framecount = 0; - DynGL_GetFunctions(NULL); + if (openglmode) + DynGL_GetFunctions(NULL); R_Init(); Input.hasfocus = true; //this ought to be true just after initialization (SDL doesn't seem to tell us either way). Modified: trunk/todo =================================================================== --- trunk/todo 2006-03-27 09:14:49 UTC (rev 684) +++ trunk/todo 2006-03-27 09:16:27 UTC (rev 685) @@ -15,3 +15,4 @@ d bug darkwar console: cursoring left on the commandline and editing the text discards the rest of the line d change darkwar drawview: redesign G_DrawView to cull surfaces of entities d change darkwar util: util_maketerrain should emit only one md5mesh file with all the surfaces in it +0 bug darkwar networking: attached entities should add dependencies to their owner so that if the owner update is lost and no more recent update of the child exists it forces an update of the child so that the child can attach properly \ No newline at end of file From lordhavoc at icculus.org Mon Mar 27 16:28:02 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 27 Mar 2006 16:28:02 -0500 Subject: r686 - trunk/game Message-ID: <20060327212802.13218.qmail@icculus.org> Author: lordhavoc Date: 2006-03-27 16:28:02 -0500 (Mon, 27 Mar 2006) New Revision: 686 Modified: trunk/game/g_entity.c trunk/game/g_entityclass.c Log: fix two botched search/replace things I forgot to fix before committing Modified: trunk/game/g_entity.c =================================================================== --- trunk/game/g_entity.c 2006-03-27 09:16:27 UTC (rev 685) +++ trunk/game/g_entity.c 2006-03-27 21:28:02 UTC (rev 686) @@ -149,7 +149,7 @@ void G_Entity_GetTransformMatrix(G_Entity *entity, NUint32 transformindex, matrix4x4_t *result) { - if (index >= 1 && index <= entity->numtransforms) + if (transformindex >= 1 && transformindex <= entity->numtransforms) Matrix4x4_Concat(result, &entity->position.m, entity->transforms + (transformindex - 1)); else *result = entity->position.m; @@ -160,7 +160,7 @@ matrix4x4_t parentmatrix; if (!entity->attachment_entity) return; - G_Entity_GetMatrix(entity->attachment_entity, entity->attachment_index, &parentmatrix); + G_Entity_GetTransformMatrix(entity->attachment_entity, entity->attachment_transformindex, &parentmatrix); Matrix4x4_Concat(&entity->position.m, &parentmatrix, &entity->attachment_matrix); G_Entity_Relink(entity); } Modified: trunk/game/g_entityclass.c =================================================================== --- trunk/game/g_entityclass.c 2006-03-27 09:16:27 UTC (rev 685) +++ trunk/game/g_entityclass.c 2006-03-27 21:28:02 UTC (rev 686) @@ -387,7 +387,7 @@ { G_PacketBuffer_WriteBool(buffer, true); G_PacketBuffer_WriteEntityAsIndex(buffer, self->owner); - G_PacketBuffer_Write16(buffer, self->attachment_index); + G_PacketBuffer_Write16(buffer, self->attachment_transformindex); } else G_PacketBuffer_WriteBool(buffer, false); @@ -401,7 +401,7 @@ if (G_PacketBuffer_ReadBool(buffer)) { self->owner = G_PacketBuffer_ReadEntityAsIndex(buffer); - self->attachment_index = G_PacketBuffer_Read16(buffer); + self->attachment_transformindex = G_PacketBuffer_Read16(buffer); } G_PacketBuffer_ReadClamped8(buffer, 255.0f / self->eclass->autorefire); } @@ -807,25 +807,25 @@ CSVCOLUMNINFO("NoRemove", noremove, CSVCOLUMNFIELDTYPE_BOOL), CSVCOLUMNINFO("Respawn", respawn, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("I0C", inventory[0].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I0B", inventory[0].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I0B", inventory[0].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I1C", inventory[1].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I1B", inventory[1].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I1B", inventory[1].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I2C", inventory[2].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I2B", inventory[2].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I2B", inventory[2].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I3C", inventory[3].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I3B", inventory[3].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I3B", inventory[3].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I4C", inventory[4].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I4B", inventory[4].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I4B", inventory[4].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I5C", inventory[5].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I5B", inventory[5].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I5B", inventory[5].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I6C", inventory[6].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I6B", inventory[6].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I6B", inventory[6].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I7C", inventory[7].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I7B", inventory[7].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I7B", inventory[7].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I8C", inventory[8].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I8B", inventory[8].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I8B", inventory[8].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("I9C", inventory[9].codename, CSVCOLUMNFIELDTYPE_CHARPOINTER), - CSVCOLUMNINFO("I9B", inventory[9].name, CSVCOLUMNFIELDTYPE_CHARPOINTER), + CSVCOLUMNINFO("I9B", inventory[9].transformname, CSVCOLUMNFIELDTYPE_CHARPOINTER), CSVCOLUMNINFO("AmmoMax", ammomax, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("AmmoRegen", ammoregen, CSVCOLUMNFIELDTYPE_NVEC), CSVCOLUMNINFO("Projectile", projectilecodename, CSVCOLUMNFIELDTYPE_CHARPOINTER), From lordhavoc at icculus.org Thu Mar 30 05:29:44 2006 From: lordhavoc at icculus.org (lordhavoc at icculus.org) Date: 30 Mar 2006 05:29:44 -0500 Subject: r687 - trunk Message-ID: <20060330102944.10950.qmail@icculus.org> Author: lordhavoc Date: 2006-03-30 05:29:44 -0500 (Thu, 30 Mar 2006) New Revision: 687 Modified: trunk/TODO.txt Log: fix a typo Modified: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2006-03-27 21:28:02 UTC (rev 686) +++ trunk/TODO.txt 2006-03-30 10:29:44 UTC (rev 687) @@ -11,7 +11,7 @@ Write the rest of DarkWar. -Mercury: (low priority) make dyngl have function stubs for GL debugging modes which can log all calls to a log file, or CheckGLError after every one (except during Begin...End where they would cause an error) thes should be enabled by commandline options (use stubs or direct calls) +Mercury: (low priority) make dyngl have function stubs for GL debugging modes which can log all calls to a log file, or CheckGLError after every one (except during Begin...End where they would cause an error) thes should be enabled by commandline options (use stubs or direct calls) (coderjoe) I decided to get started on this, since I didn't know what else to work on. question: should there be a compile-time flag to disable the stub system, in addition to the commandline flag? @@ -26,7 +26,7 @@ 0 80% system startup/shutdown 0 90% console rendering 0 90% console commands/cvars - 1 100% model loading + 1 100% model loading 1 10% model rendering 2 100% game: entity loading 2 0% game: input (binds) @@ -47,7 +47,7 @@ LISP. Yes. Seriously. LISP. alias blah (a = 5;print "blah!\n") // for average users -alias blah {a = 5;print("blah!"\n");} // for C programmers +alias blah {a = 5;print("blah!\n");} // for C programmers alias blah ((= a 5) (print "blah!\n")) // for slightly lazy LISP programmers (alias blah ((= a 5) (print "blah!\n"))) // for LISP programmers @@ -67,5 +67,5 @@ ============================================================================== input discussion -current bind theory - in_bind mouse axis0 " +current bind theory - in_bind mouse axis0 "