diff --git a/direct/src/dcparser/dcAtomicField.cxx b/direct/src/dcparser/dcAtomicField.cxx index e5da73031d..b776c384b6 100644 --- a/direct/src/dcparser/dcAtomicField.cxx +++ b/direct/src/dcparser/dcAtomicField.cxx @@ -204,6 +204,26 @@ end_array() { // These types accept arrays. return true; + case ST_uint32uint8array: + { + // In this special case type, we collapse every other 32-bit + // value down to an 8-bit value after formatting. + string new_value; + size_t p = 0; + while (p < _default_value.size()) { + // We should have at least 8 bytes for each two elements. If + // we don't, maybe the user gave us an odd number of elements. + if (p + 8 > _default_value.size()) { + return false; + } + new_value += _default_value.substr(p, 5); + p += 8; + } + + _default_value = new_value; + return true; + } + default: return false; } @@ -244,6 +264,7 @@ format_default_value(double num, string &formatted) const { case ST_uint32: case ST_int32array: case ST_uint32array: + case ST_uint32uint8array: formatted = string(1, (char)(int_value & 0xff)) + string(1, (char)((int_value >> 8) & 0xff)) + @@ -423,6 +444,7 @@ get_element_default(int n) const { case ST_uint8array: case ST_uint16array: case ST_uint32array: + case ST_uint32uint8array: case ST_blob: case ST_string: // These array types also want an implicit length. diff --git a/direct/src/dcparser/dcLexer.lxx b/direct/src/dcparser/dcLexer.lxx index 598cd092a6..4fdab47709 100644 --- a/direct/src/dcparser/dcLexer.lxx +++ b/direct/src/dcparser/dcLexer.lxx @@ -418,6 +418,11 @@ REALNUM ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?) return KW_UINT32ARRAY; } +"uint32uint8array" { + accept(); + return KW_UINT32UINT8ARRAY; +} + mol[0-9]+ { // A molecular keyword. accept(); diff --git a/direct/src/dcparser/dcParser.yxx b/direct/src/dcparser/dcParser.yxx index 7acf76b6e7..1fab618de9 100644 --- a/direct/src/dcparser/dcParser.yxx +++ b/direct/src/dcparser/dcParser.yxx @@ -65,6 +65,7 @@ dc_cleanup_parser() { %token KW_UINT8ARRAY %token KW_UINT16ARRAY %token KW_UINT32ARRAY +%token KW_UINT32UINT8ARRAY %token KW_MOL @@ -371,6 +372,10 @@ type_token: | KW_UINT32ARRAY { $$ = ST_uint32array; +} + | KW_UINT32UINT8ARRAY +{ + $$ = ST_uint32uint8array; } ; diff --git a/direct/src/dcparser/dcSubatomicType.cxx b/direct/src/dcparser/dcSubatomicType.cxx index 12e533b0c8..c5f49b2447 100644 --- a/direct/src/dcparser/dcSubatomicType.cxx +++ b/direct/src/dcparser/dcSubatomicType.cxx @@ -72,6 +72,9 @@ operator << (ostream &out, DCSubatomicType type) { case ST_uint32array: return out << "uint32array"; + case ST_uint32uint8array: + return out << "uint32uint8array"; + case ST_invalid: return out << "invalid"; } diff --git a/direct/src/dcparser/dcSubatomicType.h b/direct/src/dcparser/dcSubatomicType.h index 8e78c16ad5..14abafac5c 100644 --- a/direct/src/dcparser/dcSubatomicType.h +++ b/direct/src/dcparser/dcSubatomicType.h @@ -52,6 +52,10 @@ enum DCSubatomicType { ST_int8array, ST_uint8array, + // A special-purpose array: a list of alternating uint32 and uint8 + // values. In Python, this becomes a list of 2-tuples. + ST_uint32uint8array, + // New additions should be added at the end to prevent the file hash // code from changing.