From 60951c30868f75b071a1a4b9df9d1b76fb0655d0 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sat, 28 Nov 2020 16:08:21 +0000 Subject: [PATCH] pr_comp: Slightly improve commenting. Use explicit stdint types git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13049 d7cf8633-e32d-0410-b094-e92efae38249 --- pr_comp.h | 116 +++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/pr_comp.h b/pr_comp.h index d1ad4b7b..f69b6320 100644 --- a/pr_comp.h +++ b/pr_comp.h @@ -323,61 +323,68 @@ typedef enum opcode_e } opcode_t; - +// Statements (16 bit format) - 8 bytes each typedef struct statement16_s { - unsigned short op; - signed short a,b,c; + uint16_t op; + int16_t a, b, c; } dstatement16_t; + +// Statements (32 bit format) - 16 bytes each typedef struct statement32_s { - unsigned int op; - signed int a,b,c; + uint32_t op; + int32_t a, b, c; } dstatement32_t; +// Global and fielddefs (16 bit format) - 8 bytes each typedef struct ddef16_s { - unsigned short type; // if DEF_SAVEGLOBAL bit is set - // the variable needs to be saved in savegames - unsigned short ofs; - int s_name; + uint16_t type; // if DEF_SAVEGLOBAL bit is set + // the variable needs to be saved in savegames + uint16_t ofs; + int32_t s_name; } -ddef16_t; +ddef16_t, dfield16_t; + +// Global and fielddefs (32 bit format) - 12 bytes each typedef struct ddef32_s { - unsigned int type; // if DEF_SAVEGLOBAL bit is set - // the variable needs to be saved in savegames - unsigned int ofs; - int s_name; + uint32_t type; // if DEF_SAVEGLOBAL bit is set + // the variable needs to be saved in savegames + uint32_t ofs; + int32_t s_name; } -ddef32_t, mdef_t; +ddef32_t, dfield32_t, mdef_t; + #define DEF_SAVEGLOBAL (1<<15) #define MAX_PARMS 8 +// Functions - 36 bytes each typedef struct dfunction_s { - int first_statement; // negative numbers are builtins - int parm_start; - int locals; // total ints of parms + locals + int32_t first_statement; // negative numbers are builtins + int32_t parm_start; // first local + int32_t locals; // total ints of parms + locals - int profile; // runtime + int32_t profile; // runtime - int s_name; - int s_file; // source file defined in + int32_t s_name; // function name + int32_t s_file; // source file defined in - int numparms; - unsigned char parm_size[MAX_PARMS]; + int32_t numparms; // number of args + uint8_t parm_size[MAX_PARMS]; // and size } dfunction_t; typedef struct mfunction_s { - int first_statement; // negative numbers are builtins - int parm_start; - int locals; // total ints of parms + locals + int32_t first_statement; // negative numbers are builtins + int32_t parm_start; + int32_t locals; // total ints of parms + locals // these are doubles so that they can count up to 54bits or so rather than 32bit double tprofile; // realtime in this function @@ -391,11 +398,11 @@ typedef struct mfunction_s double builtinsprofile_total; // cost of builtin functions called by this function int recursion; - int s_name; - int s_file; // source file defined in + int32_t s_name; + int32_t s_file; // source file defined in - int numparms; - unsigned char parm_size[MAX_PARMS]; + int32_t numparms; + uint8_t parm_size[MAX_PARMS]; } mfunction_t; @@ -407,32 +414,33 @@ typedef struct mstatement_s } mstatement_t; - +// Header - 64 bytes #define PROG_VERSION 6 typedef struct dprograms_s { - int version; - int crc; // check of header file + int32_t version; // Version (usually 6) + int32_t crc; // CRC-16 of header file. Last 2 bytes are skipped - unsigned int ofs_statements; - unsigned int numstatements; // statement 0 is an error + // Sizes of and offsets to each section + uint32_t ofs_statements; + uint32_t numstatements; // statement 0 is an error - unsigned int ofs_globaldefs; - unsigned int numglobaldefs; + uint32_t ofs_globaldefs; + uint32_t numglobaldefs; - unsigned int ofs_fielddefs; - unsigned int numfielddefs; + uint32_t ofs_fielddefs; + uint32_t numfielddefs; - unsigned int ofs_functions; - unsigned int numfunctions; // function 0 is an empty + uint32_t ofs_functions; + uint32_t numfunctions; // function 0 is an empty - unsigned int ofs_strings; - unsigned int numstrings; // first string is a null string + uint32_t ofs_strings; + uint32_t numstrings; // first string is a null string - unsigned int ofs_globals; - unsigned int numglobals; + uint32_t ofs_globals; + uint32_t numglobals; - unsigned int entityfields; + uint32_t entityfields; } dprograms_t; @@ -441,16 +449,16 @@ typedef struct dprograms_v7_s dprograms_t v6; //for easier casting. //debug / version 7 extensions - unsigned int ofsfiles; //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip. - unsigned int ofslinenums; //ignored. alternative to external .lno files. - unsigned int ofsbodylessfuncs; //unsupported. function names imported from other modules. must be 0. - unsigned int numbodylessfuncs; //unsupported. must be 0. + uint32_t ofsfiles; //ignored. deprecated, should be 0. source files can instead be embedded by simply treating the .dat as a zip. + uint32_t ofslinenums; //ignored. alternative to external .lno files. + uint32_t ofsbodylessfuncs; //unsupported. function names imported from other modules. must be 0. + uint32_t numbodylessfuncs; //unsupported. must be 0. - unsigned int ofs_types; //unsupported+deprecated. rich type info. must be 0. - unsigned int numtypes; //unsupported+deprecated. rich type info. must be 0. - unsigned int blockscompressed; //unsupported. per-block compression. must be 0. + uint32_t ofs_types; //unsupported+deprecated. rich type info. must be 0. + uint32_t numtypes; //unsupported+deprecated. rich type info. must be 0. + uint32_t blockscompressed; //unsupported. per-block compression. must be 0. - int secondaryversion; //if not known then its kkqwsv's v7, qfcc's v7, or uhexen2's v7, or something. abandon all hope when not recognised. + int32_t secondaryversion; //if not known then its kkqwsv's v7, qfcc's v7, or uhexen2's v7, or something. abandon all hope when not recognised. #define PROG_SECONDARYVERSION16 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('P'<<0)|('R'<<8)|('O'<<16)|('G'<<24))) //regular 16bit statements. #define PROG_SECONDARYVERSION32 ((('1'<<0)|('F'<<8)|('T'<<16)|('E'<<24))^(('3'<<0)|('2'<<8)|('B'<<16)|(' '<<24))) //statements+globaldefs+fielddefs extended to 32bit. } -- 2.39.2