Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor: All map coordinates are now represented as double floating-…
…point

A rather substantial amount of changes because in addition to the
precision increase, I have also spent time cleaning up all of our
math routines, their interfaces and the vector types. There has
also been various name refactorings to improve readability.

Algorithmically everything still functions the same as previously.

The renderer still uses regular floats for the most part except
when sorting elements by their distance from the viewer.

Part 1 of 6.
  • Loading branch information
danij-deng committed Apr 19, 2012
1 parent 0bae941 commit 2a2f690
Show file tree
Hide file tree
Showing 114 changed files with 3,223 additions and 3,334 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/api/dd_api.h
Expand Up @@ -139,9 +139,9 @@ typedef struct {

// Miscellaneous.
void (*MobjThinker) ();
float (*MobjFriction) (void* mobj); // Returns a friction factor.
boolean (*MobjCheckPosition3f) (struct mobj_s* mobj, float x, float y, float z);
boolean (*MobjTryMove3f) (struct mobj_s* mobj, float x, float y, float z);
coord_t (*MobjFriction) (void* mobj); // Returns a friction factor.
boolean (*MobjCheckPositionXYZ) (struct mobj_s* mobj, coord_t x, coord_t y, coord_t z);
boolean (*MobjTryMoveXYZ) (struct mobj_s* mobj, coord_t x, coord_t y, coord_t z);
void (*SectorHeightChangeNotification)(int sectorIdx); // Applies necessary checks on objects.

// Main structure sizes.
Expand Down
26 changes: 13 additions & 13 deletions doomsday/engine/api/dd_maptypes.h
Expand Up @@ -3,7 +3,7 @@
#ifndef __DOOMSDAY_PLAY_PUBLIC_MAP_DATA_TYPES_H__
#define __DOOMSDAY_PLAY_PUBLIC_MAP_DATA_TYPES_H__

#define DMT_VERTEX_POS DDVT_FLOAT
#define DMT_VERTEX_ORIGIN DDVT_DOUBLE

#define DMT_HEDGE_SIDEDEF DDVT_PTR

Expand All @@ -14,8 +14,8 @@
#define DMT_HEDGE_TWIN DDVT_PTR
#define DMT_HEDGE_ANGLE DDVT_ANGLE
#define DMT_HEDGE_SIDE DDVT_BYTE // 0=front, 1=back
#define DMT_HEDGE_LENGTH DDVT_FLOAT // Accurate length of the segment (v1 -> v2).
#define DMT_HEDGE_OFFSET DDVT_FLOAT
#define DMT_HEDGE_LENGTH DDVT_DOUBLE // Accurate length of the segment (v1 -> v2).
#define DMT_HEDGE_OFFSET DDVT_DOUBLE
#define DMT_HEDGE_NEXT DDVT_PTR
#define DMT_HEDGE_PREV DDVT_PTR

Expand All @@ -34,16 +34,16 @@
#define DMT_SURFACE_BITANGENT DDVT_FLOAT
#define DMT_SURFACE_TANGENT DDVT_FLOAT
#define DMT_SURFACE_NORMAL DDVT_FLOAT
#define DMT_SURFACE_OFFSET DDVT_FLOAT // [X, Y] Planar offset to surface material origin.
#define DMT_SURFACE_OFFSET DDVT_FLOAT // [X, Y] Planar offset to surface material origin.
#define DMT_SURFACE_RGBA DDVT_FLOAT // Surface color tint

#define DMT_PLANE_ORIGIN DDVT_PTR
#define DMT_PLANE_BASE DDVT_PTR
#define DMT_PLANE_SECTOR DDVT_PTR // Owner of the plane (temp)
#define DMT_PLANE_HEIGHT DDVT_FLOAT // Current height
#define DMT_PLANE_HEIGHT DDVT_DOUBLE // Current height
#define DMT_PLANE_GLOW DDVT_FLOAT // Glow amount
#define DMT_PLANE_GLOWRGB DDVT_FLOAT // Glow color
#define DMT_PLANE_TARGET DDVT_FLOAT // Target height
#define DMT_PLANE_SPEED DDVT_FLOAT // Move speed
#define DMT_PLANE_TARGET DDVT_DOUBLE // Target height
#define DMT_PLANE_SPEED DDVT_DOUBLE // Move speed

#define DMT_SECTOR_VALIDCOUNT DDVT_INT // if == validCount, already checked.
#define DMT_SECTOR_LIGHTLEVEL DDVT_FLOAT
Expand All @@ -53,7 +53,7 @@
#define DMT_SECTOR_LINEDEFS DDVT_PTR // [lineDefCount+1] size.
#define DMT_SECTOR_BSPLEAFCOUNT DDVT_UINT
#define DMT_SECTOR_BSPLEAFS DDVT_PTR // [bspLeafCount+1] size.
#define DMT_SECTOR_ORIGIN DDVT_PTR
#define DMT_SECTOR_BASE DDVT_PTR
#define DMT_SECTOR_PLANECOUNT DDVT_UINT
#define DMT_SECTOR_REVERB DDVT_FLOAT

Expand All @@ -62,17 +62,17 @@
#define DMT_SIDEDEF_FLAGS DDVT_SHORT

#define DMT_LINEDEF_SEC DDVT_PTR
#define DMT_LINEDEF_AABOX DDVT_FLOAT
#define DMT_LINEDEF_AABOX DDVT_DOUBLE

#define DMT_LINEDEF_V DDVT_PTR
#define DMT_LINEDEF_SIDEDEFS DDVT_PTR
#define DMT_LINEDEF_FLAGS DDVT_INT // Public DDLF_* flags.
#define DMT_LINEDEF_SLOPETYPE DDVT_INT
#define DMT_LINEDEF_VALIDCOUNT DDVT_INT
#define DMT_LINEDEF_DX DDVT_FLOAT
#define DMT_LINEDEF_DY DDVT_FLOAT
#define DMT_LINEDEF_DX DDVT_DOUBLE
#define DMT_LINEDEF_DY DDVT_DOUBLE

#define DMT_BSPNODE_AABOX DDVT_FLOAT
#define DMT_BSPNODE_AABOX DDVT_DOUBLE

#define DMT_BSPNODE_CHILDREN DDVT_PTR

Expand Down
59 changes: 21 additions & 38 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -698,7 +698,7 @@ enum {
DMU_DY,
DMU_DXY,
DMU_LENGTH,
DMU_SLOPE_TYPE,
DMU_SLOPETYPE,
DMU_ANGLE,
DMU_OFFSET,

Expand All @@ -717,7 +717,7 @@ enum {
DMU_LIGHT_LEVEL,
DMT_MOBJS, ///< pointer to start of sector mobjList
DMU_BOUNDING_BOX, ///< float[4]
DMU_ORIGIN,
DMU_BASE,
DMU_WIDTH,
DMU_HEIGHT,
DMU_TARGET_HEIGHT,
Expand Down Expand Up @@ -776,7 +776,7 @@ enum { /* Do NOT change the numerical values of the constants. */
/// @ingroup mobj
#define DD_BASE_DDMOBJ_ELEMENTS() \
thinker_t thinker; /* thinker node */ \
float pos[3]; /* position [x,y,z] */
coord_t origin[3]; /* origin [x,y,z] */

/**
* All map think-able objects must use this as a base. Also used for sound
Expand All @@ -787,18 +787,6 @@ typedef struct ddmobj_base_s {
DD_BASE_DDMOBJ_ELEMENTS()
} ddmobj_base_t;

/// Fixed-point vertex position. Utility struct for the game, not used by
/// the engine. @ingroup map
typedef struct ddvertex_s {
fixed_t pos[2];
} ddvertex_t;

/// Floating-point vertex position. Utility struct for the game, not used
/// by the engine. @ingroup map
typedef struct ddvertexf_s {
float pos[2];
} ddvertexf_t;

/// R_SetupMap() modes. @ingroup map
enum {
DDSMM_AFTER_LOADING, ///< After loading a savegame...
Expand All @@ -817,11 +805,13 @@ enum {
};

typedef struct {
fixed_t pos[2], dX, dY;
fixed_t origin[2];
fixed_t direction[2];
} divline_t;

typedef struct {
float pos[2], dX, dY;
float origin[2];
float direction[2];
} fdivline_t;

/**
Expand All @@ -833,13 +823,6 @@ typedef struct {
#define PT_ADDMOBJS 2 ///< Intercept with Mobjs.
///@}

typedef enum {
ST_HORIZONTAL,
ST_VERTICAL,
ST_POSITIVE,
ST_NEGATIVE
} slopetype_t;

/**
* @defgroup lineSightFlags Line Sight Flags
* Flags used to dictate logic within P_CheckLineSight().
Expand Down Expand Up @@ -1052,24 +1035,24 @@ typedef struct aaboxd_s {
struct mobj_s* sNext, **sPrev; /* links in sector (if needed) */ \
\
struct bspleaf_s* bspLeaf; /* bspLeaf in which this resides */ \
float mom[3]; \
coord_t mom[3]; \
angle_t angle; \
spritenum_t sprite; /* used to find patch_t and flip value */ \
int frame; \
float radius; \
float height; \
coord_t radius; \
coord_t height; \
int ddFlags; /* Doomsday mobj flags (DDMF_*) */ \
float floorClip; /* value to use for floor clipping */ \
coord_t floorClip; /* value to use for floor clipping */ \
int valid; /* if == valid, already checked */ \
int type; /* mobj type */ \
struct state_s* state; \
int tics; /* state tic counter */ \
float floorZ; /* highest contacted floor */ \
float ceilingZ; /* lowest contacted ceiling */ \
coord_t floorZ; /* highest contacted floor */ \
coord_t ceilingZ; /* lowest contacted ceiling */ \
struct mobj_s* onMobj; /* the mobj this one is on top of. */ \
boolean wallHit; /* the mobj is hitting a wall. */ \
struct ddplayer_s* dPlayer; /* NULL if not a player mobj. */ \
float srvo[3]; /* short-range visual offset (xyz) */ \
coord_t srvo[3]; /* short-range visual offset (xyz) */ \
short visAngle; /* visual angle ("angle-servo") */ \
int selector; /* multipurpose info */ \
int validCount; /* used in iterating */ \
Expand All @@ -1088,7 +1071,7 @@ typedef struct aaboxd_s {
mobjinfo_t *info; /* &mobjinfo[mobj->type] */

typedef struct povertex_s {
float pos[2];
coord_t origin[2];
} povertex_t;

/// Base Polyobj elements. Games MUST use this as the basis for Polyobj. @ingroup map
Expand All @@ -1099,16 +1082,16 @@ typedef struct povertex_s {
unsigned int idx; /* Idx of polyobject. */ \
int tag; /* Reference tag. */ \
int validCount; \
AABoxf aaBox; \
float dest[2]; /* Destination XY. */ \
AABoxd aaBox; \
coord_t dest[2]; /* Destination XY. */ \
angle_t angle; \
angle_t destAngle; /* Destination angle. */ \
angle_t angleSpeed; /* Rotation speed. */ \
struct linedef_s** lines; \
unsigned int lineCount; \
struct povertex_s* originalPts; /* Used as the base for the rotations. */ \
struct povertex_s* prevPts; /* Use to restore the old point values. */ \
float speed; /* Movement speed. */ \
double speed; /* Movement speed. */ \
boolean crush; /* Should the polyobj attempt to crush mobjs? */ \
int seqType; \
struct { \
Expand Down Expand Up @@ -1763,7 +1746,7 @@ typedef enum controltype_e {
*/
#define DDPF_FIXANGLES 0x0001 ///< Server: send angle/pitch to client.
//#define DDPF_FILTER 0x0002 // Server: send filter to client.
#define DDPF_FIXPOS 0x0004 ///< Server: send coords to client.
#define DDPF_FIXORIGIN 0x0004 ///< Server: send coords to client.
#define DDPF_DEAD 0x0008 ///< Cl & Sv: player is dead.
#define DDPF_CAMERA 0x0010 ///< Player is a cameraman.
#define DDPF_LOCAL 0x0020 ///< Player is local (e.g. player zero).
Expand All @@ -1775,7 +1758,7 @@ typedef enum controltype_e {
#define DDPF_VIEW_FILTER 0x0800 ///< Cl & Sv: Draw the current view filter.
#define DDPF_REMOTE_VIEW_FILTER 0x1000 ///< Client: Draw the view filter (has been set remotely).
#define DDPF_USE_VIEW_FILTER (DDPF_VIEW_FILTER | DDPF_REMOTE_VIEW_FILTER)
#define DDPF_UNDEFINED_POS 0x2000 ///< Position of the player is undefined (view not drawn).
#define DDPF_UNDEFINED_ORIGIN 0x2000 ///< Origin of the player is undefined (view not drawn).
#define DDPF_UNDEFINED_WEAPON 0x4000 ///< Weapon of the player is undefined (not sent yet).
///@}

Expand Down Expand Up @@ -1822,7 +1805,7 @@ struct polyobj_s;

typedef struct fixcounters_s {
int angles;
int pos;
int origin;
int mom;
} fixcounters_t;

Expand Down
7 changes: 7 additions & 0 deletions doomsday/engine/api/dd_types.h
Expand Up @@ -122,6 +122,13 @@ typedef double timespan_t;
/// All points in the map coordinate space should be defined using this type.
typedef double coord_t;

typedef enum slopetype_e {
ST_HORIZONTAL,
ST_VERTICAL,
ST_POSITIVE,
ST_NEGATIVE
} slopetype_t;

/// \todo Should be a public typedef of a type defined by de::LumpDirectory.
typedef int32_t lumpnum_t;
#define LUMPNAME_T_MAXLEN 9
Expand Down
47 changes: 25 additions & 22 deletions doomsday/engine/api/doomsday.def
@@ -1,7 +1,7 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 837 <--
; Other free ordinals: none
; Highest ordinal is currently: --> 841 <--
; Other free ordinals: 57

NAME "DOOMSDAY"

Expand Down Expand Up @@ -437,18 +437,19 @@ EXPORTS
Sv_CanTrustClientPos @587 NONAME

; Play.
P_AccurateDistance @57 NONAME
P_ApproxDistance @58 NONAME
P_ApproxDistance3 @243 NONAME
P_PointOnLineDefSide @695 NONAME
P_PointXYOnLineDefSide @59 NONAME
P_BoxOnLineSide @60 NONAME
P_MakeDivline @61 NONAME
P_PointOnDivlineSide @62 NONAME
P_InterceptVector @63 NONAME
LineDef_BoxOnSide @60 NONAME
LineDef_PointDistance @208 NONAME
LineDef_PointXYDistance @209 NONAME
LineDef_PointOnSide @695 NONAME
LineDef_PointXYOnSide @59 NONAME
LineDef_SetDivline @61 NONAME
Divline_PointOnSide @838 NONAME
Divline_PointXYOnSide @62 NONAME
Divline_Intersection @63 NONAME
P_TraceLOS @829 NONAME
P_TraceOpening @828 NONAME
P_SetTraceOpening @64 NONAME
P_BspLeafAtPoint @841 NONAME
P_BspLeafAtPointXY @102 NONAME
P_MobjsBoxIterator @346 NONAME
P_LinesBoxIterator @435 NONAME
Expand Down Expand Up @@ -581,7 +582,7 @@ EXPORTS
P_RegisterMapObjProperty @412 NONAME

; Play: Mobjs.
P_MobjCreate @357 NONAME
P_MobjCreateXYZ @357 NONAME
P_MobjDestroy @358 NONAME
P_MobjLink @66 NONAME
P_MobjUnlink @67 NONAME
Expand Down Expand Up @@ -659,7 +660,6 @@ EXPORTS
R_CreateAnimGroup @241 NONAME
R_AddAnimGroupFrame @242 NONAME

R_PointToAngle2 @101 NONAME
R_HSVToRGB @439 NONAME

R_CreateColorPalette @444 NONAME
Expand Down Expand Up @@ -859,8 +859,6 @@ EXPORTS
M_IsStringValidInt @20 NONAME
M_IsStringValidByte @23 NONAME
M_IsStringValidFloat @30 NONAME
M_ClearBox @208 NONAME
M_AddToBox @209 NONAME
M_ScreenShot @210 NONAME
M_CeilPow2 @422 NONAME
M_NumDigits @143 NONAME
Expand All @@ -873,15 +871,20 @@ EXPORTS
bamsAtan2 @145 NONAME

; Vectors.
V2f_Sum @54 NONAME
V2f_Subtract @341 NONAME
V2f_Rotate @344 NONAME
V2f_Intersection @349 NONAME
V2d_Sum @54 NONAME
V2d_Subtract @341 NONAME
V2d_Rotate @344 NONAME
V2d_PointOnLineSide @376 NONAME
V2d_PointLineDistance @442 NONAME
V2d_ProjectOnLine @443 NONAME
V2d_Intersection @349 NONAME

; Utilities.
M_PointLineDistance @442 NONAME
M_ProjectPointOnLine @443 NONAME
P_PointOnLineSide @376 NONAME
M_ApproxDistance @58 NONAME
M_ApproxDistance3 @243 NONAME
M_PointXYToAngle @839 NONAME
M_PointToAngle2 @840 NONAME
M_PointXYToAngle2 @101 NONAME

; Miscellaneous: Command line.
ArgAbbreviate @146 NONAME
Expand Down

0 comments on commit 2a2f690

Please sign in to comment.