diff --git a/doomsday/engine/api/dd_share.h b/doomsday/engine/api/dd_share.h index 0af6b313e9..2222e097bf 100644 --- a/doomsday/engine/api/dd_share.h +++ b/doomsday/engine/api/dd_share.h @@ -482,13 +482,15 @@ extern "C" { EV_JOY_AXIS, // Joystick main axes (xyz + Rxyz) EV_JOY_SLIDER, // Joystick sliders EV_JOY_BUTTON, - EV_POV + EV_POV, + NUM_EVENT_TYPES } evtype_t; typedef enum { EVS_DOWN, EVS_UP, EVS_REPEAT, + NUM_EVENT_STATES } evstate_t; typedef struct { @@ -500,7 +502,8 @@ extern "C" { int data4; int data5; int data6; - int useclass; // use a specific bindclass command + unsigned int useclass; // use a specific bindclass command + boolean noclass; } event_t; // The mouse wheel is considered two extra mouse buttons. @@ -1118,12 +1121,14 @@ typedef enum blendmode_e { NUM_DDBINDCLASSES }; +#define BCF_ABSOLUTE 0x00000001 + // Bind Class typedef struct bindclass_s { char *name; - int id; + unsigned int id; int active; - int absolute; + int flags; } bindclass_t; // Console command. diff --git a/doomsday/engine/api/doomsday.def b/doomsday/engine/api/doomsday.def index 74cb903596..255ec360fe 100644 --- a/doomsday/engine/api/doomsday.def +++ b/doomsday/engine/api/doomsday.def @@ -5,6 +5,7 @@ NAME "DOOMSDAY" ; Other free ordinals: ; 77 formaly P_LoadBlockMap ; 78 formaly P_LoadReject +; 232 formaly R_SetAnimGroup EXPORTS Plug_AddHook @1 NONAME @@ -254,7 +255,6 @@ EXPORTS R_TextureNameForNum @98 NONAME R_SetFlatTranslation @99 NONAME R_SetTextureTranslation @100 NONAME - R_SetAnimGroup @232 NONAME R_PointToAngle2 @101 NONAME R_PointInSubsector @102 NONAME R_CreateAnimGroup @241 NONAME diff --git a/doomsday/engine/api/doomsday.h b/doomsday/engine/api/doomsday.h index 3948cf5755..45d6a87ad3 100644 --- a/doomsday/engine/api/doomsday.h +++ b/doomsday/engine/api/doomsday.h @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -145,9 +145,10 @@ extern "C" { void B_FormEventString(char *buff, evtype_t type, evstate_t state, int data1); int B_BindingsForCommand(char *command, char *buffer, - int bindClass); + unsigned int classID, + boolean allClasses); void DD_AddBindClass(struct bindclass_s *); - boolean DD_SetBindClass(int classID, int type); + boolean DD_SetBindClass(unsigned int classID, int type); // System. void Sys_TicksPerSecond(float num); @@ -339,7 +340,6 @@ extern "C" { char *R_TextureNameForNum(int num); int R_SetFlatTranslation(int flat, int translate_to); int R_SetTextureTranslation(int tex, int translate_to); - void R_SetAnimGroup(int type, int number, int group); int R_CreateAnimGroup(int type, int flags); void R_AddToAnimGroup(int groupNum, int number, int tics, int randomTics); diff --git a/doomsday/engine/portable/include/cl_mobj.h b/doomsday/engine/portable/include/cl_mobj.h index 5280783f55..6dac19bccf 100644 --- a/doomsday/engine/portable/include/cl_mobj.h +++ b/doomsday/engine/portable/include/cl_mobj.h @@ -4,6 +4,7 @@ * Online License Link: http://www.gnu.org/licenses/gpl.html * *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -29,12 +30,12 @@ #define __DOOMSDAY_CLIENT_MOBJ_H__ // Flags for clmobjs. -#define CLMF_HIDDEN 0x01 // Not officially created yet -#define CLMF_UNPREDICTABLE 0x02 // Temporarily hidden (until next delta) -#define CLMF_SOUND 0x04 // Sound is queued for playing on unhide. -#define CLMF_NULLED 0x08 // Once nulled, it can't be updated. -#define CLMF_STICK_FLOOR 0x10 // Mobj will stick to the floor. -#define CLMF_STICK_CEILING 0x20 // Mobj will stick to the ceiling. +#define CLMF_HIDDEN 0x01 // Not officially created yet +#define CLMF_UNPREDICTABLE 0x02 // Temporarily hidden (until next delta) +#define CLMF_SOUND 0x04 // Sound is queued for playing on unhide. +#define CLMF_NULLED 0x08 // Once nulled, it can't be updated. +#define CLMF_STICK_FLOOR 0x10 // Mobj will stick to the floor. +#define CLMF_STICK_CEILING 0x20 // Mobj will stick to the ceiling. // Clmobj knowledge flags. This keeps track of the information that has been // received. @@ -45,12 +46,12 @@ #define CLMF_KNOWN 0xf0000 // combination of all the KNOWN-flags typedef struct clmobj_s { - struct clmobj_s *next, *prev; - int flags; - uint time; // Time of last update. - int sound; // Queued sound ID. - float volume; // Volume for queued sound. - mobj_t mo; + struct clmobj_s *next, *prev; + int flags; + uint time; // Time of last update. + int sound; // Queued sound ID. + float volume; // Volume for queued sound. + mobj_t mo; } clmobj_t; void Cl_InitClientMobjs(); @@ -59,12 +60,12 @@ void Cl_DestroyClientMobjs(); clmobj_t *Cl_CreateMobj(thid_t id); void Cl_DestroyMobj(clmobj_t *cmo); boolean Cl_MobjIterator(boolean (*callback) (clmobj_t *, void *), - void *parm); + void *parm); void Cl_PredictMovement(void); void Cl_UnsetThingPosition(clmobj_t *cmo); void Cl_SetThingPosition(clmobj_t *cmo); int Cl_ReadMobjDelta(void); -void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip); +void Cl_ReadMobjDelta2(boolean skip); void Cl_ReadNullMobjDelta2(boolean skip); clmobj_t *Cl_FindMobj(thid_t id); void Cl_CheckMobj(clmobj_t *cmo, boolean justCreated); diff --git a/doomsday/engine/portable/include/con_bind.h b/doomsday/engine/portable/include/con_bind.h index eebd66fd2e..d747916308 100644 --- a/doomsday/engine/portable/include/con_bind.h +++ b/doomsday/engine/portable/include/con_bind.h @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -43,12 +43,17 @@ typedef struct { command_t *commands; } binding_t; -void B_Bind(event_t *event, char *command, int bindClass); +void B_Init(void); +void B_Bind(event_t *event, char *command, + unsigned int bindClass); void DD_AddBindClass(struct bindclass_s *); -boolean B_SetBindClass(int classID, int type); +boolean B_SetBindClass(unsigned int classID, unsigned int type); void B_RegisterBindClasses(void); -int B_BindingsForCommand(char *command, char *buffer, int bindClass); -void B_ClearBinding(char *command, int bindClass); +int B_BindingsForCommand(char *command, char *buffer, + unsigned int bindClass, + boolean allClasses); +void B_ClearBinding(char *command, unsigned int bindClass, + boolean allClasses); boolean B_Responder(event_t *ev); void B_WriteToFile(FILE * file); void B_Shutdown(); diff --git a/doomsday/engine/portable/include/net_main.h b/doomsday/engine/portable/include/net_main.h index e60a51c061..5b87e0dea6 100644 --- a/doomsday/engine/portable/include/net_main.h +++ b/doomsday/engine/portable/include/net_main.h @@ -4,6 +4,7 @@ * Online License Link: http://www.gnu.org/licenses/gpl.html * *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -284,7 +285,7 @@ int Net_TimeDelta(byte now, byte then); void Net_NewLocalCmd(ticcmd_t * cmd, int pNum); int Net_GetTicCmd(void *cmd, int player); void Net_Update(void); -void Net_Ticker(timespan_t time); +void Net_Ticker(void/*timespan_t time*/); void Net_Drawer(void); boolean Net_IsLocalPlayer(int pNum); diff --git a/doomsday/engine/portable/include/r_data.h b/doomsday/engine/portable/include/r_data.h index 8ca5ea8ba6..97e27ac235 100644 --- a/doomsday/engine/portable/include/r_data.h +++ b/doomsday/engine/portable/include/r_data.h @@ -277,7 +277,10 @@ typedef struct shadowlink_s { shadowpoly_t *poly; } shadowlink_t; +#define SEGINF_FACINGFRONT 0x0001 + typedef struct seginfo_s { + short flags; biastracker_t tracker[3]; // 0=top, 1=middle, 2=bottom vertexillum_t illum[3][4]; uint updated; @@ -456,7 +459,6 @@ int R_TextureNumForName(char *name); char *R_TextureNameForNum(int num); int R_SetFlatTranslation(int flat, int translateTo); int R_SetTextureTranslation(int tex, int translateTo); -void R_SetAnimGroup(int type, int number, int group); boolean R_IsCustomTexture(int texture); boolean R_IsAllowedDecoration(ded_decor_t * def, int index, boolean hasExternal); diff --git a/doomsday/engine/portable/include/r_lgrid.h b/doomsday/engine/portable/include/r_lgrid.h index ac2f33e3a7..e6eb77e439 100644 --- a/doomsday/engine/portable/include/r_lgrid.h +++ b/doomsday/engine/portable/include/r_lgrid.h @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -32,7 +32,7 @@ void LG_Register(void); void LG_Init(void); -void LG_SectorChanged(sector_t *sector, sectorinfo_t *info); +void LG_SectorChanged(sector_t *sector); void LG_Update(void); void LG_Evaluate(const float *point, byte *color); void LG_Debug(void); diff --git a/doomsday/engine/portable/include/sys_sock.h b/doomsday/engine/portable/include/sys_sock.h index c7366a8d39..60753edb26 100644 --- a/doomsday/engine/portable/include/sys_sock.h +++ b/doomsday/engine/portable/include/sys_sock.h @@ -4,6 +4,7 @@ * Online License Link: http://www.gnu.org/licenses/gpl.html * *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -30,7 +31,10 @@ #include "dd_types.h" -typedef unsigned int socket_t; +// DJS - this was unsigned, however socket() will return a signed +// value depending on the outcome. Which we check against a signed +// value in several places in the code. +typedef int socket_t; void N_SockInit(void); void N_SockShutdown(void); @@ -38,7 +42,7 @@ void N_SockPrintf(socket_t s, const char *format, ...); struct hostent *N_SockGetHost(const char *hostName); socket_t N_SockNewStream(void); boolean N_SockConnect(socket_t s, struct hostent *host, - unsigned short port); + unsigned short port); void N_SockClose(socket_t s); #endif diff --git a/doomsday/engine/portable/src/cl_frame.c b/doomsday/engine/portable/src/cl_frame.c index c50e3f14ca..ad1348b363 100644 --- a/doomsday/engine/portable/src/cl_frame.c +++ b/doomsday/engine/portable/src/cl_frame.c @@ -4,6 +4,7 @@ * Online License Link: http://www.gnu.org/licenses/gpl.html * *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -33,8 +34,8 @@ // MACROS ------------------------------------------------------------------ -#define SET_HISTORY_SIZE 50 -#define RESEND_HISTORY_SIZE 50 +#define SET_HISTORY_SIZE 50 +#define RESEND_HISTORY_SIZE 50 // TYPES ------------------------------------------------------------------- @@ -65,8 +66,8 @@ int predicted_tics; static uint latestSetOrdinal; static byte latestSet; -// The ordinal base is added to the set number to convert it from a set -// identifier to an ordinal. Every time the set numbers wrap around from 255 +// The ordinal base is added to the set number to convert it from a set +// identifier to an ordinal. Every time the set numbers wrap around from 255 // to zero, the ordinal is incremented by 256. static uint setOrdinalBase; @@ -82,92 +83,92 @@ static int resendHistoryIdx; // CODE -------------------------------------------------------------------- -/* +/** * Clear the history of received set numbers. */ void Cl_InitFrame(void) { - gotframe = false; // Nothing yet... + gotframe = false; // Nothing yet... + + // -1 denotes an invalid entry. + memset(setHistory, -1, sizeof(setHistory)); + historyIdx = 0; - // -1 denotes an invalid entry. - memset(setHistory, -1, sizeof(setHistory)); - historyIdx = 0; + // Clear the resend ID history. + memset(resendHistory, 0, sizeof(resendHistory)); + resendHistoryIdx = 0; - // Clear the resend ID history. - memset(resendHistory, 0, sizeof(resendHistory)); - resendHistoryIdx = 0; - // Reset ordinal counters. latestSet = 0; latestSetOrdinal = 0; setOrdinalBase = 256; } -/* +/** * Called when the map changes. */ void Cl_ResetFrame(void) { - gotframe = false; + gotframe = false; - // All frames received before the PSV_FIRST_FRAME2 are ignored. - // They must be from the wrong map. - gotFirstFrame = false; + // All frames received before the PSV_FIRST_FRAME2 are ignored. + // They must be from the wrong map. + gotFirstFrame = false; } -/* +/** * Add a set number to the history. */ void Cl_HistoryAdd(byte set) { - setHistory[historyIdx++] = set; + setHistory[historyIdx++] = set; - if(historyIdx >= SET_HISTORY_SIZE) - historyIdx -= SET_HISTORY_SIZE; + if(historyIdx >= SET_HISTORY_SIZE) + historyIdx -= SET_HISTORY_SIZE; } -/* +/** * Returns true if the set is found in the recent set history. */ boolean Cl_HistoryCheck(byte set) { - int i; - - for(i = 0; i < SET_HISTORY_SIZE; i++) - { - if(setHistory[i] == set) - return true; - } - return false; + int i; + + for(i = 0; i < SET_HISTORY_SIZE; ++i) + { + if(setHistory[i] == set) + return true; + } + return false; } -/* +/** * Add a resend ID number to the resend history. */ void Cl_ResendHistoryAdd(byte id) { - resendHistory[resendHistoryIdx++] = id; + resendHistory[resendHistoryIdx++] = id; - if(resendHistoryIdx >= RESEND_HISTORY_SIZE) - resendHistoryIdx -= RESEND_HISTORY_SIZE; + if(resendHistoryIdx >= RESEND_HISTORY_SIZE) + resendHistoryIdx -= RESEND_HISTORY_SIZE; } -/* +/** * Returns true if the resend ID is found in the history. */ boolean Cl_ResendHistoryCheck(byte id) { - int i; - - for(i = 0; i < RESEND_HISTORY_SIZE; i++) - { - if(resendHistory[i] == id) - return true; - } - return false; + int i; + + for(i = 0; i < RESEND_HISTORY_SIZE; ++i) + { + if(resendHistory[i] == id) + return true; + } + return false; } -/* +/** * Converts a set identifier, which ranges from 0...255, into a logical ordinal. * Checks for set identifier wraparounds and updates the set ordinal base * accordingly. @@ -175,12 +176,12 @@ boolean Cl_ResendHistoryCheck(byte id) uint Cl_ConvertSetToOrdinal(byte set) { uint ordinal = 0; - + if(latestSet > 185 && set < 70) { // We must conclude that wraparound has occured. setOrdinalBase += 256; - + VERBOSE2( Con_Printf("Cl_ConvertSetToOrdinal: Wraparound, now base is %i.\n", setOrdinalBase) ); } @@ -198,50 +199,50 @@ uint Cl_ConvertSetToOrdinal(byte set) return ordinal; } -/* +/** * Read a PSV_FRAME2/PSV_FIRST_FRAME2 packet. */ void Cl_Frame2Received(int packetType) { - byte set = Msg_ReadByte(), oldSet, resend, deltaType; - int deltaCount = 0; - byte resendAcks[300]; - int i, numResendAcks = 0; - boolean skip = false; + byte set = Msg_ReadByte(), oldSet, resend, deltaType; + byte resendAcks[300]; + int i, numResendAcks = 0; + boolean skip = false; #ifdef _DEBUG + int deltaCount = 0; int startOffset; int deltaLength; #endif - // All frames that arrive before the first frame are ignored. - // They are most likely from the wrong map. - if(packetType == PSV_FIRST_FRAME2) - { - gotFirstFrame = true; + // All frames that arrive before the first frame are ignored. + // They are most likely from the wrong map. + if(packetType == PSV_FIRST_FRAME2) + { + gotFirstFrame = true; #ifdef _DEBUG VERBOSE( Con_Printf("*** GOT THE FIRST FRAME (%i) ***\n", set) ); -#endif - } - else if(!gotFirstFrame) - { - // Just ignore. If this was a legitimate frame, the server will - // send it again when it notices no ack is coming. +#endif + } + else if(!gotFirstFrame) + { + // Just ignore. If this was a legitimate frame, the server will + // send it again when it notices no ack is coming. #ifdef _DEBUG - VERBOSE( Con_Printf("==> Ignored set %i\n", set) ); -#endif - return; - } + VERBOSE( Con_Printf("==> Ignored set %i\n", set) ); +#endif + return; + } -#ifdef _DEBUG +#ifdef _DEBUG VERBOSE2( Con_Printf("Cl_Frame2Received: Processing delta set %i.\n", set) ); #endif if(packetType != PSV_FIRST_FRAME2) { - // If this is not the first frame, it will be ignored if it arrives + // If this is not the first frame, it will be ignored if it arrives // out of order. uint ordinal = Cl_ConvertSetToOrdinal(set); - + if(ordinal < latestSetOrdinal) { VERBOSE2( Con_Printf("==> Ignored set %i because it arrived out of order.\n", @@ -252,15 +253,17 @@ void Cl_Frame2Received(int packetType) VERBOSE2( Con_Printf("Latest set ordinal is %i.\n", latestSetOrdinal) ); } - - // Check for duplicates (might happen if ack doesn't get through - // or ack arrives too late). - if(!Cl_HistoryCheck(set)) - { + + // Check for duplicates (might happen if ack doesn't get through + // or ack arrives too late). + if(!Cl_HistoryCheck(set)) + { +#ifdef _DEBUG int readCount = 0; - - // It isn't yet in the history, so add it there. - Cl_HistoryAdd(set); +#endif + + // It isn't yet in the history, so add it there. + Cl_HistoryAdd(set); VERBOSE2( Con_Printf("Starting to process deltas in set %i.\n", set) ); @@ -268,112 +271,112 @@ void Cl_Frame2Received(int packetType) deltaCount = Msg_ReadLong(); VERBOSE2( Con_Message("Set contains %i deltas.\n", deltaCount) ); #endif - - // Read and process the message. - while(!Msg_End()) - { + + // Read and process the message. + while(!Msg_End()) + { #ifdef _DEBUG /*Con_Message("Starting to read delta %i of %i...\n", ++readCount, deltaCount);*/ - + // Check length field. startOffset = Msg_Offset(); - deltaLength = Msg_ReadLong(); + deltaLength = Msg_ReadLong(); //Con_Message("Incoming delta length %i bytes.\n", deltaLength); #endif - - deltaType = Msg_ReadByte(); + + deltaType = Msg_ReadByte(); #ifdef _DEBUG //Con_Message(" Delta type is %i.\n", deltaType & ~DT_RESENT); #endif - skip = false; - + skip = false; + VERBOSE2( Con_Printf("Received delta %i.\n", deltaType & ~DT_RESENT) ); - // Is this a resent delta? - if(deltaType & DT_RESENT) - { + // Is this a resent delta? + if(deltaType & DT_RESENT) + { VERBOSE2( Con_Printf(" This is a resent delta.\n") ); - - deltaType &= ~DT_RESENT; - // Read the set number this was originally in. - oldSet = Msg_ReadByte(); + deltaType &= ~DT_RESENT; + + // Read the set number this was originally in. + oldSet = Msg_ReadByte(); - // Read the resend ID. - resend = Msg_ReadByte(); + // Read the resend ID. + resend = Msg_ReadByte(); - // Did we already receive this delta? + // Did we already receive this delta? { boolean historyChecked = Cl_HistoryCheck(oldSet); boolean resendChecked = Cl_ResendHistoryCheck(resend); - + if(historyChecked || resendChecked) { // Yes, we've already got this. Must skip. skip = true; VERBOSE2( Con_Printf(" Skipping delta %i (oldset=%i, rsid=%i), because history=%i resend=%i\n", - deltaType, oldSet, resend, + deltaType, oldSet, resend, historyChecked, resendChecked) ); } } - // We must acknowledge that we've received this. - resendAcks[numResendAcks++] = resend; - Cl_ResendHistoryAdd(resend); - } + // We must acknowledge that we've received this. + resendAcks[numResendAcks++] = resend; + Cl_ResendHistoryAdd(resend); + } else { VERBOSE2( Con_Printf(" Not resent.\n") ); } - - switch (deltaType) - { - case DT_CREATE_MOBJ: - // The mobj will be created/shown. - Cl_ReadMobjDelta2(true, skip); - break; - - case DT_MOBJ: - // The mobj will be hidden if it's not yet Created. - Cl_ReadMobjDelta2(true /*false*/, skip); - break; - - case DT_NULL_MOBJ: - // The mobj will be removed. - Cl_ReadNullMobjDelta2(skip); - break; - - case DT_PLAYER: - Cl_ReadPlayerDelta2(skip); - break; - - case DT_SECTOR_R6: // Old format. + + switch (deltaType) + { + case DT_CREATE_MOBJ: + // The mobj will be created/shown. + Cl_ReadMobjDelta2(skip); + break; + + case DT_MOBJ: + // The mobj will be hidden if it's not yet Created. + Cl_ReadMobjDelta2(skip); + break; + + case DT_NULL_MOBJ: + // The mobj will be removed. + Cl_ReadNullMobjDelta2(skip); + break; + + case DT_PLAYER: + Cl_ReadPlayerDelta2(skip); + break; + + case DT_SECTOR_R6: // Old format. case DT_SECTOR: - Cl_ReadSectorDelta2(deltaType, skip); - break; + Cl_ReadSectorDelta2(deltaType, skip); + break; case DT_SIDE_R6: // Old format. - case DT_SIDE: - Cl_ReadSideDelta2(deltaType, skip); - break; - - case DT_POLY: - Cl_ReadPolyDelta2(skip); - break; - - case DT_SOUND: - case DT_MOBJ_SOUND: - case DT_SECTOR_SOUND: - case DT_POLY_SOUND: - Cl_ReadSoundDelta2(deltaType, skip); - break; - - default: - Con_Error("Cl_Frame2Received: Unknown delta type %i.\n", - deltaType); - } + case DT_SIDE: + Cl_ReadSideDelta2(deltaType, skip); + break; + + case DT_POLY: + Cl_ReadPolyDelta2(skip); + break; + + case DT_SOUND: + case DT_MOBJ_SOUND: + case DT_SECTOR_SOUND: + case DT_POLY_SOUND: + Cl_ReadSoundDelta2(deltaType, skip); + break; + + default: + Con_Error("Cl_Frame2Received: Unknown delta type %i.\n", + deltaType); + } #ifdef _DEBUG // Check that we didn't misread. @@ -385,46 +388,46 @@ void Cl_Frame2Received(int packetType) } #endif } - - // We have now received a frame. - gotframe = true; - - // Reset the predict counter. - predicted_tics = 0; - } - - if(numResendAcks == 0) - { - // Acknowledge the set. - Msg_Begin(PCL_ACK_SETS); - Msg_WriteByte(set); - + + // We have now received a frame. + gotframe = true; + + // Reset the predict counter. + predicted_tics = 0; + } + + if(numResendAcks == 0) + { + // Acknowledge the set. + Msg_Begin(PCL_ACK_SETS); + Msg_WriteByte(set); + #ifdef _DEBUG VERBOSE2( Con_Printf("Cl_Frame2Received: Ack set %i. " "Nothing was resent.\n", set) ); #endif - } - else - { - // Acknowledge the set and the resent deltas. - Msg_Begin(PCL_ACKS); - Msg_WriteByte(set); + } + else + { + // Acknowledge the set and the resent deltas. + Msg_Begin(PCL_ACKS); + Msg_WriteByte(set); #ifdef _DEBUG VERBOSE2( Con_Printf("Cl_Frame2Received: Ack set %i. " - "Contained %i resent deltas: \n", + "Contained %i resent deltas: \n", set, numResendAcks) ); #endif - for(i = 0; i < numResendAcks; i++) - { - Msg_WriteByte(resendAcks[i]); + for(i = 0; i < numResendAcks; ++i) + { + Msg_WriteByte(resendAcks[i]); #ifdef _DEBUG VERBOSE2( Con_Printf("%i ", resendAcks[i]) ); #endif - } + } #ifdef _DEBUG VERBOSE2( Con_Printf("\n") ); #endif - } - Net_SendBuffer(0, 0); + } + Net_SendBuffer(0, 0); } diff --git a/doomsday/engine/portable/src/cl_mobj.c b/doomsday/engine/portable/src/cl_mobj.c index 9c50365294..f15911a801 100644 --- a/doomsday/engine/portable/src/cl_mobj.c +++ b/doomsday/engine/portable/src/cl_mobj.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -93,7 +93,7 @@ cmhash_t cmHash[HASH_SIZE]; // CODE -------------------------------------------------------------------- -/* +/** * Returns a pointer to the hash chain with the specified id. */ cmhash_t *Cl_MobjHash(thid_t id) @@ -101,7 +101,7 @@ cmhash_t *Cl_MobjHash(thid_t id) return &cmHash[(uint) id % HASH_SIZE]; } -/* +/** * Links the clmobj into the client mobj hash table. */ void Cl_LinkMobj(clmobj_t *cmo, thid_t id) @@ -125,7 +125,7 @@ void Cl_LinkMobj(clmobj_t *cmo, thid_t id) } } -/* +/** * Unlinks the clmobj from the client mobj hash table. */ void Cl_UnlinkMobj(clmobj_t *cmo) @@ -150,7 +150,7 @@ void Cl_UnlinkMobj(clmobj_t *cmo) cmo->prev->next = cmo->next; } -/* +/** * Searches through the client mobj hash table and returns the clmobj * with the specified ID, if that exists. */ @@ -170,7 +170,7 @@ clmobj_t *Cl_FindMobj(thid_t id) return NULL; } -/* +/** * Aborts and returns false if the callback returns false. * Otherwise returns true. */ @@ -179,7 +179,7 @@ boolean Cl_MobjIterator(boolean (*callback) (clmobj_t *, void *), void *parm) clmobj_t *cmo; int i; - for(i = 0; i < HASH_SIZE; i++) + for(i = 0; i < HASH_SIZE; ++i) { for(cmo = cmHash[i].first; cmo; cmo = cmo->next) { @@ -190,7 +190,7 @@ boolean Cl_MobjIterator(boolean (*callback) (clmobj_t *, void *), void *parm) return true; } -/* +/** * Unlinks the thing from sectorlinks and if the object is solid, * the blockmap. */ @@ -199,7 +199,7 @@ void Cl_UnsetThingPosition(clmobj_t *cmo) P_UnlinkThing(&cmo->mo); } -/* +/** * Links the thing into sectorlinks and if the object is solid, the * blockmap. Linking to sectorlinks makes the thing visible and linking * to the blockmap makes it possible to interact with it (collide). @@ -209,7 +209,7 @@ void Cl_SetThingPosition(clmobj_t *cmo) { mobj_t *thing = &cmo->mo; - if(cmo->flags & (CLMF_HIDDEN | CLMF_UNPREDICTABLE) || thing->dplayer) + if((cmo->flags & (CLMF_HIDDEN | CLMF_UNPREDICTABLE)) || thing->dplayer) { // We do not yet have all the details about Hidden mobjs. // The server hasn't sent us a Create Mobj delta for them. @@ -222,7 +222,7 @@ void Cl_SetThingPosition(clmobj_t *cmo) (thing->ddflags & DDMF_SOLID ? DDLINK_BLOCKMAP : 0)); } -/* +/** * Change the state of a mobj. */ void Cl_SetThingState(mobj_t *mo, int stnum) @@ -244,7 +244,7 @@ void Cl_SetThingState(mobj_t *mo, int stnum) mo->type = 0; } -/* +/** * Updates floorz and ceilingz of the mobj. */ void Cl_CheckMobj(clmobj_t *cmo, boolean justCreated) @@ -311,7 +311,7 @@ void Cl_CheckMobj(clmobj_t *cmo, boolean justCreated) #endif } -/* +/** * Make the real player mobj identical with the client mobj. * The client mobj is always unlinked. Only the *real* mobj is visible. * (The real mobj was created by the Game.) @@ -347,7 +347,7 @@ void Cl_UpdateRealPlayerMobj(mobj_t *mo, mobj_t *clmo, int flags) #ifdef _DEBUG Con_Message("Cl_UpdateRealPlayerMobj: mo=%p angle=%x\n", mo, mo->angle); #endif - } + } mo->sprite = clmo->sprite; mo->frame = clmo->frame; //mo->nextframe = clmo->nextframe; @@ -367,7 +367,7 @@ void Cl_UpdateRealPlayerMobj(mobj_t *mo, mobj_t *clmo, int flags) //if(flags & MDF_FLAGS) CON_Printf("Cl_RMD: ddf=%x\n", mo->ddflags); } -/* +/** * Reads a single mobj delta from the message buffer and applies * it to the client mobj in question. * For client mobjs that belong to players, updates the real player mobj. @@ -525,10 +525,10 @@ int Cl_ReadMobjDelta(void) return true; } -/* +/** * Initialize clientside data. */ -void Cl_InitClientMobjs() +void Cl_InitClientMobjs(void) { //previousTime = gameTime; @@ -538,16 +538,16 @@ void Cl_InitClientMobjs() Cl_InitPlayers(); } -/* +/** * Called when the client is shut down. Unlinks everything from the * sectors and the blockmap and clears the clmobj list. */ -void Cl_DestroyClientMobjs() +void Cl_DestroyClientMobjs(void) { clmobj_t *cmo; int i; - for(i = 0; i < HASH_SIZE; i++) + for(i = 0; i < HASH_SIZE; ++i) { for(cmo = cmHash[i].first; cmo; cmo = cmo->next) { @@ -560,7 +560,7 @@ void Cl_DestroyClientMobjs() Cl_Reset(); } -/* +/** * Reset the client status. Called when the level changes. */ void Cl_Reset(void) @@ -574,7 +574,7 @@ void Cl_Reset(void) Cl_InitPlayers(); } -/* +/** * The client mobj is moved linearly, with collision checking. */ void Cl_MoveThing(clmobj_t *cmo) @@ -669,7 +669,7 @@ void Cl_MoveThing(clmobj_t *cmo) } } -/* +/** * Decrement tics counter and changes the state of the thing if necessary. */ void Cl_AnimateThing(mobj_t *mo) @@ -699,7 +699,7 @@ void Cl_AnimateThing(mobj_t *mo) } } -/* +/** * All client mobjs are moved and animated using the data we have. * 'forward' parameter is currently unused. */ @@ -719,14 +719,14 @@ void Cl_PredictMovement(void) predicted_tics++; // Move all client mobjs. - for(i = 0; i < HASH_SIZE; i++) + for(i = 0; i < HASH_SIZE; ++i) { for(cmo = cmHash[i].first; cmo; cmo = next) { next = cmo->next; moCount++; - if(cmo->mo.dplayer != &ddplayers[consoleplayer] && + if(cmo->mo.dplayer != &ddplayers[consoleplayer] && cmo->flags & (CLMF_UNPREDICTABLE | CLMF_HIDDEN) /*|| cmo->mo.ddflags & DDMF_MISSILE*/) { @@ -788,7 +788,7 @@ void Cl_PredictMovement(void) #endif } -/* +/** * Create a new client mobj. */ clmobj_t *Cl_CreateMobj(thid_t id) @@ -803,7 +803,7 @@ clmobj_t *Cl_CreateMobj(thid_t id) return cmo; } -/* +/** * Destroys the client mobj. */ void Cl_DestroyMobj(clmobj_t *cmo) @@ -818,7 +818,7 @@ void Cl_DestroyMobj(clmobj_t *cmo) Z_Free(cmo); } -/* +/** * Call for Hidden client mobjs to make then visible. * If a sound is waiting, it's now played. * @@ -827,7 +827,7 @@ void Cl_DestroyMobj(clmobj_t *cmo) boolean Cl_RevealMobj(clmobj_t *cmo) { // Check that we know enough about the clmobj. - if(cmo->mo.dplayer != &ddplayers[consoleplayer] && + if(cmo->mo.dplayer != &ddplayers[consoleplayer] && (!(cmo->flags & CLMF_KNOWN_X) || !(cmo->flags & CLMF_KNOWN_Y) || !(cmo->flags & CLMF_KNOWN_Z) || @@ -836,7 +836,7 @@ boolean Cl_RevealMobj(clmobj_t *cmo) // Don't reveal just yet. We lack a vital piece of information. return false; } - + /*#ifdef _DEBUG Con_Printf("Cl_RMD2: Mo %i Hidden status lifted.\n", cmo->mo.thinker.id); #endif */ @@ -851,23 +851,23 @@ boolean Cl_RevealMobj(clmobj_t *cmo) cmo->flags &= ~CLMF_SOUND; S_StartSoundAtVolume(cmo->sound, &cmo->mo, cmo->volume); } - + #ifdef _DEBUG - VERBOSE2( Con_Printf("Cl_RevealMobj: Revealing id %i, state %p (%i)\n", - cmo->mo.thinker.id, cmo->mo.state, + VERBOSE2( Con_Printf("Cl_RevealMobj: Revealing id %i, state %p (%i)\n", + cmo->mo.thinker.id, cmo->mo.state, cmo->mo.state - states) ); #endif return true; } -/* +/** * Reads a single mobj PSV_FRAME2 delta from the message buffer and * applies it to the client mobj in question. * * For client mobjs that belong to players, updates the real player mobj. */ -void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip) +void Cl_ReadMobjDelta2(boolean skip) { boolean needsLinking = false, justCreated = false; clmobj_t *cmo = NULL; @@ -918,7 +918,7 @@ void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip) } d = &cmo->mo; - + /*if(d->dplayer && d->dplayer == &ddplayers[consoleplayer]) { // Mark the local player known. @@ -926,7 +926,7 @@ void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip) }*/ // Need to unlink? (Flags because DDMF_SOLID determines block-linking.) - if(df & (MDF_POS_X | MDF_POS_Y | MDF_POS_Z | MDF_FLAGS) && + if(df & (MDF_POS_X | MDF_POS_Y | MDF_POS_Z | MDF_FLAGS) && !justCreated && !d->dplayer) { needsLinking = true; @@ -953,7 +953,7 @@ void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip) if(df & MDF_POS_Z) { d->pos[VZ] = (Msg_ReadShort() << FRACBITS) | (Msg_ReadByte() << 8); - if(cmo) + if(cmo) { cmo->flags |= CLMF_KNOWN_Z; @@ -1060,9 +1060,9 @@ void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip) // This'll update floorz and ceilingz. Cl_CheckMobj(cmo, justCreated); } - - // If the clmobj is Hidden (or Nulled), it will not be linked back to - // the world until it's officially Created. (Otherwise, partially updated + + // If the clmobj is Hidden (or Nulled), it will not be linked back to + // the world until it's officially Created. (Otherwise, partially updated // mobjs may be visible for a while.) if(!(cmo->flags & (CLMF_HIDDEN | CLMF_NULLED))) { @@ -1081,7 +1081,7 @@ void Cl_ReadMobjDelta2(boolean allowCreate, boolean skip) } } -/* +/** * Null mobjs deltas have their own type in a PSV_FRAME2 packet. * Here we remove the mobj in question. */ diff --git a/doomsday/engine/portable/src/con_bind.c b/doomsday/engine/portable/src/con_bind.c index 2e472a3329..417b55ded5 100644 --- a/doomsday/engine/portable/src/con_bind.c +++ b/doomsday/engine/portable/src/con_bind.c @@ -32,8 +32,6 @@ #include "de_console.h" #include "de_misc.h" -#include - // MACROS ------------------------------------------------------------------ // TYPES ------------------------------------------------------------------- @@ -43,6 +41,11 @@ typedef struct { char *name; } keyname_t; +typedef struct { + unsigned int num; + binding_t *binds; +} evtypebinds_t; + // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -53,19 +56,16 @@ static void B_EventBuilder(char *buff, event_t *ev); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- -extern action_t *ddactions; - // PUBLIC DATA DEFINITIONS ------------------------------------------------- -binding_t *binds = NULL; -int numBinds = 0; - bindclass_t *bindClasses = NULL; -int numBindClasses = 0; -int maxBindClasses = 0; +unsigned int numBindClasses = 0; +static unsigned int maxBindClasses = 0; // PRIVATE DATA DEFINITIONS ------------------------------------------------ +static evtypebinds_t evBindTypes[NUM_EVENT_TYPES]; + static keyname_t keyNames[] = { {DDKEY_PAUSE, "pause"}, {DDKEY_ESCAPE, "escape"}, @@ -132,59 +132,76 @@ static char *povDirNames[] = { // Binding classes are created dynamically at runtime. During (pre)init the // game register the classes it NEEDS. The order of the bind Classes in the -// array (the class stack) determines the order in which bindings are checked -// in B_Responder(). Thus it is important that bind classes are created in the -// correct order (game specific). +// array (the class stack) determines the order in which bindings are +// checked in B_Responder(). Thus it is important that bind classes are +// created in the correct order (game specific). -// It would also be possible for users to create any additional binding classes -// they required at runtime via console commands. -// However that would mean a fair amount of extra book keeping, so for now there -// are three generic classes which can be used for this purpose. +// It would also be possible for users to create any additional binding +// classes they required at runtime via console commands. +// However that would mean a fair amount of extra book keeping, so for now +// there are three generic classes which can be used for this purpose. // Bindings are saved with the classnames eg: // bind game +w +forward -// However, omission of the class name defaults the bind to class 0 (id 1) +// However, omission of the class name defaults the bind to class 0 (id 0) // and the bindings in the cfg will be updated with the missing class names // automatically on exit (for reading old cfg files). // When a binding class is enabled/disabled we loop through the bindings -// looking for any that are bound to any keys/buttons being pressed at that time. -// If any are found we que extra up events that request a command in a specific -// binding class. Due to binding classes being ordered numericaly with the -// rule that only the command in the highest active binding class being executed -// we only need to check commands for bindings with a lower binding class id. - -// A binding class may be "absolute". This means that when the class is active, -// if there is no binding in the current class (while decending the bind class -// stack in B_Responder()) and that class is "absolute" - all classes BELOW the -// current will be ignored and no binding will be found for the event. -// The event is NOT eaten and may continue on down the event responder chain. +// looking for any that are bound to any keys/buttons being pressed at that +// time. If any are found we que extra up events that request a command in +// a specific binding class. Due to binding classes being ordered numericaly +// with the rule that only the command in the highest active binding class +// being executed we only need to check commands for bindings with a lower +// binding class id. + +// A binding class may be "absolute". This means that when the class is +// active, if there is no binding in the current class (while decending the +// bind class stack in B_Responder()) and that class is "absolute" - all +// classes BELOW the current will be ignored and no binding will be found +// for the event. The event is NOT eaten and may continue on down the event +// responder chain. bindclass_t ddBindClasses[] = { {"game", DDBC_NORMAL, 1, 0}, - {"class1", DDBC_UCLASS1, 0, 0}, // additonal classes that can be purposed by users - {"class2", DDBC_UCLASS2, 0, 0}, - {"class3", DDBC_UCLASS3, 0, 0}, + // additonal classes that can be purposed by users + {"class1", DDBC_UCLASS1, 0, 0}, + {"class2", DDBC_UCLASS2, 0, 0}, + {"class3", DDBC_UCLASS3, 0, 0}, {"biaseditor", DDBC_BIASEDITOR, 0, 0}, {NULL} }; // CODE -------------------------------------------------------------------- -/* +/** + * Called once on init. + */ +void B_Init(void) +{ + unsigned int i; + + for(i = 0; i < NUM_EVENT_TYPES; ++i) + { + evBindTypes[i].binds = NULL; + evBindTypes[i].num = 0; + } +} + +/** * Registers the engine's own binding classes. Called once during init. */ void B_RegisterBindClasses(void) { - int i; + unsigned int i; for(i = 0; ddBindClasses[i].name; ++i) DD_AddBindClass(ddBindClasses + i); } #if _DEBUG -const char* EventType_Str(int type) +const char* EventType_Str(evtype_t type) { static char typeStr[40]; struct evnttype_s { @@ -201,7 +218,7 @@ const char* EventType_Str(int type) { EV_POV, "pov"}, { 0, NULL} }; - int i; + unsigned int i; for(i = 0; evnts[i].str; ++i) if(evnts[i].type == type) @@ -212,130 +229,149 @@ const char* EventType_Str(int type) } #endif -/* +/** * Compares two sets of event data to see if they match. */ -static boolean B_EventMatch(evtype_t eventTypeA, int dataA, - evtype_t eventTypeB, int dataB) +static boolean B_EventMatch(evtype_t eventType, int dataA, int dataB) { boolean match = false; - // Check the type. - if(eventTypeA == eventTypeB) + // Check the data. + switch(eventType) { - // Check the data. - switch (eventTypeA) - { - case EV_KEY: - case EV_POV: - if(dataA == dataB) - match = true; - break; + case EV_KEY: + case EV_POV: + if(dataA == dataB) + match = true; + break; - case EV_MOUSE_BUTTON: - case EV_JOY_BUTTON: - if((dataA & dataB) != 0) - match = true; - break; + case EV_MOUSE_BUTTON: + case EV_JOY_BUTTON: + if((dataA & dataB) != 0) + match = true; + break; - default: - // We don't know what to compare... :-] - break; - } + default: + // We don't know what to compare... :-] + break; } //#if _DEBUG //if(match) Con_Message("B_EventDataMatch: (%s)\n", -// EventType_Str(eventTypeA)); +// EventType_Str(eventType)); //#endif return match; } -/* - * Searches the bindings array for a command which matches the search critera. +static binding_t *B_BindingForEvent(event_t *event) +{ + unsigned int i; + binding_t *bnd; + evtypebinds_t *bindGroup = &evBindTypes[event->type]; + + bnd = bindGroup->binds; + for(i = 0; i < bindGroup->num; ++i) + { + if(B_EventMatch(event->type, event->data1, bnd[i].data1)) + return &bnd[i]; + } + + return NULL; +} + +/** + * Searche event-type-specific binding array for a command which matches + * the search critera. + * + * @param event The event to find the command for. * - * @param eventType The type of event-binding to search for. - * @param data The data value to search for (eg key DDKEY_PGDN). - * @param forceClass Only search for bindings in this class. Set this - * parameter to -1 to search all classes. * @return char* Ptr to the found command ELSE NULL. */ -static char *B_GetCommandForEvent(evtype_t eventType, evstate_t eventState, - int data, int forceClass) +static char *B_GetCommandForEvent(event_t *ev) { - int i, k; binding_t *bnd; command_t *cmd; - boolean done = false; + unsigned int k; - for(i = 0, bnd = binds; i < numBinds && !done; ++i, bnd++) +//#if _DEBUG +//Con_Printf("B_GetCommandForEvent: ev type %i, ev state %i, " +// "ev useclass %i, ev noclass %s\n", +// ev->type, ev->state, ev->useclass, +// ev->noclass == false? "false": "true"); +//#endif + + bnd = B_BindingForEvent(ev); + if(bnd == NULL) + return NULL; + + if(!ev->noclass) // use a specific class? (active or not) + { + // FYI: These kind of events aren't sent via direct user input + // Only by "us" when we need to switch binding classes and a + // current input is active eg; a key is held down during the + // switch that has commands in multiple binding classes. + cmd = &bnd->commands[ev->useclass]; + if(cmd->command[ev->state]) + { +//#if _DEBUG +//Con_Message("B_GetCommandForEvent: Returned (%s) \"%s\"\n", +// bindClasses[ev->useclass].name, cmd->command[ev->state]); +//#endif + return cmd->command[ev->state]; + } + } + else { - // Do the parameters match those of this event-binding? - if(B_EventMatch(eventType, data, bnd->type, bnd->data1)) + unsigned int idx; + boolean done = false; + + // loop backwards through the active binding classes, the + // command in the highest binding class slot that is currently + // active is executed + for(k = 0; k < numBindClasses && !done; ++k) { - if(forceClass != -1) // use a specific class? (active or not) + idx = numBindClasses - 1 - k; + cmd = &bnd->commands[idx]; + + if(bindClasses[idx].active != 1) + continue; + + if(cmd->command[ev->state]) { - // FYI: These kind of events aren't sent via direct user input - // Only by "us" when we need to switch binding classes and a - // current input is active eg; a key is held down during the - // switch that has commands in multiple binding classes. - cmd = &bnd->commands[forceClass]; - if(cmd->command[eventState]) - { //#if _DEBUG -//Con_Message("B_GetCommandForEvent: Returned bindID %i (%s) \"%s\"\n", -// bnd - binds, bindClasses[forceClass].name, -// cmd->command[eventState]); +//Con_Message("B_GetCommandForEvent: Returned (%s) \"%s\"\n", +// bindClasses[idx].name, cmd->command[ev->state]); //#endif - return cmd->command[eventState]; - } + return cmd->command[ev->state]; } else { - // loop backwards through the active binding classes, the - // command in the highest binding class slot that is currently - // active is executed - for(k = numBindClasses; k >= 0 && !done; --k) - { - cmd = &bnd->commands[k]; - - if(bindClasses[k].active == 1) - { - if(cmd->command[eventState]) - { -//#if _DEBUG -//Con_Message("B_GetCommandForEvent: Returned bindID %i (%s) \"%s\"\n", -// bnd - binds, bindClasses[k].name, cmd->command[eventState]); -//#endif - return cmd->command[eventState]; - } - else - { - // RULE: If a repeat event does not have a - // binding in BINDCLASS (k) we should ignore - // commands in all lower classes IF there is NOT - // a keydown binding for this event in this class. - if(eventState == EVS_REPEAT && cmd->command[EVS_DOWN]) - done = true; // do nothing - } - - // Should we ignore commands in lower classes? - if(bindClasses[k].absolute == 1) - done = true; - } - } + // RULE: If a repeat event does not have a + // binding in BINDCLASS (k) we should ignore + // commands in all lower classes IF there is NOT + // a down binding for this event in this class. + if(ev->state == EVS_REPEAT && cmd->command[EVS_DOWN]) + done = true; // do nothing } + + // Should we ignore commands in lower classes? + if(bindClasses[idx].flags & BCF_ABSOLUTE) + done = true; } } + +//#if _DEBUG +//Con_Printf("B_GetCommandForEvent: return NULL\n"); +//#endif return NULL; } -/* - * Checks to see if we need to respond to the given input event in some way - * and then if so executes the action associated to the event. +/** + * Checks to see if we need to respond to the given input event in + * some way and then if so executes the action associated to the event. * - * @return boolean true If any action was performed. + * @return boolean true If an action was executed. */ boolean B_Responder(event_t *ev) { @@ -346,7 +382,8 @@ boolean B_Responder(event_t *ev) return false; // Look for a command for this event. - cmd = B_GetCommandForEvent(ev->type, ev->state, ev->data1, ev->useclass); + cmd = B_GetCommandForEvent(ev); + if(cmd != NULL) { // Found one, execute! @@ -357,33 +394,35 @@ boolean B_Responder(event_t *ev) return false; // nope nothing. } -/* - * Returns a binding for the given event. +/** + * Returns a binding for the given event. */ -binding_t *B_GetBinding(event_t *event, boolean create_new) +static binding_t *B_GetBinding(event_t *event, boolean create_new) { - int i, j; - binding_t *newb; + unsigned int i; + int j; + binding_t *newb, *bnd; + evtypebinds_t *bindGroup; // We'll first have to search through the existing bindings // to see if there already is one for this event. - for(i = 0; i < numBinds; ++i) - { - if(B_EventMatch(event->type, event->data1, binds[i].type, - binds[i].data1)) - return binds + i; - } + bnd = B_BindingForEvent(event); + if(bnd != NULL) + return bnd; if(!create_new) return NULL; // Hmm, no luck there. Let's create a new binding_t. - binds = M_Realloc(binds, sizeof(binding_t) * (numBinds + 1)); - newb = binds + numBinds++; + bindGroup = &evBindTypes[event->type]; + bindGroup->binds = + M_Realloc(bindGroup->binds, sizeof(binding_t) * (bindGroup->num + 1)); + + newb = bindGroup->binds + bindGroup->num++; memset(newb, 0, sizeof(*newb)); newb->commands = M_Malloc(sizeof(command_t) * maxBindClasses); - for(i = 0; i < maxBindClasses; ++i) + for(i = 0; i < numBindClasses; ++i) for(j = 0; j < 3; ++j) newb->commands[i].command[j] = NULL; @@ -393,74 +432,72 @@ binding_t *B_GetBinding(event_t *event, boolean create_new) return newb; } -/* - * - */ -void B_DeleteBindingIdx(int index) +static void B_DeleteBindingIdx(unsigned int index, unsigned int group) { - int i, k; + unsigned int i; + int k; + evtypebinds_t *bindGroup = &evBindTypes[group]; + binding_t *bnd; - if(index < 0 || index > numBinds - 1) + if(index > bindGroup->num - 1) return; // What? + bnd = &bindGroup->binds[index]; for(i = 0; i < numBindClasses; ++i) for(k = 0; k < 3; ++k) - if(binds[index].commands[i].command[k]) + if(bnd->commands[i].command[k]) { - M_Free(binds[index].commands[i].command[k]); - binds[index].commands[i].command[k] = NULL; + M_Free(bnd->commands[i].command[k]); + bnd->commands[i].command[k] = NULL; } - M_Free(binds[index].commands); + M_Free(bnd->commands); - if(index < numBinds - 1) // If not the last one, do some rollback. + if(index < bindGroup->num - 1) // If not the last one, do some rollback. { - memmove(binds + index, binds + index + 1, - sizeof(binding_t) * (numBinds - index - 1)); + memmove(bindGroup->binds + index, bindGroup->binds + index + 1, + sizeof(binding_t) * (bindGroup->num - index - 1)); } - binds = realloc(binds, sizeof(binding_t) * --numBinds); + bindGroup->binds = + M_Realloc(bindGroup->binds, sizeof(binding_t) * --bindGroup->num); } -/* - * Binds the given event to the command. Also Rebinds old bindings. +/** + * Binds the given event to the command. Also Rebinds old bindings. * - * 1) Binding to NULL without specifying a class: deletes the binding. + * 1) Binding to NULL without specifying a class: deletes the binding. * - * 2) Bindind to NULL and specifying a class: clears the command and - * if no more commands exist for this binding - will delete it + * 2) Bindind to NULL and specifying a class: clears the command and + * if no more commands exist for this binding - will delete it */ -void B_Bind(event_t *event, char *command, int bindClass) +void B_Bind(event_t *event, char *command, unsigned int bindClass) { - int i, k, count = 0; + unsigned int i, k, count = 0; binding_t *bnd = B_GetBinding(event, true); if(!command) // No string given? { - // What about a bind class? - if(bindClass < 0) - B_DeleteBindingIdx(bnd - binds); // nope, delete. - else - { - // clear the command in bindClass only - for(i = 0; i < numBindClasses; ++i) - for(k = 0; k < 3; ++k) - if(bnd->commands[i].command[k]) - { - count++; - if(i == bindClass && k == event->state) - bnd->commands[i].command[k] = NULL; - } + // clear the command in bindClass only + for(i = 0; i < numBindClasses; ++i) + for(k = 0; k < 3; ++k) + if(bnd->commands[i].command[k]) + { + if(i == bindClass && k == event->state) + bnd->commands[i].command[k] = NULL; + + count++; + } + + if(count == 1) + // there are no more commands for this binding so delete. + B_DeleteBindingIdx(bnd - evBindTypes[event->type].binds, event->type); - if(count == 1) - // there are no more commands for this binding so delete. - B_DeleteBindingIdx(bnd - binds); - } return; } // Set the command. bnd->commands[bindClass].command[event->state] = - realloc(bnd->commands[bindClass].command[event->state], + M_Realloc(bnd->commands[bindClass].command[event->state], strlen(command) + 1); strcpy(bnd->commands[bindClass].command[event->state], command); @@ -471,90 +508,114 @@ void B_Bind(event_t *event, char *command, int bindClass) //#endif } -/* - * - */ -void B_ClearBinding(char *command, int bindClass) +void B_ClearBinding(char *command, unsigned int bindClass, boolean allClasses) { - int i, j, k, count; - boolean match; + int k; + unsigned int i, j, g; + evtypebinds_t *bindGroup; + binding_t *bnd; - for(i = 0; i < numBinds; ++i) + if(allClasses) // clear all commands in all binding classes, all states. { - match = false; - count = 0; - if(bindClass == -1) + for(g = 0; g < NUM_EVENT_TYPES; ++g) { - // clear all commands in all binding classes, all states. - for(j = 0; j < numBindClasses; ++j) - for(k = 0; k < 3; ++k) - if(binds[i].commands[j].command[k]) - if(!stricmp(binds[i].commands[j].command[k], command)) - B_DeleteBindingIdx(i--); + bindGroup = &evBindTypes[g]; + bnd = bindGroup->binds; + + for(i = 0; i < bindGroup->num; ++i) + for(j = 0; j < numBindClasses; ++j) + for(k = 0; k < 3; ++k) + if(bnd[i].commands[j].command[k]) + if(!stricmp(bnd[i].commands[j].command[k], command)) + B_DeleteBindingIdx(i--, g); } - else + } + else // clear the command in bindClass only, all states. + { + unsigned int count; + boolean match; + + for(g = 0; g < NUM_EVENT_TYPES; ++g) { - // clear the command in bindClass only, all states. - for(j = 0; j < numBindClasses; ++j) + bindGroup = &evBindTypes[g]; + bnd = bindGroup->binds; + + for(i = 0; i < bindGroup->num; ++i) { - for(k = 0; k < 3; ++k) - if(binds[i].commands[j].command[k]) - { - count++; - if((!stricmp(binds[i].commands[j].command[k], command)) && - j == bindClass) + match = false; + count = 0; + + for(j = 0; j < numBindClasses; ++j) + { + for(k = 0; k < 3; ++k) + if(bnd[i].commands[j].command[k]) { - match = true; - binds[i].commands[j].command[k] = NULL; + count++; + if((!stricmp(bnd[i].commands[j].command[k], command)) && + j == bindClass) + { + match = true; + bnd[i].commands[j].command[k] = NULL; + } } - } - } + } - if(match && count == 1) - // there are no more commands for this binding so delete. - B_DeleteBindingIdx(i--); + if(match && count == 1) + // there are no more commands for this binding so delete. + B_DeleteBindingIdx(i--, g); + } } } } -/* +/** * Deallocates the memory for the commands and bindings. */ -void B_Shutdown() +void B_Shutdown(void) { - int i, j, k; + int k; + unsigned int i, j, g; + evtypebinds_t *bindGroup; + binding_t *bnd; - for(i = 0; i < numBinds; ++i) + for(g = 0; g < NUM_EVENT_TYPES; ++g) { - for(j = 0; j < numBindClasses; ++j) + bindGroup = &evBindTypes[g]; + bnd = bindGroup->binds; + + for(i = 0; i < bindGroup->num; ++i) { - for(k = 0; k < 3; ++k) - if(binds[i].commands[j].command[k]) - free(binds[i].commands[j].command[k]); + for(j = 0; j < numBindClasses; ++j) + { + for(k = 0; k < 3; ++k) + if(bnd[i].commands[j].command[k]) + M_Free(bnd[i].commands[j].command[k]); + } + + M_Free(bnd[i].commands); } - free(binds[i].commands); + M_Free(bindGroup->binds); + bindGroup->binds = NULL; + bindGroup->num = 0; } - free(binds); - binds = NULL; - numBinds = 0; // Now we can clear the bindClasses - for(i = 0; i < numBindClasses; ++i) - free(bindClasses[i].name); + for(j = 0; j < numBindClasses; ++j) + M_Free(bindClasses[j].name); - free(bindClasses); + M_Free(bindClasses); bindClasses = NULL; numBindClasses = maxBindClasses = 0; } -/* +/** * shortNameForKey - * If buff is "" upon returning, the key is not valid for controls. + * If buff is "" upon returning, the key is not valid for controls. */ static char *shortNameForKey(int ddkey) { - int i; + unsigned int i; for(i = 0; keyNames[i].key; ++i) if(ddkey == keyNames[i].key) @@ -562,12 +623,9 @@ static char *shortNameForKey(int ddkey) return NULL; } -/* - * getByShortName - */ static int getByShortName(const char *key) { - int i; + unsigned int i; for(i = 0; keyNames[i].key; ++i) if(!strnicmp(key, keyNames[i].name, strlen(keyNames[i].name))) @@ -575,12 +633,9 @@ static int getByShortName(const char *key) return 0; } -/* - * buttonNumber - */ static int buttonNumber(int flags) { - int i; + unsigned int i; for(i = 0; i < 32; ++i) if(flags & (1 << i)) @@ -588,7 +643,7 @@ static int buttonNumber(int flags) return -1; } -/* +/** * Converts a textual representation of an event to the real thing. * Buff must be valid source buffer ev a valid destination. * @@ -615,28 +670,28 @@ static void B_EventBuilder(char *buff, event_t *ev) // First check the obvious cases. if(!strnicmp(begin, "mb", 2)) // Mouse button? { - ev->type = EV_MOUSE_BUTTON; + ev->type = EV_MOUSE_BUTTON; ev->state = (prefix == '+' ? EVS_DOWN : EVS_UP); ev->data1 = 1 << (atoi(begin + 2) - 1); } else if(!strnicmp(begin, "mw", 2)) // Mouse wheel? { - ev->type = EV_MOUSE_BUTTON; + ev->type = EV_MOUSE_BUTTON; ev->state = (prefix == '+' ? EVS_DOWN : EVS_UP); ev->data1 = !stricmp(begin + 2, "up") ? DDMB_MWHEELUP : DDMB_MWHEELDOWN; } else if(!strnicmp(begin, "jb", 2)) // Joystick button? { - ev->type = EV_JOY_BUTTON; + ev->type = EV_JOY_BUTTON; ev->state = (prefix == '+' ? EVS_DOWN : EVS_UP); ev->data1 = 1 << (atoi(begin + 2) - 1); } else if(!strnicmp(begin, "pov", 3)) // A POV angle? { - int i; + unsigned int i; - ev->type = EV_POV; + ev->type = EV_POV; ev->state = (prefix == '+' ? EVS_DOWN : EVS_UP); ev->data1 = -1; for(i = 0; povDirNames[i]; ++i) @@ -648,10 +703,11 @@ static void B_EventBuilder(char *buff, event_t *ev) } else { - ev->type = EV_KEY; + ev->type = EV_KEY; ev->state = (prefix == '+' ? EVS_DOWN : (prefix == '*' ? EVS_REPEAT : EVS_UP)); + if((key = getByShortName(begin))) ev->data1 = key; else @@ -659,14 +715,14 @@ static void B_EventBuilder(char *buff, event_t *ev) } } -/* - * Forms a textual representation for an input event. - * Part of the Doomsday public API. +/** + * Forms a textual representation for an input event. + * Part of the Doomsday public API. * - * @param buff Destination buffer to hold the formed string. - * @param type The event type (e.g. EV_KEY = keyboard). - * @param state The event state (EVS_DOWN/EVS_UP/EVS_REPEAT). - * @param data Usage depends on type eg keynumber. + * @param buff Destination buffer to hold the formed string. + * @param type The event type (e.g. EV_KEY = keyboard). + * @param state The event state (EVS_DOWN/EVS_UP/EVS_REPEAT). + * @param data Usage depends on type eg keynumber. */ void B_FormEventString(char *buff, evtype_t type, evstate_t state, int data1) @@ -674,7 +730,7 @@ void B_FormEventString(char *buff, evtype_t type, evstate_t state, char prefix[3] = {'+', '-', '*'}; char *begin; - if(state < EVS_DOWN || state > EVS_REPEAT) + if(state > EVS_REPEAT) Con_Error("B_FormEventString: bad event state (%d)\n", state); switch (type) @@ -711,9 +767,302 @@ void B_FormEventString(char *buff, evtype_t type, evstate_t state, } } -/* - * CCmdBind +void DD_AddBindClass(bindclass_t *newbc) +{ + unsigned int i, g; + bindclass_t *added; + + VERBOSE2(Con_Printf("DD_AddBindClass: %s.\n", newbc->name)); + + if(++numBindClasses > maxBindClasses) + { + // Allocate more memory. + maxBindClasses *= 2; + if(maxBindClasses < numBindClasses) + maxBindClasses = numBindClasses; + + bindClasses = M_Realloc(bindClasses, sizeof(bindclass_t) * maxBindClasses); + + for(g = 0; g < NUM_EVENT_TYPES; ++g) + { + binding_t *bnd; + unsigned int num; + + bnd = evBindTypes[g].binds; + num = evBindTypes[g].num; + for(i = 0; i < num; ++i) + { + bnd[i].commands = + M_Realloc(bnd[i].commands, sizeof(command_t) * maxBindClasses); + } + } + } + + added = &bindClasses[numBindClasses - 1]; + memcpy(added, newbc, sizeof(bindclass_t)); + added->id = numBindClasses - 1; + + // Allocate a copy of the class name. + added->name = strdup(newbc->name); +} + +/** + * Enables/disables binding classes + * Wrapper for the game dll. + * This way we can allow users to create their own binding classes that + * can be placed anywhere in the bindClass stack without the dll having to + * keep track of the classIDs + */ +boolean DD_SetBindClass(unsigned int classID, unsigned int type) +{ + // creation of user bind classes not implemented yet so there is no offset + return B_SetBindClass(classID, type); +} + +/** + * Enables/disables binding classes + * Ques extra input events as required + */ +boolean B_SetBindClass(unsigned int classID, unsigned int type) +{ + unsigned int i, k, g, count; + binding_t *bind; + + // Change the active state of the bindClass + switch(type) + { + case 0: // implicitly set + case 1: + bindClasses[classID].active = type? 1 : 0; + break; + case 2: // toggle + bindClasses[classID].active = bindClasses[classID].active? 0 : 1; + break; + default: + Con_Error("B_SetBindClass: Unknown state change value %i", type); + } + + VERBOSE2(Con_Printf("B_SetBindClass: %s %s %s.\n", + bindClasses[classID].name, + (type==2)? "TOGGLE" : "SET", + bindClasses[classID].active? "ON" : "OFF")); + + // Now we need to do a check in case there are keys currently + // being pressed that should be released if the event binding they are + // bound too has commands in the bind class being enabled/disabled. + + // loop through the bindings + for(g=0; g < NUM_EVENT_TYPES; ++g) + for(i=0, bind = evBindTypes[g].binds; i < evBindTypes[g].num; ++i, bind++) + { + // we're only interested in bindings for down events currently being pressed + // that have a binding in the class being enabled/disabled (classID) + if(!(bind->commands[classID].command[EVS_DOWN] != NULL && + ((bind->type == EV_KEY && (DD_IsKeyDown(bind->data1))) || + (bind->type == EV_MOUSE_BUTTON && (DD_IsMouseBDown(bind->data1))) || + (bind->type == EV_JOY_BUTTON && (DD_IsJoyBDown(bind->data1))) ))) + continue; + + count = 0; + // loop through the commands for this binding, + // count the number of commands for this binding that are for currently active + // bind classes with a lower id than the class being enabled/disabled (i) + for(k = 0; k < numBindClasses; ++k) + if(bindClasses[k].active && bind->commands[k].command[EVS_DOWN]) + { + // if there is a command for this event binding in a class that is + // currently active (current is k), that has a greater id than the + // class being enabled/disabled (classID) then we don't need to que + // any extra events at all as that will have been done when the binding + // class with the higher id was enabled. The commands in the lower + // classes can't have been active (for this event), as the highest + // class command is ALWAYS executed unless a specific class is requested. + if(k > classID) + { + // don't need to que any extra events + count = 0; + break; + } + else + count++; + } + + if(count > 0) + { + // We need to send up events with a forced binding + // command request for all the binding classes with a + // lower id than the class being enabled/disabled (classID) + // that are also active. + for(k = 0; k < classID; ++k) + { + if(bindClasses[k].active && bind->commands[k].command[EVS_UP]) + { + event_t ev; + // que an up event for this down event. + ev.type = bind->type; + ev.data1 = bind->data1; + ev.state = EVS_UP; + + // request a command in this class + ev.useclass = bindClasses[k].id; + ev.noclass = false; + // Finally, post the event + DD_PostEvent(&ev); + } + } + } + + // Also send an up event for this binding if the currently + // currently active command is in the class being disabled + // and it has the highest id of the active bindClass commands + // for this binding + for(k = 0; k < numBindClasses; ++k) + { + unsigned int idx = numBindClasses - 1 - k; + + if((idx > classID && bindClasses[idx].active && + bind->commands[idx].command[EVS_DOWN]) || idx < classID) + break; + + if(!bindClasses[idx].active && bind->commands[idx].command[EVS_DOWN]) + { + event_t ev; + // Que an up event for this down event. + ev.type = bind->type; + ev.data1 = bind->data1; + ev.state = EVS_UP; + + // Request a command in this class + ev.useclass = bindClasses[idx].id; + ev.noclass = false; + // Finally, post the event + DD_PostEvent(&ev); + } + } + } + + return true; +} + +void B_WriteToFile(FILE * file) +{ + int j; + unsigned int i, k, g, num, count; + char buffer[20]; + binding_t *bnd; + + for(k = 0; k < numBindClasses; ++k) + { + for(g = 0; g < NUM_EVENT_TYPES; ++g) + { + count = 0; + bnd = evBindTypes[g].binds; + num = evBindTypes[g].num; + for(i = 0; i < num; ++i) + { + for(j = 0; j < 3; ++j) + { + B_FormEventString(buffer, bnd[i].type, j, bnd[i].data1); + if(bnd[i].commands[k].command[j]) + { + fprintf(file, "bind "); + fprintf(file, "%s ", bindClasses[k].name); + fprintf(file, "%s", buffer); + fprintf(file, " \""); + + M_WriteTextEsc(file, bnd[i].commands[k].command[j]); + fprintf(file, "\"\n"); + + count++; + } + } + } + + if(count > 0) + fprintf(file,"\n"); + } + } +} + +/** + * Returns the number of bindings. The buffer will be filled with the + * names of the events. Part of the Doomsday public API. + */ +int B_BindingsForCommand(char *command, char *buffer, unsigned int bindClass, + boolean allClasses) +{ + int j; + unsigned int i, k, g, count = 0; + char bindname[20]; + binding_t *bnd; + unsigned int num; + + strcpy(buffer, ""); + + if(bindClass > numBindClasses) + return count; + + if(allClasses) // check all bindclasses + { + for(g = 0; g < NUM_EVENT_TYPES; ++g) + { + bnd = evBindTypes[g].binds; + num = evBindTypes[g].num; + + for(i = 0; i < num; ++i) + for(k = 0; k < numBindClasses; ++k) + for(j = 0; j < 3; ++j) + if(bnd[i].commands[k].command[j]) + { + B_FormEventString(bindname, bnd[i].type, j, bnd[i].data1); + if(!stricmp(command, bnd[i].commands[k].command[j])) + { + if(buffer[0]) // If the buffer is not empty... + strcat(buffer, " "); + strcat(buffer, bindname); + + count++; + } + } + } + } + else // only check bindClass + { + for(g = 0; g < NUM_EVENT_TYPES; ++g) + { + bnd = evBindTypes[g].binds; + num = evBindTypes[g].num; + + for(i = 0; i < num; ++i) + for(j = 0; j < 3; ++j) + if(bnd[i].commands[bindClass].command[j]) + { + B_FormEventString(bindname, bnd[i].type, j, bnd[i].data1); + if(!stricmp(command, bnd[i].commands[bindClass].command[j])) + { + if(buffer[0]) // If the buffer is not empty... + strcat(buffer, " "); + strcat(buffer, bindname); + + count++; + } + } + } + } + return count; +} + +/** + * Return the key code that corresponds the given key identifier name. + * Part of the Doomsday public API. */ +int DD_GetKeyCode(const char *key) +{ + int code = getByShortName(key); + + return code ? code : key[0]; +} + D_CMD(Bind) { boolean prefixGiven = true; @@ -726,7 +1075,8 @@ D_CMD(Bind) int repeat = !stricmp(argv[0], "bindr") || !stricmp(argv[0], "safebindr"); int safe = !strnicmp(argv[0], "safe", 4); - int i, bc = -1; + unsigned int bc; + unsigned int i; binding_t *existing; if(argc < 2 || argc > 4) @@ -735,6 +1085,7 @@ D_CMD(Bind) Con_Printf("Binding Classes:\n"); for(i = 0; i < numBindClasses; ++i) Con_Printf(" %s\n", bindClasses[i].name); + return true; } @@ -760,7 +1111,7 @@ D_CMD(Bind) } begin = evntptr; - if(strlen(evntptr) > 1) // Can the event have a prefix? + if(strlen(evntptr) > 1) // Can the event have a prefix? { prefix = evntptr[0]; begin = evntptr + 1; @@ -778,7 +1129,7 @@ D_CMD(Bind) ((argc == 2) && !prefixGiven && !bindClassGiven)) { char prefixes[3] = { '+', '-', '*' }; - int i; + unsigned int i; // We're clearing a binding. If no prefix has been given, // all event states (+, - and *) are all cleared. @@ -817,7 +1168,8 @@ D_CMD(Bind) } sprintf(validEventName, "%c%s", prefix, begin); - //Con_Printf( "Binding %s : %s.\n", validEventName, argc==2? "(nothing)" : cmdptr); +//Con_Printf("Binding %s : %s.\n", validEventName, +// argc==2? "(nothing)" : cmdptr); // Convert the name to an event. B_EventBuilder(validEventName, &event); @@ -855,9 +1207,11 @@ D_CMD(ClearBindings) D_CMD(DeleteBind) { - int i, bc = -1; + int j; + unsigned int i, bc; int start = 1; char *cmdptr = argv[1]; + boolean bcSpecified; if(argc < 2) { @@ -867,6 +1221,7 @@ D_CMD(DeleteBind) } // Check for a specified binding class + bcSpecified = false; if(argc > 2) for(i = 0 ; i < numBindClasses; ++i) { @@ -882,6 +1237,7 @@ D_CMD(DeleteBind) else { bc = i; + bcSpecified = true; cmdptr = argv[2]; start = 2; break; @@ -889,10 +1245,10 @@ D_CMD(DeleteBind) } } - if(bc == -1 || bc < numBindClasses) + if(!bcSpecified || bc < numBindClasses) { - for(i = start; i < argc && cmdptr; cmdptr = argv[i++]) - B_ClearBinding(cmdptr, bc); + for(j = start; j < argc && cmdptr; cmdptr = argv[j++]) + B_ClearBinding(cmdptr, bc, !bcSpecified); } else { @@ -905,7 +1261,7 @@ D_CMD(DeleteBind) D_CMD(ListBindClasses) { - int k; + unsigned int k; // Show the available binding classes Con_Printf("Binding Classes:\n"); @@ -918,115 +1274,92 @@ D_CMD(ListBindClasses) D_CMD(ListBindings) { - int i, j, k, onlythis = -1; - int comcount = 0; + int k; + unsigned int i, j, g, num, comcount = 0, onlythis = 0; char buffer[20]; + binding_t *bnd; + unsigned int totalBinds = 0; + boolean specificClass = false; // Are we showing bindings in a particular class only? if(argc >= 2) { - for(k = 0; k < numBindClasses; ++k) - if(!stricmp(argv[1], bindClasses[k].name)) + for(j = 0; j < numBindClasses; ++j) + if(!stricmp(argv[1], bindClasses[j].name)) { // only show bindings in this class - onlythis = bindClasses[k].id; + onlythis = bindClasses[j].id; + specificClass = true; } } - // loop through the bindings - for(i = 0; i < numBinds; ++i) + for(g = 0; g < NUM_EVENT_TYPES; ++g) { - // loop through the bindclasses - for(j = 0; j < numBindClasses; ++j) + bnd = evBindTypes[g].binds; + num = evBindTypes[g].num; + totalBinds += num; + + // loop through the bindings + for(i = 0; i < num; ++i) { - for(k = 0; k < 3; ++k) // for each event state + // loop through the bindclasses + for(j = 0; j < numBindClasses; ++j) { - if(binds[i].commands[j].command[k]) + for(k = 0; k < 3; ++k) // for each event state { - B_FormEventString(buffer, binds[i].type, k, binds[i].data1); + if(!bnd[i].commands[j].command[k]) + continue; + + B_FormEventString(buffer, bnd[i].type, k, bnd[i].data1); if(argc >= 2) { - if(onlythis == -1 && strnicmp(buffer + 1, argv[1], strlen(argv[1]))) + if(!specificClass && strnicmp(buffer + 1, argv[1], strlen(argv[1]))) continue; // Doesn't match the search pattern. else { if(argc >= 3) { if(strnicmp(buffer + 1, argv[2], strlen(argv[2])) || - (j != -1 && j != onlythis)) + (specificClass && j != onlythis)) continue; // Doesn't match the search pattern } - else if(onlythis != -1 && j != onlythis) + else if(specificClass && j != onlythis) continue; // Doesn't match the search pattern } } comcount++; - if(onlythis != -1) - Con_Printf("%-8s : %s\n", buffer, binds[i].commands[j].command[k]); + if(specificClass) + Con_Printf("%-8s : %s\n", buffer, bnd[i].commands[j].command[k]); else Con_Printf("%-8s : %s : %s\n", buffer, bindClasses[j].name, - binds[i].commands[j].command[k]); + bnd[i].commands[j].command[k]); } } } } - if(onlythis != -1) + if(specificClass) { Con_Printf("Showing %d (%s class) commands from %d bindings.\n", - comcount, bindClasses[onlythis].name, numBinds); + comcount, bindClasses[onlythis].name, totalBinds); } else { Con_Printf("Showing %d commands from %d bindings.\n", - comcount, numBinds); + comcount, totalBinds); } return true; } -/* - * Add a new binding class - */ -void DD_AddBindClass(bindclass_t *newbc) -{ - int i; - bindclass_t *added; - - VERBOSE2(Con_Printf("DD_AddBindClass: %s.\n", newbc->name)); - - if(++numBindClasses > maxBindClasses) - { - // Allocate more memory. - maxBindClasses *= 2; - if(maxBindClasses < numBindClasses) - maxBindClasses = numBindClasses; - - bindClasses = realloc(bindClasses, sizeof(bindclass_t) * maxBindClasses); - - for(i = 0; i < numBinds; ++i) - { - binds[i].commands = realloc(binds[i].commands, - sizeof(command_t) * maxBindClasses); - } - } - - added = &bindClasses[numBindClasses - 1]; - memcpy(added, newbc, sizeof(bindclass_t)); - added->id = numBindClasses - 1; - - // Allocate a copy of the class name. - added->name = strdup(newbc->name); -} - -/* +/** * Enables/disables binding classes * Ques extra input events as required */ D_CMD(EnableBindClass) { - int i = -1; + unsigned int i; if(argc < 2 || argc > 3) { @@ -1050,7 +1383,7 @@ D_CMD(EnableBindClass) } } - if(i >= 0 && i < numBindClasses) + if(i < numBindClasses) { if(B_SetBindClass(i, (argc == 3)? atoi(argv[2]) : 2)) return true; @@ -1060,227 +1393,3 @@ D_CMD(EnableBindClass) return false; } - -/* - * Enables/disables binding classes - * Wrapper for the game dll. - * This way we can allow users to create their own binding classes that can be placed - * anywhere in the bindClass stack without the dll having to keep track of the classIDs - */ -boolean DD_SetBindClass(int classID, int type) -{ - // creation of user bind classes not implemented yet so there is no offset - return B_SetBindClass(classID, type); -} - -/* - * Enables/disables binding classes - * Ques extra input events as required - */ -boolean B_SetBindClass(int classID, int type) -{ - int i, k; - int count; - binding_t *bind; - - // Change the active state of the bindClass - switch(type) - { - case 0: // implicitly set - case 1: - bindClasses[classID].active = type? 1 : 0; - break; - case 2: // toggle - bindClasses[classID].active = bindClasses[classID].active? 0 : 1; - break; - } - - VERBOSE2(Con_Printf("B_SetBindClass: %s %s %s.\n", - bindClasses[classID].name, - (type==2)? "TOGGLE" : "SET", - bindClasses[classID].active? "ON" : "OFF")); - - // Now we need to do a check in case there are keys currently - // being pressed that should be released if the event binding they are - // bound too has commands in the bind class being enabled/disabled. - - // loop through the bindings - for(i=0, bind = binds; i < numBinds; ++i, ++bind) - { - // we're only interested in bindings for down events currently being pressed - // that have a binding in the class being enabled/disabled (classID) - if(bind->commands[classID].command[EVS_DOWN] != NULL && - ( (bind->type == EV_KEY && (DD_IsKeyDown(bind->data1))) || - (bind->type == EV_MOUSE_BUTTON && (DD_IsMouseBDown(bind->data1))) || - (bind->type == EV_JOY_BUTTON && (DD_IsJoyBDown(bind->data1))) )) - { - count = 0; - // loop through the commands for this binding, - // count the number of commands for this binding that are for currently active - // bind classes with a lower id than the class being enabled/disabled (i) - for(k = 0; k < numBindClasses; ++k) - if(bindClasses[k].active && bind->commands[k].command[EVS_DOWN]) - { - // if there is a command for this event binding in a class that is - // currently active (current is k), that has a greater id than the - // class being enabled/disabled (classID) then we don't need to que - // any extra events at all as that will have been done when the binding - // class with the higher id was enabled. The commands in the lower - // classes can't have been active (for this event), as the highest - // class command is ALWAYS executed unless a specific class is requested. - if(k > classID) - { - // don't need to que any extra events - count = 0; - break; - } - else - count++; - } - - if(count > 0) - { - // We need to send up events with a forced binding - // command request for all the binding classes with a - // lower id than the class being enabled/disabled (classID) - // that are also active. - for(k = 0; k < classID; ++k) - { - if(bindClasses[k].active && bind->commands[k].command[EVS_UP]) - { - event_t ev; - // que an up event for this down event. - ev.type = bind->type; - ev.data1 = bind->data1; - ev.state = EVS_UP; - - // request a command in this class - ev.useclass = bindClasses[k].id; - // Finally, post the event - DD_PostEvent(&ev); - } - } - } - - // Also send an up event for this binding if the currently - // currently active command is in the class being disabled - // and it has the highest id of the active bindClass commands - // for this binding - for(k = numBindClasses - 1; k > 0; --k) - { - if((k > classID && bindClasses[k].active && - bind->commands[k].command[EVS_DOWN]) || k < classID) - break; - - if(!bindClasses[k].active && bind->commands[k].command[EVS_DOWN]) - { - event_t ev; - // que an up event for this down event. - ev.type = bind->type; - ev.data1 = bind->data1; - ev.state = EVS_UP; - - // request a command in this class - ev.useclass = bindClasses[k].id; - // Finally, post the event - DD_PostEvent(&ev); - } - } - } - } - - return true; -} - -void B_WriteToFile(FILE * file) -{ - int i, j, k, count; - char buffer[20]; - - for(k = 0; k < numBindClasses; ++k) - { - count = 0; - for(i = 0; i < numBinds; ++i) - { - for(j = 0; j < 3; ++j) - { - B_FormEventString(buffer, binds[i].type, j, binds[i].data1); - if(binds[i].commands[k].command[j]) - { - fprintf(file, "bind "); - fprintf(file, "%s ", bindClasses[k].name); - fprintf(file, "%s", buffer); - fprintf(file, " \""); - M_WriteTextEsc(file, binds[i].commands[k].command[j]); - fprintf(file, "\"\n"); - count++; - } - } - } - - if(count > 0) - fprintf(file,"\n"); - } -} - -/* - * Returns the number of bindings. The buffer will be filled with the - * names of the events. Part of the Doomsday public API. - */ -int B_BindingsForCommand(char *command, char *buffer, int bindClass) -{ - int i, j, k, count = 0; - char bindname[20]; - - strcpy(buffer, ""); - - if(bindClass > numBindClasses) - return count; - - for(i = 0; i < numBinds; ++i) - { - if(bindClass == -1) // check all bindclasses - { - for(k = 0; k < numBindClasses; ++k) - for(j = 0; j < 3; ++j) - if(binds[i].commands[k].command[j]) - { - B_FormEventString(bindname, binds[i].type, j, binds[i].data1); - if(!stricmp(command, binds[i].commands[k].command[j])) - { - if(buffer[0]) // If the buffer is not empty... - strcat(buffer, " "); - strcat(buffer, bindname); - count++; - } - } - } - else // only check bindClass - { - for(j = 0; j < 3; ++j) - if(binds[i].commands[bindClass].command[j]) - { - B_FormEventString(bindname, binds[i].type, j, binds[i].data1); - if(!stricmp(command, binds[i].commands[bindClass].command[j])) - { - if(buffer[0]) // If the buffer is not empty... - strcat(buffer, " "); - strcat(buffer, bindname); - count++; - } - } - } - } - return count; -} - -/* - * Return the key code that corresponds the given key identifier name. - * Part of the Doomsday public API. - */ -int DD_GetKeyCode(const char *key) -{ - int code = getByShortName(key); - - return code ? code : key[0]; -} diff --git a/doomsday/engine/portable/src/con_main.c b/doomsday/engine/portable/src/con_main.c index 305cc382b0..5ca7395a90 100644 --- a/doomsday/engine/portable/src/con_main.c +++ b/doomsday/engine/portable/src/con_main.c @@ -182,7 +182,7 @@ static int complPos; // Where is the completion cursor? static knownword_t **matchedWords; static unsigned int matchedWordCount; -static unsigned int lastCompletion; // The last completed known word match. +static int lastCompletion; // The last completed known word match. static boolean finishCompletion; // An autocomplete has taken place that must // be completed ASAP. @@ -392,6 +392,8 @@ void Con_Init(void) { cbuffer_t *buffer = &cBuffer; + B_Init(); + ConsoleActive = false; ConsoleInited = true; ConsoleTime = 0; @@ -1137,6 +1139,8 @@ static int completeWord(int mode) // Completion Mode 1: Cycle through the possible completions. unsigned int idx; + // fix me: signed/unsigned mismatch + // use another var to note when lastCompletion is not valid. if(lastCompletion == -1 || lastCompletion + 1 >= matchedWordCount) idx = 0; diff --git a/doomsday/engine/portable/src/dd_input.c b/doomsday/engine/portable/src/dd_input.c index 2121f59887..18af4567c1 100644 --- a/doomsday/engine/portable/src/dd_input.c +++ b/doomsday/engine/portable/src/dd_input.c @@ -214,7 +214,7 @@ void DD_DumpKeyMappings(char *fileName) int i; file = fopen(fileName, "wt"); - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) { fprintf(file, "%03i\t", i); fprintf(file, !isspace(keyMappings[i]) && @@ -222,7 +222,7 @@ void DD_DumpKeyMappings(char *fileName) } fprintf(file, "\n+Shift\n"); - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) { if(shiftKeyMappings[i] == i) continue; @@ -233,7 +233,7 @@ void DD_DumpKeyMappings(char *fileName) } fprintf(file, "-Shift\n\n+Alt\n"); - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) { if(altKeyMappings[i] == i) continue; @@ -252,7 +252,7 @@ void DD_DefaultKeyMapping(void) { int i; - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) { keyMappings[i] = scantokey[i]; shiftKeyMappings[i] = i >= 32 && i <= 127 && @@ -513,7 +513,7 @@ byte DD_KeyToScan(byte key) { int i; - for(i = 0; i < NUMKKEYS; i++) + for(i = 0; i < NUMKKEYS; ++i) if(keyMappings[i] == key) return i; return 0; @@ -548,9 +548,9 @@ void DD_ReadKeyboard(void) ev.type = EV_KEY; ev.state = EVS_REPEAT; - // Don't specify a class - ev.useclass = -1; - for(i = 0; i < MAX_DOWNKEYS; i++) + ev.noclass = true; // Don't specify a class + ev.useclass = 0; // initialize with something + for(i = 0; i < MAX_DOWNKEYS; ++i) { repeater_t *rep = keyReps + i; @@ -580,7 +580,7 @@ void DD_ReadKeyboard(void) numkeyevs = I_GetKeyEvents(keyevs, KBDQUESIZE); // Translate them to Doomsday keys. - for(i = 0; i < numkeyevs; i++) + for(i = 0; i < numkeyevs; ++i) { keyevent_t *ke = keyevs + i; @@ -612,7 +612,7 @@ void DD_ReadKeyboard(void) if(ev.state == EVS_DOWN) { // Find an empty repeater. - for(k = 0; k < MAX_DOWNKEYS; k++) + for(k = 0; k < MAX_DOWNKEYS; ++k) if(!keyReps[k].key) { keyReps[k].key = ev.data1; @@ -624,7 +624,7 @@ void DD_ReadKeyboard(void) else if(ev.state == EVS_UP) { // Clear any repeaters with this key. - for(k = 0; k < MAX_DOWNKEYS; k++) + for(k = 0; k < MAX_DOWNKEYS; ++k) if(keyReps[k].key == ev.data1) keyReps[k].key = 0; } @@ -677,8 +677,8 @@ void DD_ReadMouse(timespan_t ticLength) ev.data1 = mouse.x * DD_MICKEY_ACCURACY; ev.data2 = mouse.y * DD_MICKEY_ACCURACY; ev.data3 = mouse.z * DD_MICKEY_ACCURACY; - // Don't specify a class - ev.useclass = -1; + ev.noclass = true; // Don't specify a class + ev.useclass = 0; // initialize with something // Mouse axis data may be modified if not in UI mode. if(allowMouseMod) @@ -826,12 +826,12 @@ void DD_ReadJoystick(void) bstate = 0; // Check the buttons. - for(i = 0; i < IJOY_MAXBUTTONS; i++) + for(i = 0; i < IJOY_MAXBUTTONS; ++i) if(state.buttons[i]) bstate |= 1 << i; // Set the bits. - // Don't specify a class - ev.useclass = -1; + ev.noclass = true; // Don't specify a class + ev.useclass = 0; // initialize with something ev.state = 0; // Check for button state changes. diff --git a/doomsday/engine/portable/src/dd_loop.c b/doomsday/engine/portable/src/dd_loop.c index 13e4248608..9b7bb38231 100644 --- a/doomsday/engine/portable/src/dd_loop.c +++ b/doomsday/engine/portable/src/dd_loop.c @@ -413,7 +413,7 @@ void DD_RunTics(void) DD_Ticker(ticLength); // The netcode gets to tick, too. - Net_Ticker(ticLength); + Net_Ticker(/*ticLength*/); // Various global variables are used for counting time. DD_AdvanceTime(ticLength); diff --git a/doomsday/engine/portable/src/dd_zone.c b/doomsday/engine/portable/src/dd_zone.c index 105285c298..2f54e8ebbd 100644 --- a/doomsday/engine/portable/src/dd_zone.c +++ b/doomsday/engine/portable/src/dd_zone.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -39,12 +39,12 @@ * blocks. If the rover block isn't suitable, a new empty volume is created * without further checking. This is suitable for cases where lots of blocks * are being allocated in a rapid sequence, with no frees in between (e.g., - * map setup). + * map setup). * - * Block sequences. The PU_LEVELSTATIC purge tag has a special purpose. - * It works like PU_LEVEL so that it is purged on a per level basis, but + * Block sequences. The PU_LEVELSTATIC purge tag has a special purpose. + * It works like PU_LEVEL so that it is purged on a per level basis, but * blocks allocated as PU_LEVELSTATIC should not be freed at any time when the - * map is being used. Internally, the level-static blocks are linked into + * map is being used. Internally, the level-static blocks are linked into * sequences so that Z_Malloc knows to skip all of them efficiently. This is * possible because no block inside the sequence could be purged by Z_Malloc * anyway. @@ -149,14 +149,14 @@ void Z_EnableFastMalloc(boolean isEnabled) memvolume_t *Z_Create(size_t volumeSize) { memblock_t *block; - memvolume_t *vol = calloc(1, sizeof(memvolume_t)); + memvolume_t *vol = M_Calloc(sizeof(memvolume_t)); vol->next = volumeRoot; volumeRoot = vol; vol->size = volumeSize; // Allocate memory for the zone volume. - vol->zone = malloc(vol->size); + vol->zone = M_Malloc(vol->size); // Clear the start of the zone. memset(vol->zone, 0, sizeof(memzone_t) + sizeof(memblock_t)); @@ -215,12 +215,12 @@ void Z_Shutdown(void) Z_FreeTags(0, DDMAXINT); #endif - free(vol->zone); - free(vol); + M_Free(vol->zone); + M_Free(vol); } printf("Z_Shutdown: Used %i volumes, total %lu bytes.\n", - numVolumes, totalMemory); + numVolumes, (long unsigned int) totalMemory); } #ifdef FAKE_MEMORY_ZONE @@ -259,7 +259,7 @@ void Z_Free(void *ptr) VERBOSE( Con_Message("Z_Free: Warning: Attempt to free NULL ignored.\n") ); return; } - + block = Z_GetBlock(ptr); if(block->id != ZONEID) { @@ -277,7 +277,7 @@ void Z_Free(void *ptr) block->id = 0; #ifdef FAKE_MEMORY_ZONE - free(block->area); + M_Free(block->area); block->area = NULL; #endif @@ -289,13 +289,13 @@ void Z_Free(void *ptr) { memblock_t* first = block->seq_first; memblock_t* iter = first; - while(iter->seq_first == first) + while(iter->seq_first == first) { iter->seq_first = iter->seq_last = NULL; iter = iter->next; - } + } } - + other = block->prev; if(!other->user) { // merge with previous free block @@ -376,15 +376,15 @@ void *Z_Malloc(size_t size, int tag, void *user) start = base->prev; // If the start is in a sequence, move it to the beginning of the - // entire sequence. Sequences are handled as a single unpurgable entity, + // entire sequence. Sequences are handled as a single unpurgable entity, // so we can stop checking at its start. if(start->seq_first) { start = start->seq_first; } - + do - { + { if(rover == start) { // Scanned all the way around the list. @@ -447,7 +447,7 @@ void *Z_Malloc(size_t size, int tag, void *user) } #ifdef FAKE_MEMORY_ZONE - base->area = malloc(size - sizeof(memblock_t)); + base->area = M_Malloc(size - sizeof(memblock_t)); #endif if(user) @@ -467,7 +467,7 @@ void *Z_Malloc(size_t size, int tag, void *user) base->user = (void *) 2; // mark as in use, but unowned } base->tag = tag; - + if(tag == PU_LEVELSTATIC) { // Level-statics are linked into unpurgable sequences so they can @@ -565,7 +565,7 @@ void Z_CheckHeap(void) #ifdef _DEBUG VERBOSE2( printf("Z_CheckHeap\n") ); #endif - + for(volume = volumeRoot; volume; volume = volume->next) { for(block = volume->zone->blocklist.next; ; block = block->next) @@ -584,7 +584,7 @@ void Z_CheckHeap(void) Con_Error("Z_CheckHeap: two consecutive free blocks\n"); if(block->user == (void **) -1) Con_Error("Z_CheckHeap: bad user pointer %p\n", block->user); - + /* if(block->seq_first == block) { @@ -608,7 +608,7 @@ void Z_CheckHeap(void) } } } - + } } } @@ -742,13 +742,13 @@ size_t Z_FreeMemory(void) static void Z_AddBlockToSet(zblockset_t* set) { zblock_t* block = 0; - - // Get a new block by resizing the blocks array. This is done relatively + + // Get a new block by resizing the blocks array. This is done relatively // seldom, since there is a large number of elements per each block. set->count++; - set->blocks = Z_Recalloc(set->blocks, sizeof(zblock_t) * set->count, + set->blocks = Z_Recalloc(set->blocks, sizeof(zblock_t) * set->count, set->tag); - + // Initialize the block's data. block = &set->blocks[set->count - 1]; block->max = set->elementsPerBlock; @@ -770,20 +770,20 @@ void *Z_BlockNewElement(zblockset_t* set) // When this is called, there is always an available element in the topmost // block. We will return it. void* element = ((byte*)block->elements) + (block->elementSize * block->count); - + // Reserve the element. block->count++; - + // If we run out of space in the topmost block, add a new one. if(block->count == block->max) { - // Just being cautious: adding a new block invalidates existing + // Just being cautious: adding a new block invalidates existing // pointers to the blocks. block = 0; - Z_AddBlockToSet(set); + Z_AddBlockToSet(set); } - + return element; } @@ -816,7 +816,7 @@ zblockset_t *Z_BlockCreate(size_t sizeOfElement, unsigned int batchSize, // Allocate the first block right away. Z_AddBlockToSet(set); - + return set; } diff --git a/doomsday/engine/portable/src/def_read.c b/doomsday/engine/portable/src/def_read.c index 4fec3e7089..a0705c9f7b 100644 --- a/doomsday/engine/portable/src/def_read.c +++ b/doomsday/engine/portable/src/def_read.c @@ -544,7 +544,7 @@ static int ReadLabel(char *label) return true; } -static void DED_Include(ded_t * ded, char *fileName, directory_t * dir) +static void DED_Include(char *fileName, directory_t * dir) { char tmp[256], path[256]; @@ -708,7 +708,7 @@ static int DED_ReadData(ded_t *ded, char *buffer, const char *sourceFile) READSTR(tmp); CHECKSC; - DED_Include(ded, tmp, &fileDir); + DED_Include(tmp, &fileDir); strcpy(label, ""); } if(ISTOKEN("IncludeIf")) // An optional include. @@ -725,7 +725,7 @@ static int DED_ReadData(ded_t *ded, char *buffer, const char *sourceFile) READSTR(tmp); CHECKSC; - DED_Include(ded, tmp, &fileDir); + DED_Include(tmp, &fileDir); strcpy(label, ""); } else diff --git a/doomsday/engine/portable/src/edit_bias.c b/doomsday/engine/portable/src/edit_bias.c index 8bd4470e6f..3090614a38 100644 --- a/doomsday/engine/portable/src/edit_bias.c +++ b/doomsday/engine/portable/src/edit_bias.c @@ -19,7 +19,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -47,7 +47,7 @@ // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- extern void Con_ClearActions(void); -extern boolean B_SetBindClass(int classID, int type); +extern boolean B_SetBindClass(unsigned int classID, int type); // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -448,7 +448,7 @@ void SBE_SetHueCircle(boolean activate) { int i; - if(activate == editHueCircle) + if((signed) activate == editHueCircle) return; // No change in state. if(activate && SBE_GetGrabbed() == NULL) diff --git a/doomsday/engine/portable/src/gl_main.c b/doomsday/engine/portable/src/gl_main.c index 53182f31f4..b8c2a16f2f 100644 --- a/doomsday/engine/portable/src/gl_main.c +++ b/doomsday/engine/portable/src/gl_main.c @@ -334,7 +334,7 @@ void GL_MakeGammaRamp(unsigned short *ramp, float gamma, float contrast, bright = -0.8f; // Init the ramp as a line with the steepness defined by contrast. - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) ideal[i] = i * contrast - (contrast - 1) * 127; // Apply the gamma curve. @@ -343,16 +343,16 @@ void GL_MakeGammaRamp(unsigned short *ramp, float gamma, float contrast, if(gamma <= 0.1f) gamma = 0.1f; norm = pow(255, 1 / gamma - 1); // Normalizing factor. - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) ideal[i] = pow(ideal[i], 1 / gamma) / norm; } // The last step is to add the brightness offset. - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) ideal[i] += bright * 128; // Clamp it and write the ramp table. - for(i = 0; i < 256; i++) + for(i = 0; i < 256; ++i) { ideal[i] *= 0x100; // Byte => word if(ideal[i] < 0) @@ -409,7 +409,6 @@ const char* GL_ChooseVariableFont(glfontstyle_t style) glScreenHeight < MED_LIMIT ? "normalbold18" : "normalbold24"); } - return "normal18"; } void GL_InitFont(void) diff --git a/doomsday/engine/portable/src/gl_tex.c b/doomsday/engine/portable/src/gl_tex.c index f80bf44e3c..66759a480b 100644 --- a/doomsday/engine/portable/src/gl_tex.c +++ b/doomsday/engine/portable/src/gl_tex.c @@ -1781,7 +1781,7 @@ DGLuint GL_PrepareDDTexture(ddtexture_t which) "bbox" }; - if(which >= 0 && which < NUM_DD_TEXTURES) + if(which < NUM_DD_TEXTURES) { if(!ddTextures[which]) { @@ -1822,7 +1822,7 @@ void GL_SetFlat(int idx) * * Modified to allow taller masked textures - GMJ Aug 2002 */ -static int DrawRealPatch(byte *buffer, byte *palette, int texwidth, +static int DrawRealPatch(byte *buffer, /*byte *palette,*/ int texwidth, int texheight, patch_t *patch, int origx, int origy, boolean maskZero, unsigned char *transtable, boolean checkForAlpha) @@ -1993,7 +1993,8 @@ void GL_ConvertToAlpha(image_t * image, boolean makeWhite) byte *GL_LoadImage(image_t * img, const char *imagefn, boolean useModelPath) { DFILE *file; - byte *ckdest, ext[40], *in, *out; + byte *ckdest, *in, *out; + char ext[40]; int format, i, numpx; // Clear any old values. @@ -2304,7 +2305,7 @@ boolean GL_BufferTexture(texture_t *tex, byte *buffer, int width, int height, } // Draw the patch in the buffer. alphaChannel = - DrawRealPatch(buffer, palette, width, height, patch, + DrawRealPatch(buffer, /*palette,*/ width, height, patch, tex->patches[i].originx, tex->patches[i].originy, false, 0, i == tex->patchcount - 1); } @@ -2648,7 +2649,7 @@ void GL_BufferSkyTexture(int idx, byte **outbuffer, int *width, int *height, } */ for(i = 0; i < tex->patchcount; ++i) { - DrawRealPatch(imgdata, palette, tex->width, tex->height, + DrawRealPatch(imgdata, /*palette,*/ tex->width, tex->height, W_CacheLumpNum(tex->patches[i].patch, PU_CACHE), tex->patches[i].originx, tex->patches[i].originy, zeroMask, 0, false); @@ -2672,7 +2673,7 @@ void GL_BufferSkyTexture(int idx, byte **outbuffer, int *width, int *height, // Allocate a large enough buffer. numpels = tex->width * bufHeight; imgdata = M_Calloc(2 * numpels); - DrawRealPatch(imgdata, palette, tex->width, bufHeight, patch, 0, 0, + DrawRealPatch(imgdata, /*palette,*/ tex->width, bufHeight, patch, 0, 0, zeroMask, 0, false); } if(zeroMask && filloutlines) @@ -3217,7 +3218,7 @@ unsigned int GL_PrepareTranslatedSprite(int pnum, int tmap, int tclass) image.pixelSize = 1; image.pixels = M_Calloc(2 * image.width * image.height); - DrawRealPatch(image.pixels, W_CacheLumpNum(pallump, PU_CACHE), + DrawRealPatch(image.pixels, /*W_CacheLumpNum(pallump, PU_CACHE),*/ image.width, image.height, patch, 0, 0, false, table, false); } @@ -3282,7 +3283,7 @@ unsigned int GL_PrepareSprite(int pnum, int spriteMode) image.pixels = M_Calloc(2 * image.width * image.height); image.pixelSize = 1; - DrawRealPatch(image.pixels, W_CacheLumpNum(pallump, PU_CACHE), + DrawRealPatch(image.pixels, /*W_CacheLumpNum(pallump, PU_CACHE),*/ image.width, image.height, patch, 0, 0, false, 0, false); } @@ -3536,7 +3537,7 @@ void GL_PrepareLumpPatch(int lump) buffer = M_Calloc(2 * numpels); alphaChannel = - DrawRealPatch(buffer, W_CacheLumpNum(pallump, PU_CACHE), + DrawRealPatch(buffer, /*W_CacheLumpNum(pallump, PU_CACHE),*/ SHORT(patch->width), SHORT(patch->height), patch, 0, 0, false, 0, true); if(filloutlines) @@ -3773,7 +3774,7 @@ DGLuint GL_PrepareLSTexture(lightingtex_t which) DGLuint GL_PrepareFlareTexture(flaretex_t flare) { // There are three flare textures. - if(flare < 0 || flare >= NUM_FLARE_TEXTURES) + if(flare >= NUM_FLARE_TEXTURES) return 0; if(!flaretexnames[flare]) diff --git a/doomsday/engine/portable/src/m_args.c b/doomsday/engine/portable/src/m_args.c index 5e2a7c223a..8c00074155 100644 --- a/doomsday/engine/portable/src/m_args.c +++ b/doomsday/engine/portable/src/m_args.c @@ -4,6 +4,7 @@ * Online License Link: http://www.gnu.org/licenses/gpl.html * *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -75,7 +76,7 @@ static int last_match; // CODE -------------------------------------------------------------------- -/* +/** * Parses the given command line. */ int ArgParse(int mode, const char *cmdline) @@ -167,7 +168,7 @@ int ArgParse(int mode, const char *cmdline) i = ftell(file); rewind(file); - if((response = calloc(i + 1, 1)) == NULL) + if((response = M_Calloc(i + 1)) == NULL) Con_Error("ArgParse: failed on alloc of %d bytes.", i + 1); @@ -176,7 +177,7 @@ int ArgParse(int mode, const char *cmdline) count += ArgParse(mode == PM_COUNT ? PM_COUNT : PM_NORMAL_REC, response); - free(response); + M_Free(response); } } else if(!strcmp(word, "--")) // End of arguments. @@ -190,7 +191,7 @@ int ArgParse(int mode, const char *cmdline) if(mode != PM_COUNT) { // Allocate memory for the argument and copy it to the list. - args[arg_pos] = malloc(strlen(word) + 1); + args[arg_pos] = M_Malloc(strlen(word) + 1); strcpy(args[arg_pos++], word); } } @@ -198,7 +199,7 @@ int ArgParse(int mode, const char *cmdline) return count; } -/* +/** * Initializes the command line arguments list. */ void ArgInit(const char *cmdline) @@ -211,35 +212,35 @@ void ArgInit(const char *cmdline) num_args = ArgParse(PM_COUNT, cmdline); // Allocate memory for the list. - args = calloc(num_args, sizeof(char *)); + args = M_Calloc(num_args * sizeof(char *)); // Then create the actual list of arguments. ArgParse(PM_NORMAL, cmdline); } -/* +/** * Frees the memory allocated for the command line. */ void ArgShutdown(void) { int i; - for(i = 0; i < num_args; i++) - free(args[i]); - free(args); + for(i = 0; i < num_args; ++i) + M_Free(args[i]); + M_Free(args); args = NULL; num_args = 0; - for(i = 0; i < num_names; i++) - free(names[i]); + for(i = 0; i < num_names; ++i) + M_Free(names[i]); memset(names, 0, sizeof(names)); num_names = 0; } -/* +/** * Registers a short name for a long arg name. * The short name can then be used on the command line and CheckParm * will know to match occurances of the short name with the long name. -*/ + */ void ArgAbbreviate(char *longname, char *shortname) { argname_t *name; @@ -247,7 +248,7 @@ void ArgAbbreviate(char *longname, char *shortname) if(num_names == MAX_ARG_NAMES) return; - if((name = calloc(1, sizeof(*name))) == NULL) + if((name = M_Calloc(sizeof(*name))) == NULL) Con_Error("ArgAbbreviate: calloc failed on allocation of %d bytes.", sizeof(*name)); @@ -256,7 +257,7 @@ void ArgAbbreviate(char *longname, char *shortname) strncpy(name->short_name, shortname, sizeof(name->short_name) - 1); } -/* +/** * Returns the number of arguments on the command line. */ int Argc(void) @@ -264,7 +265,7 @@ int Argc(void) return num_args; } -/* +/** * Returns a pointer to the i'th argument. */ char *Argv(int i) @@ -274,24 +275,24 @@ char *Argv(int i) return args[i]; } -/* +/** * Returns a pointer to the i'th argument's pointer. */ -char **ArgvPtr(int i) +char **ArgvPtr(int i) { if(i < 0 || i >= num_args) Con_Error("ArgvPtr: There is no arg %i.\n", i); return &args[i]; } -char *ArgNext(void) +char *ArgNext(void) { if(!last_match || last_match >= Argc() - 1) return NULL; return args[++last_match]; } -/* +/** * Returns true if the two parameters are equivalent according to the * abbreviations. */ @@ -303,7 +304,7 @@ int ArgRecognize(char *first, char *second) if(!stricmp(first, second)) return true; - for(k = 0; k < num_names; k++) + for(k = 0; k < num_names; ++k) { if(stricmp(first, names[k]->long_name)) continue; @@ -314,7 +315,7 @@ int ArgRecognize(char *first, char *second) return false; } -/* +/** * Checks for the given parameter in the program's command line arguments. * Returns the argument number (1 to argc-1) or 0 if not present. */ @@ -322,7 +323,7 @@ int ArgCheck(char *check) { int i; - for(i = 1; i < num_args; i++) + for(i = 1; i < num_args; ++i) { // Check the short names for this arg, too. if(ArgRecognize(check, args[i])) @@ -331,7 +332,7 @@ int ArgCheck(char *check) return last_match = 0; } -/* +/** * Checks for the given parameter in the program's command line arguments * and it is followed by N other arguments. * Returns the argument number (1 to argc-1) or 0 if not present. @@ -345,7 +346,7 @@ int ArgCheckWith(char *check, int num) return i; } -/* +/** * Returns true if the given argument begins with a hyphen. */ int ArgIsOption(int i) @@ -355,7 +356,7 @@ int ArgIsOption(int i) return args[i][0] == '-'; } -/* +/** * Returns true if the given parameter exists in the program's command * line arguments, false if not. */ diff --git a/doomsday/engine/portable/src/net_main.c b/doomsday/engine/portable/src/net_main.c index c20ad6de5b..c300b3b303 100644 --- a/doomsday/engine/portable/src/net_main.c +++ b/doomsday/engine/portable/src/net_main.c @@ -909,7 +909,7 @@ uint Net_GetAckThreshold(int clientNumber) return threshold; } -void Net_Ticker(timespan_t time) +void Net_Ticker(void /*timespan_t time*/) { int i; client_t *cl; diff --git a/doomsday/engine/portable/src/p_dmu.c b/doomsday/engine/portable/src/p_dmu.c index 8def8e1d90..ede7401c39 100644 --- a/doomsday/engine/portable/src/p_dmu.c +++ b/doomsday/engine/portable/src/p_dmu.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -1057,8 +1057,6 @@ static int SetProperty(void* ptr, void* context) p = sec->planes[PLN_CEILING]; } } - else - Con_Error("SetProperty: Invalid args.\n"); switch(args->prop) { @@ -1198,7 +1196,6 @@ static int SetProperty(void* ptr, void* context) case DMU_SIDE: { side_t* p = ptr; - sideinfo_t *info = SIDE_INFO(p); switch(args->prop) { @@ -1734,8 +1731,6 @@ static int GetProperty(void* ptr, void* context) else p = sec->planes[PLN_CEILING]; } - else - Con_Error("GetProperty: Invalid args.\n"); switch(args->prop) { @@ -1810,8 +1805,6 @@ static int GetProperty(void* ptr, void* context) p = ptr; else if(args->type == DMU_SUBSECTOR) p = ((subsector_t*)ptr)->sector; - else - Con_Error("GetProperty: Invalid args.\n"); switch(args->prop) { @@ -1885,8 +1878,6 @@ static int GetProperty(void* ptr, void* context) p = SIDE_PTR(line->sidenum[1]); } } - else - Con_Error("GetProperty: Invalid args.\n"); switch(args->prop) { diff --git a/doomsday/engine/portable/src/r_data.c b/doomsday/engine/portable/src/r_data.c index 656d01e784..e624bfb4cb 100644 --- a/doomsday/engine/portable/src/r_data.c +++ b/doomsday/engine/portable/src/r_data.c @@ -379,29 +379,6 @@ int R_SetTextureTranslation(int tex, int translateTo) return old; } -/* - * Textures/flats in the same animation group are precached at the same - * time. 'type' can be either DD_TEXTURE or DD_FLAT. - */ -void R_SetAnimGroup(int type, int number, int group) -{ - /* flat_t *flat; - - switch(type) - { - case DD_TEXTURE: - if(number < 0 || number >= numtextures) break; - textures[number]->group = group; - break; - - case DD_FLAT: - if(number < 0 || number >= numlumps) break; - flat = R_GetFlat(number); - flat->group = group; - break; - } */ -} - /* * Create a new animation group. Returns the group number. * This function is exported and accessible from DLLs. @@ -1045,7 +1022,7 @@ void R_PrecacheTexture(int num) void R_PrecacheLevel(void) { char *texturepresent; - char *spritepresent; + char *spritepresent = NULL; int i, j, k, lump, mocount; thinker_t *th; spriteframe_t *sf; diff --git a/doomsday/engine/portable/src/r_lgrid.c b/doomsday/engine/portable/src/r_lgrid.c index 2ec8b52bac..906824a3c6 100644 --- a/doomsday/engine/portable/src/r_lgrid.c +++ b/doomsday/engine/portable/src/r_lgrid.c @@ -19,7 +19,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -571,7 +571,7 @@ static void LG_ApplySector(gridblock_t *block, const byte *color, int level, /* * Called when a sector has changed its light level. */ -void LG_SectorChanged(sector_t *sector, sectorinfo_t *info) +void LG_SectorChanged(sector_t *sector) { int i, n; @@ -579,16 +579,16 @@ void LG_SectorChanged(sector_t *sector, sectorinfo_t *info) return; // Mark changed blocks and contributors. - for(i = 0; i < info->changedblockcount; ++i) + for(i = 0; i < sector->info->changedblockcount; ++i) { - n = info->blocks[i]; + n = sector->info->blocks[i]; grid[n].flags |= GBF_CHANGED | GBF_CONTRIBUTOR; // The color will be recalculated. memset(grid[n].rgb, 0, 3); } - for(; i < info->blockcount; ++i) + for(; i < sector->info->blockcount; ++i) { - grid[info->blocks[i]].flags |= GBF_CONTRIBUTOR; + grid[sector->info->blocks[i]].flags |= GBF_CONTRIBUTOR; } needsUpdate = true; diff --git a/doomsday/engine/portable/src/r_main.c b/doomsday/engine/portable/src/r_main.c index b5d5e6eef9..a8a87a2c0e 100644 --- a/doomsday/engine/portable/src/r_main.c +++ b/doomsday/engine/portable/src/r_main.c @@ -599,7 +599,7 @@ void R_RenderPlayerView(ddplayer_t *player) { extern boolean firstFrameAfterLoad, freezeRLs; extern int psp3d, modelTriCount; - int i, oldFlags; + int i, oldFlags = 0; if(firstFrameAfterLoad) { diff --git a/doomsday/engine/portable/src/r_model.c b/doomsday/engine/portable/src/r_model.c index 2486c285b8..963d06af9c 100644 --- a/doomsday/engine/portable/src/r_model.c +++ b/doomsday/engine/portable/src/r_model.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -115,7 +115,7 @@ int R_FindModelFor(const char *filename) /* * Allocates a new model. Returns the index. */ -int R_NewModelFor(const char *filename) +int R_NewModelFor(void /*const char *filename*/) { int i; @@ -607,7 +607,7 @@ int R_LoadModel(char *origfn) return 0; } // Allocate a new model_t. - if((index = R_NewModelFor(filename)) < 0) + if((index = R_NewModelFor(/*filename*/)) < 0) { F_Close(file); return 0; // Bugger. diff --git a/doomsday/engine/portable/src/r_shadow.c b/doomsday/engine/portable/src/r_shadow.c index 8b653634ac..c170270919 100644 --- a/doomsday/engine/portable/src/r_shadow.c +++ b/doomsday/engine/portable/src/r_shadow.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -295,12 +295,15 @@ void R_LinkShadow(shadowpoly_t *poly, subsector_t *subsector) boolean RIT_ShadowSubsectorLinker(subsector_t *subsector, void *parm) { shadowpoly_t *poly = parm; +#if 0 vec2_t corners[4], a, b, mid; int i, j; +#endif R_LinkShadow(poly, subsector); - return true; + return true; // DJS - is this meant to be here? +#if 0 // currently unused // Use the extended points, they are wider than inoffsets. V2_Set(corners[0], FIX2FLT(poly->outer[0]->x), FIX2FLT(poly->outer[0]->y)); V2_Set(corners[1], FIX2FLT(poly->outer[1]->x), FIX2FLT(poly->outer[1]->y)); @@ -360,6 +363,7 @@ boolean RIT_ShadowSubsectorLinker(subsector_t *subsector, void *parm) // Continue with the iteration, maybe some other subsectors will // contact it. return true; +#endif } /* diff --git a/doomsday/engine/portable/src/r_things.c b/doomsday/engine/portable/src/r_things.c index a1268b47ff..c1375a3f12 100644 --- a/doomsday/engine/portable/src/r_things.c +++ b/doomsday/engine/portable/src/r_things.c @@ -101,7 +101,6 @@ static int maxFrame; static char *spriteName; static vissprite_t overflowSprite; -static int newVisSprite; static mobj_t *projectedThing; // Used during RIT_VisMobjZ // CODE -------------------------------------------------------------------- diff --git a/doomsday/engine/portable/src/r_world.c b/doomsday/engine/portable/src/r_world.c index f13cd3a79c..e14d460cd1 100644 --- a/doomsday/engine/portable/src/r_world.c +++ b/doomsday/engine/portable/src/r_world.c @@ -547,10 +547,10 @@ static void R_InitSkyFix(void) static boolean doSkyFix(sector_t *front, sector_t *back, int pln) { int f, b; - int height; + int height = 0; boolean adjusted = false; - int *fix; - sector_t *adjustSec; + int *fix = NULL; + sector_t *adjustSec = NULL; // Both the front and back surfaces must be sky on this plane. if(!R_IsSkySurface(&front->planes[pln]->surface) || @@ -816,10 +816,10 @@ static float TriangleArea(fvertex_t * o, fvertex_t * s, fvertex_t * t) /** * Returns true if 'base' is a good tri-fan base. */ -static int R_TestTriFan(subsector_t *sub, int base) +static int R_TestTriFan(subsector_t *sub, int base, int num) { #define TRIFAN_LIMIT 0.1 - int i, a, b, num = sub->numverts; + int i, a, b; fvertex_t *verts = sub->verts; if(num == 3) @@ -846,40 +846,41 @@ static int R_TestTriFan(subsector_t *sub, int base) static void R_SubsectorPlanes(void) { int i; - unsigned int k, num, bufSize = 0; + unsigned int k, num, bufSize = 64; subsector_t *sub; fvertex_t *verts; - fvertex_t *buf; + fvertex_t *vbuf; size_t size = sizeof(fvertex_t); boolean valid; - buf = M_Malloc(size * 64); + vbuf = M_Malloc(size * bufSize); for(i = 0, sub = subsectors; i < numsubsectors; sub++, ++i) { num = sub->numverts; verts = sub->verts; - if(num > bufSize) + if(num >= bufSize - 2) { bufSize = num; - buf = M_Realloc(buf, size * bufSize); + vbuf = M_Realloc(vbuf, size * (bufSize)); } // We need to find a good tri-fan base vertex. // (One that doesn't generate zero-area triangles). // We'll test each one and pick the first good one. + valid = false; for(k = 0; k < num; ++k) { - if(R_TestTriFan(sub, k)) + if(R_TestTriFan(sub, k, num)) { // Yes! This'll do nicely. Change the order of the // vertices so that k comes first. if(k) // Need to change? { - memcpy(buf, verts, size * num); - memcpy(verts, &buf[k], size * (num - k)); - memcpy(&verts[num - k], buf, size * k); + memcpy(vbuf, verts, size * num); + memcpy(verts, &vbuf[k], size * (num - k)); + memcpy(&verts[num - k], vbuf, size * k); } valid = true; break; @@ -895,7 +896,7 @@ static void R_SubsectorPlanes(void) } } - M_Free(buf); + M_Free(vbuf); } static void R_SetVertexOwner(vertex_t *vtx, sector_t *secptr) @@ -2613,7 +2614,7 @@ void R_UpdateSector(sector_t* sec, boolean forceUpdate) sin->oldlightlevel = sec->lightlevel; memcpy(sin->oldrgb, sec->rgb, 3); - LG_SectorChanged(sec, sin); + LG_SectorChanged(sec); } else { diff --git a/doomsday/engine/portable/src/rend_bias.c b/doomsday/engine/portable/src/rend_bias.c index 5e8787335e..c0bfa30ecd 100644 --- a/doomsday/engine/portable/src/rend_bias.c +++ b/doomsday/engine/portable/src/rend_bias.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -634,7 +634,7 @@ int SB_TrackerCheck(biastracker_t *tracker, int index) */ void SB_TrackerApply(biastracker_t *dest, const biastracker_t *src) { - int i; + unsigned int i; for(i = 0; i < sizeof(dest->changes)/sizeof(dest->changes[0]); ++i) { @@ -647,7 +647,7 @@ void SB_TrackerApply(biastracker_t *dest, const biastracker_t *src) */ void SB_TrackerClear(biastracker_t *dest, const biastracker_t *src) { - int i; + unsigned int i; for(i = 0; i < sizeof(dest->changes)/sizeof(dest->changes[0]); ++i) { diff --git a/doomsday/engine/portable/src/rend_console.c b/doomsday/engine/portable/src/rend_console.c index 337e5da644..25ba1d883d 100644 --- a/doomsday/engine/portable/src/rend_console.c +++ b/doomsday/engine/portable/src/rend_console.c @@ -34,6 +34,8 @@ #include "de_refresh.h" #include "de_ui.h" +#include "math.h" + #ifdef TextOut // Windows has its own TextOut. # undef TextOut @@ -195,6 +197,7 @@ void Con_DrawRuler(int y, int lineHeight, float alpha) * Draw a 'side' text in the console. This is intended for extra * information about the current game mode. */ +#if 0 // currently unused static void drawSideText(const char *text, int line, float alpha) { char buf[300]; @@ -229,6 +232,7 @@ static void drawSideText(const char *text, int line, float alpha) Cfont.TextOut(buf, ssw - Cfont.Width(buf) - 3, y / Cfont.sizeY); } } +#endif void Rend_ConsoleToggleFullscreen(void) { @@ -251,8 +255,6 @@ void Rend_ConsoleOpen(int yes) void Rend_ConsoleMove(int numLines) { - int l = 0; - if(numLines == 0) return; diff --git a/doomsday/engine/portable/src/rend_dyn.c b/doomsday/engine/portable/src/rend_dyn.c index 9e19031f15..ba234bc18f 100644 --- a/doomsday/engine/portable/src/rend_dyn.c +++ b/doomsday/engine/portable/src/rend_dyn.c @@ -1374,6 +1374,7 @@ static void DL_LinkLuminous(void) /** * Returns true if the texture is already used in the list of dynlights. */ +#if 0 // currently unused static boolean DL_IsTexUsed(dynlight_t *node, DGLuint texture) { for(; node; node = node->next) @@ -1381,6 +1382,7 @@ static boolean DL_IsTexUsed(dynlight_t *node, DGLuint texture) return true; return false; } +#endif /** * Process the given lumobj to maybe add a dynamic light for the plane. @@ -1659,7 +1661,6 @@ boolean DL_RadiusIterator(subsector_t *subsector, fixed_t x, fixed_t y, */ void DL_ClipInSubsector(int ssecidx) { - subsector_t *ssec = SUBSECTOR_PTR(ssecidx); lumobj_t *lumi; // Lum Iterator, or 'snow' in Finnish. :-) // Determine which dynamic light sources in the subsector get clipped. diff --git a/doomsday/engine/portable/src/rend_fakeradio.c b/doomsday/engine/portable/src/rend_fakeradio.c index c55aadaa79..312a3fab99 100644 --- a/doomsday/engine/portable/src/rend_fakeradio.c +++ b/doomsday/engine/portable/src/rend_fakeradio.c @@ -381,7 +381,6 @@ void Rend_RadioTexCoordY(rendpoly_t *q, float size) int R_GetAlignedNeighbor(line_t **neighbor, const line_t *line, int side, boolean leftNeighbor) { - lineinfo_t *info = LINE_INFO(line); sideinfo_t *sinfo; int i; diff --git a/doomsday/engine/portable/src/rend_list.c b/doomsday/engine/portable/src/rend_list.c index 575130c2da..f46edb95d4 100644 --- a/doomsday/engine/portable/src/rend_list.c +++ b/doomsday/engine/portable/src/rend_list.c @@ -332,7 +332,7 @@ void RL_VertexColors(rendpoly_t *poly, int lightlevel, const byte *rgb) rendpoly_vertex_t *vtx; boolean usewhite; - if(poly->isWall) // A quad? + if(poly->isWall && rend_light_wall_angle && !useBias) // A quad? { // Do a lighting adjustment based on orientation. lightlevel += @@ -398,10 +398,11 @@ void RL_VertexColors(rendpoly_t *poly, int lightlevel, const byte *rgb) void RL_PreparePlane(subplaneinfo_t *plane, rendpoly_t *poly, float height, subsector_t *subsector) { - int i, num, vid, sectorlight; + int i, num, vid, sectorlight; const byte *pLightColor; - byte vColor[] = { 0, 0, 0, 0}; + byte vColor[] = { 0, 0, 0, 0}; subsectorinfo_t *ssecinfo = SUBSECT_INFO(subsector); + surface_t *surface = &poly->sector->planes[plane->type]->surface; poly->numvertices = ssecinfo->numvertices; @@ -428,14 +429,14 @@ void RL_PreparePlane(subplaneinfo_t *plane, rendpoly_t *poly, float height, pLightColor = R_GetSectorLightColor(poly->sector); // Calculate the color for each vertex, blended with plane color? - if(poly->sector->planes[plane->type]->surface.rgba[0] < 255 || - poly->sector->planes[plane->type]->surface.rgba[1] < 255 || - poly->sector->planes[plane->type]->surface.rgba[2] < 255 ) + if(surface->rgba[0] < 255 || + surface->rgba[1] < 255 || + surface->rgba[2] < 255 ) { // Blend sector light+color+planecolor for(i = 0; i < 3; ++i) { - vColor[i] = (byte) (((poly->sector->planes[plane->type]->surface.rgba[i]/ 255.0f)) * pLightColor[i]); + vColor[i] = (byte) (((surface->rgba[i]/ 255.0f)) * pLightColor[i]); } RL_VertexColors(poly, sectorlight, vColor); @@ -908,8 +909,7 @@ static float RL_ShinyVertical(float dy, float dx) return ( (atan(dy/dx) / (PI/2)) + 1 ) / 2; } -void RL_QuadShinyTexCoords(gl_texcoord_t *tc, rendpoly_t *poly, - gltexture_t *tex) +void RL_QuadShinyTexCoords(gl_texcoord_t *tc, rendpoly_t *poly) { vec2_t surface, normal, projected, s, reflected; vec2_t view; @@ -1130,7 +1130,7 @@ void RL_WriteQuad(rendlist_t *list, rendpoly_t *poly) if(poly->flags & RPF_SHINY) { // Shiny environmental texture coordinates. - RL_QuadShinyTexCoords(&texCoords[TCA_MAIN][base], poly, &poly->tex); + RL_QuadShinyTexCoords(&texCoords[TCA_MAIN][base], poly); // Mask texture coordinates. if(list->intertex.id) @@ -1221,7 +1221,7 @@ void RL_WriteDivQuad(rendlist_t * list, rendpoly_t *poly) if(poly->flags & RPF_SHINY) { // Shiny environmental texture coordinates. - RL_QuadShinyTexCoords(&texCoords[TCA_MAIN][base], poly, &poly->tex); + RL_QuadShinyTexCoords(&texCoords[TCA_MAIN][base], poly); if(list->intertex.id) { RL_QuadTexCoords(&texCoords[TCA_BLEND][base], poly, &poly->tex); diff --git a/doomsday/engine/portable/src/rend_main.c b/doomsday/engine/portable/src/rend_main.c index 7a65b6eb41..e36eb3eb35 100644 --- a/doomsday/engine/portable/src/rend_main.c +++ b/doomsday/engine/portable/src/rend_main.c @@ -358,65 +358,56 @@ static void Rend_ShinySurfaceColor(gl_rgba_t *color, ded_reflection_t *ref) color->rgba[3] = (DGLubyte) (ref->shininess * 255); } -/* - * Pre: As we modify param poly quite a bit it is the responsibility of - * the caller to ensure this is OK (ie if not it should pass us a - * copy instead (eg wall segs)). - * - * @param texture The texture/flat id of the texture on the poly. - * @param isFlat (TRUE) = param texture is a flat. - * @param poly The poly to add the shiny poly for. - */ -void Rend_AddShinyPoly(int texture, boolean isFlat, rendpoly_t *poly) +static ded_reflection_t *Rend_ShinyDefForSurface(surface_t *suf, short *width, + short *height) { - int i; ded_reflection_t *ref = NULL; - short width = 0; - short height = 0; - - if(!useShinySurfaces) - { - // Shiny surfaces are not enabled. - return; - } // Figure out what kind of surface properties have been defined // for the texture or flat in question. - if(isFlat) + if(suf->isflat) { - flat_t *flat = R_GetFlat(texture); + flat_t *flat = R_GetFlat(suf->texture); - if(flat->translation.current != texture) + if(flat->translation.current != suf->texture) { // The flat is currently translated to another one. flat = R_GetFlat(flat->translation.current); } ref = flat->reflection; - width = 64; - height = 64; + if(width) + *width = 64; + if(height) + *height = 64; } else { - texture_t *texptr = textures[texturetranslation[texture].current]; + texture_t *texptr = textures[texturetranslation[suf->texture].current]; ref = texptr->reflection; - width = texptr->width; - height = texptr->height; + if(width) + *width = texptr->width; + if(height) + *height = texptr->height; } - if(ref == NULL) - { - // The surface doesn't shine. - return; - } + return ref; +} - // Make sure the texture has been loaded. - if(!GL_LoadReflectionMap(ref)) - { - // Can't shine because there is no shiny map. - return; - } +/* + * Pre: As we modify param poly quite a bit it is the responsibility of + * the caller to ensure this is OK (ie if not it should pass us a + * copy instead (eg wall segs)). + * + * @param texture The texture/flat id of the texture on the poly. + * @param isFlat (TRUE) = param texture is a flat. + * @param poly The poly to add the shiny poly for. + */ +static void Rend_AddShinyPoly(rendpoly_t *poly, ded_reflection_t *ref, + short width, short height) +{ + int i; // Make it a shiny polygon. poly->lights = NULL; @@ -792,6 +783,10 @@ int Rend_MidTexturePos(float *bottomleft, float *bottomright, return (visible[0] || visible[1]); } +#define RPF2_SHADOW 0x0001 +#define RPF2_SHINY 0x0002 +#define RPF2_GLOW 0x0004 + /* * Called by Rend_RenderWallSeg to render ALL wall sections. * @@ -799,8 +794,7 @@ int Rend_MidTexturePos(float *bottomleft, float *bottomright, */ static void Rend_RenderWallSection(rendpoly_t *quad, const seg_t *seg, side_t *side, sector_t *frontsec, surface_t *surface, - int mode, byte alpha, - boolean shadow, boolean shiny, boolean glow) + int mode, byte alpha, short flags) { int i; int segIndex = GET_SEG_IDX(seg); @@ -862,7 +856,7 @@ static void Rend_RenderWallSection(rendpoly_t *quad, const seg_t *seg, side_t *s Con_Error("Rend_RenderWallSection: Invalid wall section mode %i", mode); } - if(glow && glowingTextures) // Make it fullbright? + if((flags & RPF2_GLOW) && glowingTextures) // Make it fullbright? quad->flags |= RPF_GLOW; // Check for neighborhood division? @@ -896,20 +890,29 @@ static void Rend_RenderWallSection(rendpoly_t *quad, const seg_t *seg, side_t *s // Add the poly to the appropriate list RL_AddPoly(quad); - if(shadow) // Render Fakeradio polys for this seg? + if(flags & RPF2_SHADOW) // Render Fakeradio polys for this seg? Rend_RadioWallSection(seg, quad); - if(shiny) // Render Shiny polys for this seg? + if((flags & RPF2_SHINY) && useShinySurfaces) // Render Shiny polys for this seg? { - rendpoly_t *q = R_AllocRendPoly(RP_QUAD, true, 4); + ded_reflection_t *ref; + short width = 0; + short height = 0; - // We're going to modify the polygon quite a bit. - memcpy(q, quad, sizeof(rendpoly_t)); - memcpy(q->vertices, quad->vertices, sizeof(rendpoly_vertex_t) * q->numvertices); + if((ref = Rend_ShinyDefForSurface(surface, &width, &height)) != NULL) + if(GL_LoadReflectionMap(ref)) // Make sure the texture has been loaded. + { + // We're going to modify the polygon quite a bit... + rendpoly_t *q = R_AllocRendPoly(RP_QUAD, true, 4); + + memcpy(q, quad, sizeof(rendpoly_t)); + memcpy(q->vertices, quad->vertices, + sizeof(rendpoly_vertex_t) * q->numvertices); - Rend_AddShinyPoly(surface->texture, surface->isflat, q); + Rend_AddShinyPoly(q, ref, width, height); - R_FreeRendPoly(q); + R_FreeRendPoly(q); + } } } @@ -918,15 +921,14 @@ static void Rend_RenderWallSection(rendpoly_t *quad, const seg_t *seg, side_t *s * two into a Rend_RenderSurface. */ static void Rend_DoRenderPlane(rendpoly_t *poly, subsector_t *subsector, - subplaneinfo_t* plane, surface_t *surface, float height, byte alpha, - boolean shadow, boolean shiny, - boolean glow) + subplaneinfo_t* plane, surface_t *surface, + float height, byte alpha, short flags) { int i; int subIndex = GET_SUBSECTOR_IDX(subsector); rendpoly_vertex_t *vtx; - if(glow && glowingTextures) // Make it fullbright? + if((flags & RPF2_GLOW) && glowingTextures) // Make it fullbright? poly->flags |= RPF_GLOW; // Surface color/light. @@ -954,38 +956,41 @@ static void Rend_DoRenderPlane(rendpoly_t *poly, subsector_t *subsector, // Add the poly to the appropriate list RL_AddPoly(poly); - //if(shadow) // Fakeradio uses a seperate algorithm for planes. + //if(flags & RPF2_SHADOW) // Fakeradio uses a seperate algorithm for planes. - // Add a shine to this flat existence. - if(shiny) + if((flags & RPF2_SHINY) && useShinySurfaces) // Render Shiny polys for this seg? { - Rend_AddShinyPoly(surface->texture, surface->isflat, poly); + ded_reflection_t *ref; + short width = 0; + short height = 0; + + if((ref = Rend_ShinyDefForSurface(surface, &width, &height)) != NULL) + if(GL_LoadReflectionMap(ref)) // Make sure the texture has been loaded. + { + Rend_AddShinyPoly(poly, ref, width, height); + } } } -/* +/** * The sector height should've been checked by now. * This seriously needs to be rewritten! Witness the accumulation of hacks * on kludges... */ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) { - int i; - int surfaceFlags; - int solidSeg = false; // -1 means NEVER. - sector_t *backsec; - surface_t *surface; - side_t *sid, *backsid, *side; - line_t *ldef; - float ffloor, fceil, bfloor, bceil, fsh, bsh; + int i; + int surfaceFlags; + int solidSeg = false; // -1 means NEVER. + sector_t *backsec; + surface_t *surface; + side_t *sid, *backsid, *side; + line_t *ldef; + float ffloor, fceil, bfloor, bceil, fsh, bsh; rendpoly_t *quad; - float *vBL, *vBR, *vTL, *vTR; - boolean backSide = true; - boolean backsecSkyFix = false; - - // Let's first check which way this seg is facing. - if(!Rend_FixedSegFacingDir(seg)) - return; + float *vBL, *vBR, *vTL, *vTR; + boolean backSide = true; + boolean backsecSkyFix = false; backsec = seg->backsector; sid = SIDE_PTR(seg->linedef->sidenum[0]); @@ -1171,6 +1176,8 @@ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) // Is there a visible surface? if(surfaceFlags != -1) { + short tempflags = 0; + // Fill in the remaining quad data. quad->flags = 0; vTL[VZ] = vTR[VZ] = fceil; @@ -1181,11 +1188,15 @@ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) if(ldef->flags & ML_DONTPEGBOTTOM) quad->texoffy += texh - fsh; + if(!(flags & RWSF_NO_RADIO)) + tempflags |= RPF2_SHADOW; + if(surface->texture != -1) + tempflags |= RPF2_SHINY; + if(surfaceFlags & SUF_GLOW) + tempflags |= RPF2_GLOW; + Rend_RenderWallSection(quad, seg, side, frontsec, surface, SEG_MIDDLE, - /*Alpha*/ 255, - /*Shadow?*/ !(flags & RWSF_NO_RADIO), - /*Shiny?*/ (surface->texture != -1), - /*Glow?*/ (surfaceFlags & SUF_GLOW)); + /*Alpha*/ 255, tempflags); } else { @@ -1307,11 +1318,19 @@ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) else quad->flags = 0; - Rend_RenderWallSection(quad, seg, side, frontsec, surface, SEG_MIDDLE, - /*Alpha*/ alpha, - /*Shadow?*/ (solidSeg && !(flags & RWSF_NO_RADIO) && !texmask), - /*Shiny?*/ (solidSeg && surface->texture != -1 && !texmask), - /*Glow?*/ (surfaceFlags & SUF_GLOW)); + { + short tempflags = 0; + + if(solidSeg && !(flags & RWSF_NO_RADIO) && !texmask) + tempflags |= RPF2_SHADOW; + if(solidSeg && surface->texture != -1 && !texmask) + tempflags |= RPF2_SHINY; + if(surfaceFlags & SUF_GLOW) + tempflags |= RPF2_GLOW; + + Rend_RenderWallSection(quad, seg, side, frontsec, surface, SEG_MIDDLE, + /*Alpha*/ alpha, tempflags); + } } } } @@ -1390,11 +1409,19 @@ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) } if(isVisible) - Rend_RenderWallSection(quad, seg, side, frontsec, surface, SEG_TOP, - /*Alpha*/ alpha, - /*Shadow?*/ !(flags & RWSF_NO_RADIO), - /*Shiny?*/ (surface->texture != -1), - /*Glow?*/ (surfaceFlags & SUF_GLOW)); + { + short tempflags = 0; + + if(!(flags & RWSF_NO_RADIO)) + tempflags |= RPF2_SHADOW; + if(surface->texture != -1) + tempflags |= RPF2_SHINY; + if(surfaceFlags & SUF_GLOW) + tempflags |= RPF2_GLOW; + + Rend_RenderWallSection(quad, seg, side, frontsec, surface, SEG_TOP, + /*Alpha*/ alpha, tempflags); + } } } @@ -1410,6 +1437,7 @@ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) // Is there a visible surface? if(surfaceFlags != -1) { + short tempflags = 0; // Calculate texture coordinates. quad->texoffx = side->bottom.offx + FIX2FLT(seg->offset); quad->texoffy = side->bottom.offy; @@ -1426,11 +1454,15 @@ void Rend_RenderWallSeg(const seg_t *seg, sector_t *frontsec, int flags) vTL[VZ] = vTR[VZ] = fceil; } + if(!(flags & RWSF_NO_RADIO)) + tempflags |= RPF2_SHADOW; + if(surface->texture != -1) + tempflags |= RPF2_SHINY; + if(surfaceFlags & SUF_GLOW) + tempflags |= RPF2_GLOW; + Rend_RenderWallSection(quad, seg, side, frontsec, surface, SEG_BOTTOM, - /*Alpha*/ 255, - /*Shadow?*/ !(flags & RWSF_NO_RADIO), - /*Shiny?*/ (surface->texture != -1), - /*Glow?*/ (surfaceFlags & SUF_GLOW)); + /*Alpha*/ 255, tempflags); } } } @@ -1490,6 +1522,31 @@ int Rend_SectorLight(sector_t *sec) return i; } +static void Rend_MarkSegsFacingFront(subsector_t *sub) +{ + int i; + float v1[2], v2[2]; + seg_t *seg; + + for(i = sub->linecount, seg = &segs[sub->firstline]; i > 0; --i, seg++) + { + // Occlusions can only happen where two sectors contact. + if(!seg->linedef) + continue; + + v1[VX] = FIX2FLT(seg->v1->x); + v1[VY] = FIX2FLT(seg->v1->y); + v2[VX] = FIX2FLT(seg->v2->x); + v2[VY] = FIX2FLT(seg->v2->y); + + // Which way should it be facing? + if(Rend_SegFacingDir(v1, v2)) // 1=front + seg->info->flags |= SEGINF_FACINGFRONT; + else + seg->info->flags &= ~SEGINF_FACINGFRONT; + } +} + /* * Creates new occlusion planes from the subsector's sides. * Before testing, occlude subsector's backfaces. After testing occlude @@ -1499,35 +1556,32 @@ int Rend_SectorLight(sector_t *sec) void Rend_OccludeSubsector(subsector_t *sub, boolean forward_facing) { sector_t *front = sub->sector, *back; - int segfacing; int i; float v1[2], v2[2], fronth[2], backh[2]; float *startv, *endv; seg_t *seg; - fronth[0] = FIX2FLT(front->planes[PLN_FLOOR]->height); - fronth[1] = FIX2FLT(front->planes[PLN_CEILING]->height); - if(devNoCulling || P_IsInVoid(viewplayer)) return; + fronth[0] = FIX2FLT(front->planes[PLN_FLOOR]->height); + fronth[1] = FIX2FLT(front->planes[PLN_CEILING]->height); + for(i = sub->linecount, seg = &segs[sub->firstline]; i > 0; --i, seg++) { // Occlusions can only happen where two sectors contact. if(!seg->linedef || !seg->backsector) continue; - back = seg->backsector; + if(forward_facing != (seg->info->flags & SEGINF_FACINGFRONT)) + continue; + v1[VX] = FIX2FLT(seg->v1->x); v1[VY] = FIX2FLT(seg->v1->y); v2[VX] = FIX2FLT(seg->v2->x); v2[VY] = FIX2FLT(seg->v2->y); - // Which way should it be facing? - segfacing = Rend_SegFacingDir(v1, v2); // 1=front - if(forward_facing != (segfacing != 0)) - continue; - + back = seg->backsector; backh[0] = FIX2FLT(back->planes[PLN_FLOOR]->height); backh[1] = FIX2FLT(back->planes[PLN_CEILING]->height); // Choose start and end vertices so that it's facing forward. @@ -1616,13 +1670,15 @@ void Rend_RenderPlane(subplaneinfo_t *plane, subsector_t *subsector) (plane->type == PLN_CEILING && vy < height)) { rendpoly_t *poly = - R_AllocRendPoly(RP_FLAT, false, subsector->numverts); + R_AllocRendPoly(RP_FLAT, false, subsector->info->numvertices); surfaceFlags = Rend_PrepareTextureForPoly(poly, surface); // Is there a visible surface? if(surfaceFlags != -1) { + short tempflags = 0; + // Fill in the remaining quad data. poly->flags = flags; poly->sector = polySector; @@ -1634,11 +1690,13 @@ void Rend_RenderPlane(subplaneinfo_t *plane, subsector_t *subsector) poly->texoffy = sector->planes[plane->type]->surface.offy; } + if(surface->texture != -1) + tempflags |= RPF2_SHINY; + if(surfaceFlags & SUF_GLOW) + tempflags |= RPF2_GLOW; + Rend_DoRenderPlane(poly, subsector, plane, surface, height, - /*Alpha*/ 255, - /*Shadow?*/ false, // unused - /*Shiny?*/ (surface->texture != -1), - /*Glow?*/ (surfaceFlags & SUF_GLOW)); + /*Alpha*/ 255, tempflags); } R_FreeRendPoly(poly); @@ -1687,6 +1745,8 @@ void Rend_RenderSubsector(int ssecidx) Rend_RadioInitForSector(sect); Rend_RadioSubsectorEdges(ssec); + Rend_MarkSegsFacingFront(ssec); + Rend_OccludeSubsector(ssec, false); DL_ClipInSubsector(ssecidx); Rend_OccludeSubsector(ssec, true); @@ -1712,14 +1772,19 @@ void Rend_RenderSubsector(int ssecidx) if(seg->linedef == NULL) // "minisegs" have no linedefs. continue; - Rend_RenderWallSeg(seg, sect, flags); + // Let's first check which way this seg is facing. + if(seg->info->flags & SEGINF_FACINGFRONT) + Rend_RenderWallSeg(seg, sect, flags); } // Is there a polyobj on board? if(ssec->poly) { for(i = 0; i < ssec->poly->numsegs; ++i) - Rend_RenderWallSeg(ssec->poly->segs[i], sect, RWSF_NO_RADIO); + { + if(Rend_FixedSegFacingDir(seg)) + Rend_RenderWallSeg(ssec->poly->segs[i], sect, RWSF_NO_RADIO); + } } // Render all planes of this sector. diff --git a/doomsday/engine/portable/src/rend_model.c b/doomsday/engine/portable/src/rend_model.c index c604b2f1b6..d9b667a1be 100644 --- a/doomsday/engine/portable/src/rend_model.c +++ b/doomsday/engine/portable/src/rend_model.c @@ -136,7 +136,7 @@ void Rend_ModelRegister(void) C_VAR_FLOAT("rend-model-shiny-strength", &modelShinyFactor, 0, 0, 10); } -static float __inline qatan2(float y, float x) +static __inline float qatan2(float y, float x) { float ang = BANG2RAD(bamsAtan2(y * 512, x * 512)); @@ -239,7 +239,7 @@ model_frame_t *Mod_GetVisibleFrame(modeldef_t * mf, int subnumber, int mobjid) /** * Render a set of GL commands using the given data. */ -void Mod_RenderCommands(rendcmd_t mode, void *glCommands, uint numVertices, +void Mod_RenderCommands(rendcmd_t mode, void *glCommands, /*uint numVertices,*/ gl_vertex_t * vertices, gl_color_t * colors, gl_texcoord_t * texCoords) { @@ -912,7 +912,7 @@ void Mod_RenderSubModel(vissprite_t * spr, int number) RL_Bind(skinTexture); Mod_RenderCommands(RC_COMMAND_COORDS, - mdl->lods[activeLod].glCommands, numVerts, + mdl->lods[activeLod].glCommands, /*numVerts,*/ modelVertices, modelColors, NULL); } @@ -939,7 +939,7 @@ void Mod_RenderSubModel(vissprite_t * spr, int number) RL_BindTo(0, skinTexture); Mod_RenderCommands(RC_BOTH_COORDS, - mdl->lods[activeLod].glCommands, numVerts, + mdl->lods[activeLod].glCommands, /*numVerts,*/ modelVertices, modelColors, modelTexCoords); RL_SelectTexUnits(1); @@ -951,7 +951,7 @@ void Mod_RenderSubModel(vissprite_t * spr, int number) RL_SelectTexUnits(1); RL_Bind(shinyTexture); Mod_RenderCommands(RC_OTHER_COORDS, - mdl->lods[activeLod].glCommands, numVerts, + mdl->lods[activeLod].glCommands, /*numVerts,*/ modelVertices, modelColors, modelTexCoords); } } @@ -972,7 +972,7 @@ void Mod_RenderSubModel(vissprite_t * spr, int number) RL_BindTo(0, skinTexture); Mod_RenderCommands(RC_BOTH_COORDS, mdl->lods[activeLod].glCommands, - numVerts, modelVertices, modelColors, + /*numVerts,*/ modelVertices, modelColors, modelTexCoords); RL_SelectTexUnits(1); diff --git a/doomsday/engine/portable/src/s_mus.c b/doomsday/engine/portable/src/s_mus.c index c7411fd411..c98fd9f52d 100644 --- a/doomsday/engine/portable/src/s_mus.c +++ b/doomsday/engine/portable/src/s_mus.c @@ -112,7 +112,7 @@ void Mus_Register(void) */ boolean Mus_Init(void) { - int i; + unsigned int i; if(isDedicated || mus_avail || ArgExists("-nomusic")) return true; @@ -128,8 +128,8 @@ boolean Mus_Init(void) { Con_Message("Mus_Init: Failed to initialize Win driver.\n"); } - // Must rely on Windows without an Ext interface. - icd = &musd_win_icd; + // Must rely on Windows without an Ext interface. + icd = &musd_win_icd; #endif #ifdef UNIX // The available interfaces have already been loaded. @@ -142,7 +142,7 @@ boolean Mus_Init(void) #endif // Initialize the chosen interfaces. - for(i = 0; i < NUM_INTERFACES; i++) + for(i = 0; i < NUM_INTERFACES; ++i) if(*interfaces[i].ip && !(*interfaces[i].ip)->Init()) { Con_Message("Mus_Init: Failed to initialize %s interface.\n", @@ -157,7 +157,7 @@ boolean Mus_Init(void) char buf[40]; Con_Printf("Mus_Init: Interfaces:"); - for(i = 0; i < NUM_INTERFACES; i++) + for(i = 0; i < NUM_INTERFACES; ++i) if(*interfaces[i].ip) { if(!(*interfaces[i].ip)->Get(MUSIP_ID, buf)) @@ -198,13 +198,13 @@ void Mus_Shutdown(void) */ void Mus_StartFrame(void) { - int i; + unsigned int i; if(!mus_avail) return; // Update all interfaces. - for(i = 0; i < NUM_INTERFACES; i++) + for(i = 0; i < NUM_INTERFACES; ++i) if(*interfaces[i].ip) (*interfaces[i].ip)->Update(); } @@ -215,13 +215,13 @@ void Mus_StartFrame(void) */ void Mus_SetVolume(float vol) { - int i; + unsigned int i; if(!mus_avail) return; // Set volume of all available interfaces. - for(i = 0; i < NUM_INTERFACES; i++) + for(i = 0; i < NUM_INTERFACES; ++i) if(*interfaces[i].ip) (*interfaces[i].ip)->Set(MUSIP_VOLUME, vol); } @@ -231,20 +231,20 @@ void Mus_SetVolume(float vol) */ void Mus_Pause(boolean do_pause) { - int i; + unsigned int i; if(!mus_avail) return; // Pause all interfaces. - for(i = 0; i < NUM_INTERFACES; i++) + for(i = 0; i < NUM_INTERFACES; ++i) if(*interfaces[i].ip) (*interfaces[i].ip)->Pause(do_pause); } void Mus_Stop(void) { - int i; + unsigned int i; if(!mus_avail) return; @@ -252,7 +252,7 @@ void Mus_Stop(void) current_song = -1; // Stop all interfaces. - for(i = 0; i < NUM_INTERFACES; i++) + for(i = 0; i < NUM_INTERFACES; ++i) if(*interfaces[i].ip) (*interfaces[i].ip)->Stop(); } @@ -426,9 +426,9 @@ int Mus_Start(ded_music_t * def, boolean looped) } // Try to start the song. - for(i = 0; i < 3; i++) + for(i = 0; i < 3; ++i) { - switch (order[i]) + switch(order[i]) { case MUSP_CD: if(Mus_GetCD(def)) diff --git a/doomsday/engine/portable/src/sv_frame.c b/doomsday/engine/portable/src/sv_frame.c index 4e02d65fea..558486a667 100644 --- a/doomsday/engine/portable/src/sv_frame.c +++ b/doomsday/engine/portable/src/sv_frame.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -742,7 +742,7 @@ void Sv_WriteDelta(const delta_t * delta) lengthOffset = Msg_Offset(); Msg_WriteLong(0); #endif - + // Null mobj deltas are special. if(type == DT_MOBJ) { @@ -774,7 +774,7 @@ void Sv_WriteDelta(const delta_t * delta) // First the type of the delta. Sv_WriteDeltaHeader(type, delta); - + switch (delta->type) { case DT_MOBJ: @@ -811,7 +811,7 @@ void Sv_WriteDelta(const delta_t * delta) default: Con_Error("Sv_WriteDelta: Unknown delta type %i.\n", delta->type); } - + #ifdef _DEBUG writeDeltaLength: // Update the length of the delta. @@ -863,7 +863,9 @@ void Sv_SendFrame(int playerNumber) byte oldResend; delta_t *delta; int deltaCount = 0; +#if _DEBUG int endOffset = 0; +#endif int deltaCountOffset = 0; // Does the send queue allow us to send this packet? @@ -903,7 +905,7 @@ void Sv_SendFrame(int playerNumber) #ifdef _DEBUG Msg_WriteLong(0); #endif - + /*#ifdef _DEBUG Con_Printf("set%i\n", pool->setDealer); #endif */ @@ -941,7 +943,7 @@ void Sv_SendFrame(int playerNumber) pool->resendDealer = oldResend; break; } - + // Successfully written, increment counter. deltaCount++; @@ -972,7 +974,7 @@ void Sv_SendFrame(int playerNumber) Msg_WriteLong(deltaCount); Msg_SetOffset(endOffset); #endif - + // The PSV_FIRST_FRAME2 packet is sent Ordered, which means it'll // always arrive in the correct order when compared to the other // game setup packets. diff --git a/doomsday/engine/portable/src/sv_main.c b/doomsday/engine/portable/src/sv_main.c index 2277ca77a9..c92dd0d404 100644 --- a/doomsday/engine/portable/src/sv_main.c +++ b/doomsday/engine/portable/src/sv_main.c @@ -136,7 +136,7 @@ void Sv_GetInfo(serverinfo_t *info) */ int Sv_InfoToString(serverinfo_t *info, ddstring_t * msg) { - int i; + unsigned int i; Str_Appendf(msg, "port:%i\n", info->port); Str_Appendf(msg, "name:%s\n", info->name); @@ -153,7 +153,7 @@ int Sv_InfoToString(serverinfo_t *info, ddstring_t * msg) Str_Appendf(msg, "maxp:%i\n", info->maxPlayers); Str_Appendf(msg, "open:%i\n", info->canJoin); Str_Appendf(msg, "plrn:%s\n", info->clientNames); - for(i = 0; i < sizeof(info->data) / sizeof(info->data[0]); i++) + for(i = 0; i < sizeof(info->data) / sizeof(info->data[0]); ++i) { Str_Appendf(msg, "data%i:%x\n", i, info->data[i]); } @@ -539,6 +539,7 @@ void Sv_ExecuteCommand(void) default: Con_Error("Sv_ExecuteCommand: Not a command packet!\n"); + return; // shutup compiler } // Verify using string length. @@ -1123,7 +1124,7 @@ boolean Sv_CheckBandwidth(int playerNumber) void Sv_PlaceThing(mobj_t* mo, fixed_t x, fixed_t y, fixed_t z, boolean onFloor) { P_CheckPosXYZ(mo, x, y, z); - + P_UnlinkThing(mo); mo->pos[VX] = x; mo->pos[VY] = y; @@ -1149,19 +1150,19 @@ void Sv_ClientCoords(int playerNum) mobj_t *mo = players[playerNum].mo; int clx, cly, clz; boolean onFloor = false; -#ifdef _DEBUG +#ifdef _DEBUG fixed_t oldz; #endif - + // If mobj or player is invalid, the message is discarded. if(!mo || !players[playerNum].ingame || players[playerNum].flags & DDPF_DEAD) return; -#ifdef _DEBUG +#ifdef _DEBUG oldz = mo->pos[VZ]; #endif - + clx = Msg_ReadShort() << 16; cly = Msg_ReadShort() << 16; clz = Msg_ReadShort() << 16; @@ -1179,12 +1180,12 @@ void Sv_ClientCoords(int playerNum) { // Large differences in the coordinates suggest that player position // has been misestimated on serverside. - + // Prevent illegal stepups. - if(tmpFloorZ - mo->pos[VZ] <= 24*FRACUNIT || + if(tmpFloorZ - mo->pos[VZ] <= 24*FRACUNIT || // But also allow warping the position. (abs(clx - mo->pos[VX]) > WARP_LIMIT * FRACUNIT || - abs(cly - mo->pos[VY]) > WARP_LIMIT * FRACUNIT || + abs(cly - mo->pos[VY]) > WARP_LIMIT * FRACUNIT || abs(clz - mo->pos[VZ]) > WARP_LIMIT * FRACUNIT)) { Sv_PlaceThing(mo, clx, cly, clz, onFloor); diff --git a/doomsday/engine/portable/src/sv_pool.c b/doomsday/engine/portable/src/sv_pool.c index 49eb79066c..d42e6863cf 100644 --- a/doomsday/engine/portable/src/sv_pool.c +++ b/doomsday/engine/portable/src/sv_pool.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -139,7 +139,7 @@ static line_t **sideOwners; // CODE -------------------------------------------------------------------- -/* +/** * Called once for each level, from R_SetupLevel(). Initialize the world * register and drain all pools. */ @@ -229,14 +229,14 @@ void Sv_InitPools(void) #endif } -/* +/** * Called during server shutdown (when shutting down the engine). */ void Sv_ShutdownPools(void) { } -/* +/** * Called when a client joins the game. */ void Sv_InitPoolForClient(int clientNumber) @@ -254,7 +254,7 @@ void Sv_InitPoolForClient(int clientNumber) pools[clientNumber].isFirst = true; } -/* +/** * Returns a pointer to the console's delta pool. */ pool_t *Sv_GetPool(int consoleNumber) @@ -262,7 +262,7 @@ pool_t *Sv_GetPool(int consoleNumber) return &pools[consoleNumber]; } -/* +/** * The hash function for the register mobj hash. */ uint Sv_RegisterHashFunction(thid_t id) @@ -270,10 +270,10 @@ uint Sv_RegisterHashFunction(thid_t id) return (uint) id & REG_MOBJ_HASH_FUNCTION_MASK; } -/* +/** * Returns a pointer to the register-mobj, if it already exists. */ -reg_mobj_t *Sv_RegisterFindMobj(cregister_t * reg, thid_t id) +reg_mobj_t *Sv_RegisterFindMobj(cregister_t *reg, thid_t id) { mobjhash_t *hash = ®->mobjs[Sv_RegisterHashFunction(id)]; reg_mobj_t *iter; @@ -291,10 +291,10 @@ reg_mobj_t *Sv_RegisterFindMobj(cregister_t * reg, thid_t id) return NULL; } -/* +/** * Adds a new reg_mobj_t to the register's mobj hash. */ -reg_mobj_t *Sv_RegisterAddMobj(cregister_t * reg, thid_t id) +reg_mobj_t *Sv_RegisterAddMobj(cregister_t *reg, thid_t id) { mobjhash_t *hash = ®->mobjs[Sv_RegisterHashFunction(id)]; reg_mobj_t *newRegMo; @@ -324,10 +324,10 @@ reg_mobj_t *Sv_RegisterAddMobj(cregister_t * reg, thid_t id) return newRegMo; } -/* +/** * Removes a reg_mobj_t from the register's mobj hash. */ -void Sv_RegisterRemoveMobj(cregister_t * reg, reg_mobj_t * regMo) +void Sv_RegisterRemoveMobj(cregister_t *reg, reg_mobj_t *regMo) { mobjhash_t *hash = ®->mobjs[Sv_RegisterHashFunction(regMo->mo.thinker.id)]; @@ -356,7 +356,7 @@ void Sv_RegisterRemoveMobj(cregister_t * reg, reg_mobj_t * regMo) Z_Free(regMo); } -/* +/** * If the mobj is on the floor, returns MININT. If the mobj is touching the * ceiling, returns MAXINT. Otherwise returns the Z coordinate. The maxed-out * coordinate is stored in the register. @@ -374,11 +374,11 @@ fixed_t Sv_GetMaxedMobjZ(const mobj_t *mo) return mo->pos[VZ]; } -/* +/** * Store the state of the mobj into the register-mobj. * Called at register init and after each delta generation cycle. */ -void Sv_RegisterMobj(dt_mobj_t * reg, const mobj_t *mo) +void Sv_RegisterMobj(dt_mobj_t *reg, const mobj_t *mo) { // (dt_mobj_t <=> mobj_t) // Just copy the data we need. @@ -404,11 +404,11 @@ void Sv_RegisterMobj(dt_mobj_t * reg, const mobj_t *mo) reg->vistarget = mo->vistarget; } -/* +/** * Reset the data of the registered mobj to reasonable defaults. * In effect, forces a resend of the zeroed entries as deltas. */ -void Sv_RegisterResetMobj(dt_mobj_t * reg) +void Sv_RegisterResetMobj(dt_mobj_t *reg) { reg->pos[VX] = 0; reg->pos[VY] = 0; @@ -424,11 +424,11 @@ void Sv_RegisterResetMobj(dt_mobj_t * reg) reg->vistarget = 0; } -/* +/** * Store the state of the player into the register-player. * Called at register init and after each delta generation cycle. */ -void Sv_RegisterPlayer(dt_player_t * reg, int number) +void Sv_RegisterPlayer(dt_player_t *reg, int number) { ddplayer_t *p = players + number; client_t *c = clients + number; @@ -455,7 +455,7 @@ void Sv_RegisterPlayer(dt_player_t * reg, int number) * @param reg The sector register to be initialized. * @param number The world sector number to be registered. */ -void Sv_RegisterSector(dt_sector_t * reg, int number) +void Sv_RegisterSector(dt_sector_t *reg, int number) { int i; sector_t *sec = SECTOR_PTR(number); @@ -482,11 +482,11 @@ void Sv_RegisterSector(dt_sector_t * reg, int number) } } -/* +/** * Store the state of the side into the register-side. * Called at register init and after each delta generation. */ -void Sv_RegisterSide(dt_side_t * reg, int number) +void Sv_RegisterSide(dt_side_t *reg, int number) { side_t *side = SIDE_PTR(number); line_t *line = sideOwners[number]; @@ -503,11 +503,11 @@ void Sv_RegisterSide(dt_side_t * reg, int number) reg->flags = side->flags & 0xff; } -/* +/** * Store the state of the polyobj into the register-poly. * Called at register init and after each delta generation. */ -void Sv_RegisterPoly(dt_poly_t * reg, int number) +void Sv_RegisterPoly(dt_poly_t *reg, int number) { polyobj_t *poly = PO_PTR(number); @@ -518,11 +518,11 @@ void Sv_RegisterPoly(dt_poly_t * reg, int number) reg->angleSpeed = poly->angleSpeed; } -/* +/** * Returns true if the result is not void. */ -boolean Sv_RegisterCompareMobj(cregister_t * reg, const mobj_t *s, - mobjdelta_t * d) +boolean Sv_RegisterCompareMobj(cregister_t *reg, const mobj_t *s, + mobjdelta_t *d) { int df; reg_mobj_t *regMo = NULL; @@ -606,11 +606,11 @@ boolean Sv_RegisterCompareMobj(cregister_t * reg, const mobj_t *s, return !Sv_IsVoidDelta(d); } -/* +/** * Returns true if the result is not void. */ -boolean Sv_RegisterComparePlayer(cregister_t * reg, int number, - playerdelta_t * d) +boolean Sv_RegisterComparePlayer(cregister_t *reg, int number, + playerdelta_t *d) { const dt_player_t *r = ®->players[number]; dt_player_t *s = &d->player; @@ -646,7 +646,7 @@ boolean Sv_RegisterComparePlayer(cregister_t * reg, int number, /* // The player sprites are a bit more complicated to check. - for(i = 0; i < 2; i++) + for(i = 0; i < 2; ++i) { int off = 16 + i * 8; const ddpsprite_t *rps = r->psp + i; @@ -675,11 +675,11 @@ boolean Sv_RegisterComparePlayer(cregister_t * reg, int number, return !Sv_IsVoidDelta(d); } -/* +/** * Returns true if the result is not void. */ -boolean Sv_RegisterCompareSector(cregister_t * reg, int number, - sectordelta_t * d, byte doUpdate) +boolean Sv_RegisterCompareSector(cregister_t *reg, int number, + sectordelta_t *d, byte doUpdate) { dt_sector_t *r = ®->sectors[number]; const sector_t *s = SECTOR_PTR(number); @@ -820,10 +820,10 @@ boolean Sv_RegisterCompareSector(cregister_t * reg, int number, return !Sv_IsVoidDelta(d); } -/* +/** * Returns true if the result is not void. */ -boolean Sv_RegisterCompareSide(cregister_t * reg, int number, sidedelta_t * d, +boolean Sv_RegisterCompareSide(cregister_t *reg, int number, sidedelta_t *d, byte doUpdate) { const side_t *s = SIDE_PTR(number); @@ -958,10 +958,10 @@ boolean Sv_RegisterCompareSide(cregister_t * reg, int number, sidedelta_t * d, return !Sv_IsVoidDelta(d); } -/* +/** * Returns true if the result is not void. */ -boolean Sv_RegisterComparePoly(cregister_t * reg, int number, polydelta_t * d) +boolean Sv_RegisterComparePoly(cregister_t *reg, int number, polydelta_t *d) { const dt_poly_t *r = ®->polys[number]; dt_poly_t *s = &d->po; @@ -987,7 +987,7 @@ boolean Sv_RegisterComparePoly(cregister_t * reg, int number, polydelta_t * d) return !Sv_IsVoidDelta(d); } -/* +/** * Returns true if the mobj can be excluded from delta processing. */ boolean Sv_IsMobjIgnored(mobj_t *mo) @@ -995,7 +995,7 @@ boolean Sv_IsMobjIgnored(mobj_t *mo) return (mo->ddflags & DDMF_LOCAL) != 0; } -/* +/** * Returns true if the player can be excluded from delta processing. */ boolean Sv_IsPlayerIgnored(int number) @@ -1003,7 +1003,7 @@ boolean Sv_IsPlayerIgnored(int number) return !players[number].ingame; } -/* +/** * Initialize the register with the current state of the world. * The arrays are allocated and the data is copied, nothing else is done. * @@ -1012,7 +1012,7 @@ boolean Sv_IsPlayerIgnored(int number) * initial register, clients wouldn't receive much info from mobjs that * haven't moved since the beginning. */ -void Sv_RegisterWorld(cregister_t * reg, boolean isInitial) +void Sv_RegisterWorld(cregister_t *reg, boolean isInitial) { int i; @@ -1024,14 +1024,14 @@ void Sv_RegisterWorld(cregister_t * reg, boolean isInitial) // Init sectors. reg->sectors = Z_Calloc(sizeof(dt_sector_t) * numsectors, PU_LEVEL, 0); - for(i = 0; i < numsectors; i++) + for(i = 0; i < numsectors; ++i) { Sv_RegisterSector(®->sectors[i], i); } // Init sides. reg->sides = Z_Calloc(sizeof(dt_side_t) * numsides, PU_LEVEL, 0); - for(i = 0; i < numsides; i++) + for(i = 0; i < numsides; ++i) { Sv_RegisterSide(®->sides[i], i); } @@ -1040,16 +1040,16 @@ void Sv_RegisterWorld(cregister_t * reg, boolean isInitial) reg->polys = (po_NumPolyobjs ? Z_Calloc(sizeof(dt_poly_t) * po_NumPolyobjs, PU_LEVEL, 0) : NULL); - for(i = 0; i < po_NumPolyobjs; i++) + for(i = 0; i < po_NumPolyobjs; ++i) { Sv_RegisterPoly(®->polys[i], i); } } -/* +/** * Update the pool owner's info. */ -void Sv_UpdateOwnerInfo(pool_t * pool) +void Sv_UpdateOwnerInfo(pool_t *pool) { ddplayer_t *player = &players[pool->owner]; ownerinfo_t *info = &pool->ownerInfo; @@ -1074,7 +1074,7 @@ void Sv_UpdateOwnerInfo(pool_t * pool) info->ackThreshold = Net_GetAckThreshold(pool->owner); } -/* +/** * Returns a timestamp that is used to track how old deltas are. */ uint Sv_GetTimeStamp(void) @@ -1082,7 +1082,7 @@ uint Sv_GetTimeStamp(void) return Sys_GetRealTime(); } -/* +/** * Initialize a new delta. */ void Sv_NewDelta(void *deltaPtr, deltatype_t type, uint id) @@ -1098,7 +1098,7 @@ void Sv_NewDelta(void *deltaPtr, deltatype_t type, uint id) delta->timeStamp = Sv_GetTimeStamp(); } -/* +/** * Returns true if the delta contains no information. */ boolean Sv_IsVoidDelta(const void *delta) @@ -1106,7 +1106,7 @@ boolean Sv_IsVoidDelta(const void *delta) return ((const delta_t *) delta)->flags == 0; } -/* +/** * Returns true if the delta is a Sound delta. */ boolean Sv_IsSoundDelta(const void *delta) @@ -1117,7 +1117,7 @@ boolean Sv_IsSoundDelta(const void *delta) d->type == DT_SECTOR_SOUND || d->type == DT_POLY_SOUND); } -/* +/** * Returns true if the delta is a Start Sound delta. */ boolean Sv_IsStartSoundDelta(const void *delta) @@ -1128,7 +1128,7 @@ boolean Sv_IsStartSoundDelta(const void *delta) d->volume > 0); } -/* +/** * Returns true if the delta is Stop Sound delta. */ boolean Sv_IsStopSoundDelta(const void *delta) @@ -1139,7 +1139,7 @@ boolean Sv_IsStopSoundDelta(const void *delta) d->volume <= 0); } -/* +/** * Returns true if the delta is a Null Mobj delta. */ boolean Sv_IsNullMobjDelta(const void *delta) @@ -1148,7 +1148,7 @@ boolean Sv_IsNullMobjDelta(const void *delta) ((const delta_t *) delta)->flags & MDFC_NULL; } -/* +/** * Returns true if the delta is a Create Mobj delta. */ boolean Sv_IsCreateMobjDelta(const void *delta) @@ -1157,7 +1157,7 @@ boolean Sv_IsCreateMobjDelta(const void *delta) ((const delta_t *) delta)->flags & MDFC_CREATE; } -/* +/** * Returns true if the deltas refer to the same object. */ boolean Sv_IsSameDelta(const void *delta1, const void *delta2) @@ -1167,7 +1167,7 @@ boolean Sv_IsSameDelta(const void *delta1, const void *delta2) return (a->type == b->type) && (a->id == b->id); } -/* +/** * Makes a copy of the delta. */ void *Sv_CopyDelta(void *deltaPtr) @@ -1197,7 +1197,7 @@ void *Sv_CopyDelta(void *deltaPtr) return newDelta; } -/* +/** * Subtracts the contents of the second delta from the first delta. * Subtracting means that if a given flag is defined for both 1 and 2, * the flag for 1 is cleared (2 overrides 1). The result is that the @@ -1229,7 +1229,7 @@ void Sv_SubtractDelta(void *deltaPtr1, const void *deltaPtr2) } } -/* +/** * Applies the data in the source delta to the destination delta. * Both must be in the NEW state. Handles all types of deltas. */ @@ -1315,7 +1315,7 @@ void Sv_ApplyDeltaData(void *destDelta, const void *srcDelta) { int i; - for(i = 0; i < 2; i++) + for(i = 0; i < 2; ++i) { int off = 16 + i * 8; @@ -1496,7 +1496,7 @@ void Sv_ApplyDeltaData(void *destDelta, const void *srcDelta) } } -/* +/** * Merges the second delta with the first one. * The source and destination must refer to the same entity. * Returns false if the result of the merge is a void delta. @@ -1569,19 +1569,19 @@ boolean Sv_MergeDelta(void *destDelta, const void *srcDelta) return true; } -/* +/** * Returns the age of the delta, in milliseconds. */ -uint Sv_DeltaAge(const delta_t * delta) +uint Sv_DeltaAge(const delta_t *delta) { return Sv_GetTimeStamp() - delta->timeStamp; } -/* +/** * Approximate the distance to the given sector. Set 'mayBeGone' to true * if the mobj may have been destroyed and should not be processed. */ -fixed_t Sv_MobjDistance(const mobj_t *mo, const ownerinfo_t * info, +fixed_t Sv_MobjDistance(const mobj_t *mo, const ownerinfo_t *info, boolean isReal) { fixed_t z; @@ -1607,10 +1607,10 @@ fixed_t Sv_MobjDistance(const mobj_t *mo, const ownerinfo_t * info, info->z - (z + mo->height / 2)); } -/* +/** * Approximate the distance to the given sector. */ -fixed_t Sv_SectorDistance(int index, const ownerinfo_t * info) +fixed_t Sv_SectorDistance(int index, const ownerinfo_t *info) { sector_t *sector = SECTOR_PTR(index); @@ -1621,10 +1621,10 @@ fixed_t Sv_SectorDistance(int index, const ownerinfo_t * info) sector->planes[PLN_FLOOR]->height) / 2)); } -/* +/** * Returns the distance to the origin of the delta's entity. */ -fixed_t Sv_DeltaDistance(const void *deltaPtr, const ownerinfo_t * info) +fixed_t Sv_DeltaDistance(const void *deltaPtr, const ownerinfo_t *info) { const delta_t *delta = deltaPtr; @@ -1695,18 +1695,18 @@ fixed_t Sv_DeltaDistance(const void *deltaPtr, const ownerinfo_t * info) return FRACUNIT; } -/* +/** * The hash function for the pool delta hash. */ -deltalink_t *Sv_PoolHash(pool_t * pool, int id) +deltalink_t *Sv_PoolHash(pool_t *pool, int id) { return &pool->hash[(uint) id & POOL_HASH_FUNCTION_MASK]; } -/* +/** * The delta is removed from the pool's delta hash. */ -void Sv_RemoveDelta(pool_t * pool, void *deltaPtr) +void Sv_RemoveDelta(pool_t *pool, void *deltaPtr) { delta_t *delta = deltaPtr; deltalink_t *hash = Sv_PoolHash(pool, delta->id); @@ -1735,7 +1735,7 @@ void Sv_RemoveDelta(pool_t * pool, void *deltaPtr) Z_Free(delta); } -/* +/** * Draining the pool means emptying it of all contents. (Doh?) */ void Sv_DrainPool(int clientNumber) @@ -1756,7 +1756,7 @@ void Sv_DrainPool(int clientNumber) Sv_PoolQueueClear(pool); // Free all deltas stored in the hash. - for(i = 0; i < POOL_HASH_SIZE; i++) + for(i = 0; i < POOL_HASH_SIZE; ++i) { for(delta = pool->hash[i].first; delta; delta = next) { @@ -1766,7 +1766,7 @@ void Sv_DrainPool(int clientNumber) } // Free all missile records in the pool. - for(i = 0; i < POOL_MISSILE_HASH_SIZE; i++) + for(i = 0; i < POOL_MISSILE_HASH_SIZE; ++i) { for(mis = pool->misHash[i].first; mis; mis = next) { @@ -1780,11 +1780,11 @@ void Sv_DrainPool(int clientNumber) memset(pool->misHash, 0, sizeof(pool->misHash)); } -/* +/** * Returns the maximum distance for the sound. If the origin is any * farther, the delta will not be sent to the client in question. */ -fixed_t Sv_GetMaxSoundDistance(const sounddelta_t * delta) +fixed_t Sv_GetMaxSoundDistance(const sounddelta_t *delta) { float volume = 1; @@ -1802,10 +1802,10 @@ fixed_t Sv_GetMaxSoundDistance(const sounddelta_t * delta) return volume * sound_max_distance * FRACUNIT; } -/* +/** * Returns the flags that remain after exclusion. */ -int Sv_ExcludeDelta(pool_t * pool, const void *deltaPtr) +int Sv_ExcludeDelta(pool_t *pool, const void *deltaPtr) { const delta_t *delta = deltaPtr; ddplayer_t *player = &players[pool->owner]; @@ -1890,7 +1890,7 @@ int Sv_ExcludeDelta(pool_t * pool, const void *deltaPtr) return flags; } -/* +/** * When adding a delta to the pool, it subtracts from the unacked deltas * there and is merged with matching new deltas. If a delta becomes void * after subtraction, it's removed from the pool. All the processing is @@ -1902,7 +1902,7 @@ int Sv_ExcludeDelta(pool_t * pool, const void *deltaPtr) * * The contents of the delta must not be modified. */ -void Sv_AddDelta(pool_t * pool, void *deltaPtr) +void Sv_AddDelta(pool_t *pool, void *deltaPtr) { delta_t *iter; delta_t *next = NULL; @@ -1993,10 +1993,10 @@ void Sv_AddDelta(pool_t * pool, void *deltaPtr) delta->flags = originalFlags; } -/* +/** * Add the delta to all the pools in the NULL-terminated array. */ -void Sv_AddDeltaToPools(void *deltaPtr, pool_t ** targets) +void Sv_AddDeltaToPools(void *deltaPtr, pool_t **targets) { for(; *targets; targets++) { @@ -2004,10 +2004,10 @@ void Sv_AddDeltaToPools(void *deltaPtr, pool_t ** targets) } } -/* +/** * All NEW deltas for the mobj are removed from the pool as obsolete. */ -void Sv_PoolMobjRemoved(pool_t * pool, thid_t id) +void Sv_PoolMobjRemoved(pool_t *pool, thid_t id) { deltalink_t *hash = Sv_PoolHash(pool, id); delta_t *delta, *next = NULL; @@ -2028,7 +2028,7 @@ void Sv_PoolMobjRemoved(pool_t * pool, thid_t id) Sv_MRRemove(pool, id); } -/* +/** * This is called when a mobj is removed in a predictable fashion. * (Mobj state is NULL when it's destroyed. Assumption: The NULL state * is set only when animation reaches its end.) Because the register-mobj @@ -2049,7 +2049,7 @@ void Sv_MobjRemoved(thid_t id) // the register, no Null Mobj delta is generated, and thus the // client will eventually receive those mobj deltas unnecessarily. - for(i = 0; i < MAXPLAYERS; i++) + for(i = 0; i < MAXPLAYERS; ++i) { if(clients[i].connected) { @@ -2059,7 +2059,7 @@ void Sv_MobjRemoved(thid_t id) } } -/* +/** * When a player leaves the game, his data is removed from the register. * Otherwise he'll not get all the data if he reconnects before the map * is changed. @@ -2071,10 +2071,10 @@ void Sv_PlayerRemoved(int playerNumber) memset(p, 0, sizeof(*p)); } -/* +/** * Returns true if the pool is in the targets array. */ -boolean Sv_IsPoolTargeted(pool_t * pool, pool_t ** targets) +boolean Sv_IsPoolTargeted(pool_t *pool, pool_t **targets) { for(; *targets; targets++) { @@ -2084,15 +2084,15 @@ boolean Sv_IsPoolTargeted(pool_t * pool, pool_t ** targets) return false; } -/* +/** * Fills the array with pointers to the pools of the connected clients, * if specificClient is < 0. Returns the number of pools in the list. */ -int Sv_GetTargetPools(pool_t ** targets, int clientsMask) +int Sv_GetTargetPools(pool_t **targets, int clientsMask) { int i, numTargets = 0; - for(i = 0; i < MAXPLAYERS; i++) + for(i = 0; i < MAXPLAYERS; ++i) { if(clientsMask & (1 << i) && clients[i].connected) { @@ -2107,7 +2107,7 @@ int Sv_GetTargetPools(pool_t ** targets, int clientsMask) return 1; } - for(i = 0; i < MAXPLAYERS; i++) + for(i = 0; i < MAXPLAYERS; ++i) { // Deltas must be generated for all connected players, even // if they aren't yet ready to receive them. @@ -2124,20 +2124,20 @@ int Sv_GetTargetPools(pool_t ** targets, int clientsMask) return numTargets; } -/* +/** * Null deltas are generated for mobjs that have been destroyed. * The register's mobj hash is scanned to see which mobjs no longer exist. * * When updating, the destroyed mobjs are removed from the register. */ -void Sv_NewNullDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) +void Sv_NewNullDeltas(cregister_t *reg, boolean doUpdate, pool_t **targets) { mobjhash_t *hash; reg_mobj_t *obj, *next = 0; mobjdelta_t null; int i; - for(i = 0, hash = reg->mobjs; i < REG_MOBJ_HASH_SIZE; i++, hash++) + for(i = 0, hash = reg->mobjs; i < REG_MOBJ_HASH_SIZE; ++i, hash++) { for(obj = hash->first; obj; obj = next) { @@ -2170,10 +2170,10 @@ void Sv_NewNullDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) } } -/* +/** * Mobj deltas are generated for all mobjs that have changed. */ -void Sv_NewMobjDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) +void Sv_NewMobjDeltas(cregister_t *reg, boolean doUpdate, pool_t **targets) { thinker_t *th; mobj_t *mo; @@ -2208,15 +2208,15 @@ void Sv_NewMobjDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) } } -/* +/** * Player deltas are generated for changed player data. */ -void Sv_NewPlayerDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) +void Sv_NewPlayerDeltas(cregister_t *reg, boolean doUpdate, pool_t **targets) { playerdelta_t player; int i; - for(i = 0; i < MAXPLAYERS; i++) + for(i = 0; i < MAXPLAYERS; ++i) { if(Sv_IsPlayerIgnored(i)) continue; @@ -2286,20 +2286,20 @@ void Sv_NewPlayerDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) // Doing this once is enough. players[i].flags &= ~(DDPF_FIXPOS | DDPF_FIXMOM); } -#endif +#endif } } } -/* +/** * Sector deltas are generated for changed sectors. */ -void Sv_NewSectorDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) +void Sv_NewSectorDeltas(cregister_t *reg, boolean doUpdate, pool_t **targets) { sectordelta_t delta; int i; - for(i = 0; i < numsectors; i++) + for(i = 0; i < numsectors; ++i) { if(Sv_RegisterCompareSector(reg, i, &delta, doUpdate)) { @@ -2308,12 +2308,12 @@ void Sv_NewSectorDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) } } -/* +/** * Side deltas are generated for changed sides (and line flags). * Changes in sides (textures) are so rare that all sides need not be * checked on every tic. */ -void Sv_NewSideDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) +void Sv_NewSideDeltas(cregister_t *reg, boolean doUpdate, pool_t **targets) { static int numShifts = 2; static int shift = 0; @@ -2337,7 +2337,7 @@ void Sv_NewSideDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) shift %= numShifts; } - for(i = start; i < end; i++) + for(i = start; i < end; ++i) { // The side must be owned by a line. if(sideOwners[i] == NULL) @@ -2350,15 +2350,15 @@ void Sv_NewSideDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) } } -/* +/** * Poly deltas are generated for changed polyobjs. */ -void Sv_NewPolyDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) +void Sv_NewPolyDeltas(cregister_t *reg, boolean doUpdate, pool_t **targets) { polydelta_t delta; int i; - for(i = 0; i < po_NumPolyobjs; i++) + for(i = 0; i < po_NumPolyobjs; ++i) { if(Sv_RegisterComparePoly(reg, i, &delta)) { @@ -2375,7 +2375,7 @@ void Sv_NewPolyDeltas(cregister_t * reg, boolean doUpdate, pool_t ** targets) } } -/* +/** * Adds a new sound delta to the appropriate pools. * Because the starting of a sound is in itself a 'delta-like' event, * there is no need for comparing or to have a register. @@ -2441,7 +2441,7 @@ void Sv_NewSoundDelta(int soundId, mobj_t *emitter, int sourceSector, Sv_AddDeltaToPools(&soundDelta, targets); } -/* +/** * Returns true if the client should receive frames. */ boolean Sv_IsFrameTarget(int number) @@ -2453,7 +2453,7 @@ boolean Sv_IsFrameTarget(int number) clients[number].recording); } -/* +/** * Compare the current state of the world with the register and add the * deltas to all the pools, or if a specific client number is given, only * to its pool (done when a new client enters the game). No deltas will be @@ -2464,7 +2464,7 @@ boolean Sv_IsFrameTarget(int number) * * clientNumber < 0: All ingame clients should get the deltas. */ -void Sv_GenerateNewDeltas(cregister_t * reg, int clientNumber, +void Sv_GenerateNewDeltas(cregister_t *reg, int clientNumber, boolean doUpdate) { pool_t *targets[MAXPLAYERS + 1], **pool; @@ -2503,7 +2503,7 @@ void Sv_GenerateNewDeltas(cregister_t * reg, int clientNumber, } } -/* +/** * This is called once for each frame, in Sv_TransmitFrame(). */ void Sv_GenerateFrameDeltas(void) @@ -2512,18 +2512,18 @@ void Sv_GenerateFrameDeltas(void) Sv_GenerateNewDeltas(&worldRegister, -1, true); } -/* +/** * Clears the priority queue of the pool. */ -void Sv_PoolQueueClear(pool_t * pool) +void Sv_PoolQueueClear(pool_t *pool) { pool->queueSize = 0; } -/* +/** * Exchanges two elements in the queue. */ -void Sv_PoolQueueExchange(pool_t * pool, int index1, int index2) +void Sv_PoolQueueExchange(pool_t *pool, int index1, int index2) { delta_t *temp = pool->queue[index1]; @@ -2531,11 +2531,11 @@ void Sv_PoolQueueExchange(pool_t * pool, int index1, int index2) pool->queue[index2] = temp; } -/* +/** * Adds the delta to the priority queue. More memory is allocated for * the queue if necessary. */ -void Sv_PoolQueueAdd(pool_t * pool, delta_t * delta) +void Sv_PoolQueueAdd(pool_t *pool, delta_t *delta) { int i, parent; @@ -2589,11 +2589,11 @@ void Sv_PoolQueueAdd(pool_t * pool, delta_t * delta) } } -/* +/** * Extracts the delta with the highest priority from the queue. * Returns NULL if there are no more deltas. */ -delta_t *Sv_PoolQueueExtract(pool_t * pool) +delta_t *Sv_PoolQueueExtract(pool_t *pool) { delta_t *max; int i = 0, left, right, big; @@ -2644,10 +2644,10 @@ delta_t *Sv_PoolQueueExtract(pool_t * pool) return max; } -/* +/** * Postponed deltas can't be sent yet. */ -boolean Sv_IsPostponedDelta(void *deltaPtr, ownerinfo_t * info) +boolean Sv_IsPostponedDelta(void *deltaPtr, ownerinfo_t *info) { delta_t *delta = deltaPtr; uint age = Sv_DeltaAge(delta); @@ -2693,12 +2693,12 @@ boolean Sv_IsPostponedDelta(void *deltaPtr, ownerinfo_t * info) return false; } -/* +/** * Calculate a priority score for the delta. A higher score indicates * greater importance. Returns true if the delta should be included * in the queue. */ -boolean Sv_RateDelta(void *deltaPtr, ownerinfo_t * info) +boolean Sv_RateDelta(void *deltaPtr, ownerinfo_t *info) { float score, distance, size; delta_t *delta = deltaPtr; @@ -2797,12 +2797,12 @@ boolean Sv_RateDelta(void *deltaPtr, ownerinfo_t * info) return (delta->score = score) > 0; } -/* +/** * Calculate a priority score for each delta and build the priority queue. * The most important deltas will be included in a frame packet. * A pool is rated after new deltas have been generated. */ -void Sv_RatePool(pool_t * pool) +void Sv_RatePool(pool_t *pool) { #ifdef _DEBUG ddplayer_t *player = &players[pool->owner]; @@ -2823,7 +2823,7 @@ void Sv_RatePool(pool_t * pool) // We will rate all the deltas in the pool. After each delta // has been rated, it's added to the priority queue. - for(i = 0; i < POOL_HASH_SIZE; i++) + for(i = 0; i < POOL_HASH_SIZE; ++i) { for(delta = pool->hash[i].first; delta; delta = delta->next) { @@ -2835,7 +2835,7 @@ void Sv_RatePool(pool_t * pool) } } -/* +/** * Do special things that need to be done when the delta has been acked. */ void Sv_AckDelta(pool_t *pool, delta_t *delta) @@ -2854,7 +2854,7 @@ void Sv_AckDelta(pool_t *pool, delta_t *delta) } } -/* +/** * Acknowledged deltas are removed from the pool, never to be seen again. * Clients ack deltas to tell the server they've received them. * If 'resent' is nonzero, ignore 'set' and ack by resend ID. @@ -2867,7 +2867,7 @@ void Sv_AckDeltaSet(int clientNumber, int set, byte resent) int i; // Iterate through the entire hash table. - for(i = 0; i < POOL_HASH_SIZE; i++) + for(i = 0; i < POOL_HASH_SIZE; ++i) { for(delta = pool->hash[i].first; delta; delta = next) { @@ -2894,7 +2894,7 @@ void Sv_AckDeltaSet(int clientNumber, int set, byte resent) } } -/* +/** * Debugging metric. */ int Sv_CountUnackedDeltas(int clientNumber) @@ -2904,7 +2904,7 @@ int Sv_CountUnackedDeltas(int clientNumber) int i, count = 0; // Iterate through the entire hash table. - for(i = 0; i < POOL_HASH_SIZE; i++) + for(i = 0; i < POOL_HASH_SIZE; ++i) { for(delta = pool->hash[i].first; delta; delta = delta->next) { diff --git a/doomsday/engine/portable/src/sys_filein.c b/doomsday/engine/portable/src/sys_filein.c index 7420bb11a4..da92609e75 100644 --- a/doomsday/engine/portable/src/sys_filein.c +++ b/doomsday/engine/portable/src/sys_filein.c @@ -4,6 +4,7 @@ * Online License Link: http://www.gnu.org/licenses/gpl.html * *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -102,7 +103,7 @@ static unsigned int vdMappingsMax; // CODE -------------------------------------------------------------------- -/* +/** * Returns true if the string matches the pattern. * This is a case-insensitive test. * I do hope this algorithm works like it should... @@ -138,7 +139,7 @@ int F_MatchName(const char *string, const char *pattern) return *st == 0; } -/* +/** * Skips all whitespace except newlines. */ char *F_SkipSpace(char *ptr) @@ -157,15 +158,20 @@ char *F_FindNewline(char *ptr) int F_GetDirecIdx(char *exact_path) { - int i; + int i; + boolean found; - for(i = 0; direc[i].path; i++) + for(i = 0, found = false; direc[i].path && !found; ++i) if(!stricmp(direc[i].path, exact_path)) - return i; - return -1; + found = true; + + if(found) + return i; + else + return -1; } -/* +/** * The path names are converted to full paths before adding to the table. */ void F_AddDirec(char *lumpname, char *symbolic_path) @@ -177,7 +183,7 @@ void F_AddDirec(char *lumpname, char *symbolic_path) if(!lumpname[0] || !symbolic_path[0]) return; - for(i = 0; direc[i].path && i < MAX_LUMPDIRS; i++); + for(i = 0; direc[i].path && i < MAX_LUMPDIRS; ++i); if(i == MAX_LUMPDIRS) { // FIXME: Why no dynamic allocation? @@ -202,7 +208,7 @@ void F_AddDirec(char *lumpname, char *symbolic_path) if(i >= 0) { // Already exists! - free(full); + M_Free(full); ld = direc + i; full = ld->path; } @@ -216,7 +222,7 @@ void F_AddDirec(char *lumpname, char *symbolic_path) } } -/* +/** * The path names are converted to full paths before adding to the table. * Files in the source directory are mapped to the target directory. */ @@ -242,7 +248,7 @@ void F_AddMapping(const char* source, const char* destination) if(vdMappingsMax < vdMappingsCount) vdMappingsMax = 2*vdMappingsCount; - vdMappings = realloc(vdMappings, sizeof(vdmapping_t) * vdMappingsMax); + vdMappings = M_Realloc(vdMappings, sizeof(vdmapping_t) * vdMappingsMax); } // Fill in the info into the array. @@ -254,7 +260,7 @@ void F_AddMapping(const char* source, const char* destination) vd->source, vd->target)); } -/* +/** * LUMPNAM0 \Path\In\The\Base.ext * LUMPNAM1 Path\In\The\RuntimeDir.ext * : @@ -306,17 +312,18 @@ void F_ParseDirecData(char *buffer) void F_InitMapping(void) { int i; + int argC = Argc(); F_ResetMapping(); // Create virtual directory mappings by processing all -vdmap // options. - for(i = 0; i < Argc(); i++) + for(i = 0; i < argC; ++i) { if(stricmp(Argv(i), "-vdmap")) continue; // This is not the option we're looking for. - if(i < Argc() - 1 && !ArgIsOption(i + 1) && !ArgIsOption(i + 2)) + if(i < argC - 1 && !ArgIsOption(i + 1) && !ArgIsOption(i + 2)) { F_AddMapping(Argv(i + 1), Argv(i + 2)); i += 2; @@ -324,14 +331,14 @@ void F_InitMapping(void) } } -/* +/** * Initialize the WAD/dir translations. Called after WADs have been read. */ void F_InitDirec(void) { static boolean alreadyInited = false; int i, len; - byte *buf; + char *buf; if(alreadyInited) { @@ -341,7 +348,7 @@ void F_InitDirec(void) } // Add the contents of all DD_DIREC lumps. - for(i = 0; i < numlumps; i++) + for(i = 0; i < numlumps; ++i) if(!strnicmp(lumpinfo[i].name, "DD_DIREC", 8)) { // Make a copy of it so we can make it end in a null. @@ -363,11 +370,11 @@ void F_ResetMapping(void) // Free the allocated memory. for(i = 0; i < vdMappingsCount; ++i) { - free(vdMappings[i].source); - free(vdMappings[i].target); + M_Free(vdMappings[i].source); + M_Free(vdMappings[i].target); } - free(vdMappings); + M_Free(vdMappings); vdMappings = NULL; vdMappingsCount = vdMappingsMax = 0; } @@ -376,23 +383,23 @@ void F_ResetDirec(void) { int i; - for(i = 0; direc[i].path; i++) + for(i = 0; direc[i].path; ++i) if(direc[i].path) - free(direc[i].path); // Allocated by _fullpath. + M_Free(direc[i].path); // Allocated by _fullpath. } void F_CloseAll(void) { unsigned int i; - for(i = 0; i < filesCount; i++) + for(i = 0; i < filesCount; ++i) //if(files[i].file->flags.open) if(files[i].file != NULL) { F_Close(files[i].file); } - free(files); + M_Free(files); files = NULL; filesCount = 0; } @@ -404,7 +411,7 @@ void F_ShutdownDirec(void) F_CloseAll(); } -/* +/** * Returns true if the file can be opened for reading. */ int F_Access(const char *path) @@ -421,13 +428,19 @@ int F_Access(const char *path) DFILE *F_GetFreeFile(void) { unsigned int i, oldCount; + boolean found; + filehandle_t *fhdl; - for(i = 0; i < filesCount; i++) - if(files[i].file == NULL) - { - files[i].file = calloc(1, sizeof(DFILE)); - return files[i].file; - } + for(i = 0, found = false, fhdl = files; i < filesCount && !found; + fhdl++, ++i) + if(fhdl->file == NULL) + found = true; + + if(found) + { + fhdl->file = M_Calloc(sizeof(DFILE)); + return fhdl->file; + } oldCount = filesCount; @@ -436,19 +449,19 @@ DFILE *F_GetFreeFile(void) if(filesCount < 16) filesCount = 16; - files = realloc(files, sizeof(filehandle_t) * filesCount); + files = M_Realloc(files, sizeof(filehandle_t) * filesCount); // Clear the new handles. for(i = oldCount; i < filesCount; ++i) { - memset(files + i, 0, sizeof(filehandle_t)); + memset(&files[i], 0, sizeof(filehandle_t)); } - files[oldCount].file = calloc(1, sizeof(DFILE)); + files[oldCount].file = M_Calloc(sizeof(DFILE)); return files[oldCount].file; } -/* +/** * Frees the memory allocated to the handle. */ void F_Release(DFILE *file) @@ -461,7 +474,7 @@ void F_Release(DFILE *file) files[i].file = NULL; // File was allocated in F_GetFreeFile. - free(file); + M_Free(file); } DFILE *F_OpenLump(const char *name, boolean dontBuffer) @@ -488,7 +501,7 @@ DFILE *F_OpenLump(const char *name, boolean dontBuffer) return file; } -/* +/** * This only works on real files. */ static unsigned int F_GetLastModified(const char *path) @@ -506,7 +519,7 @@ static unsigned int F_GetLastModified(const char *path) #endif } -/* +/** * Returns true if the mapping matched the path. */ boolean F_MapPath(const char *path, vdmapping_t *vd, char *mapped) @@ -577,7 +590,7 @@ void F_TranslateZipFileName(const char *zipFileName, char *translated) M_PrependBasePath(zipFileName, translated); } -/* +/** * Zip data is buffered like lump data. */ DFILE *F_OpenZip(zipindex_t zipIndex, boolean dontBuffer) @@ -600,7 +613,7 @@ DFILE *F_OpenZip(zipindex_t zipIndex, boolean dontBuffer) return file; } -/* +/** * Opens the given file (will be translated) or lump for reading. * "t" = text mode (with real files, lumps are always binary) * "b" = binary @@ -631,7 +644,7 @@ DFILE *F_Open(const char *path, const char *mode) if(foundZip) return F_OpenZip(foundZip, dontBuffer); - for(i = 0; direc[i].path; i++) + for(i = 0; direc[i].path; ++i) if(!stricmp(full, direc[i].path)) return F_OpenLump(direc[i].lump, dontBuffer); } @@ -661,7 +674,7 @@ void F_Close(DFILE *file) F_Release(file); } -/* +/** * Returns the number of bytes read (up to 'count'). */ int F_Read(void *dest, int count, DFILE *file) @@ -711,7 +724,7 @@ int F_Tell(DFILE *file) return file->pos - (char *) file->data; } -/* +/** * Returns the current position in the file, before the move, as an offset * from the beginning of the file. */ @@ -741,7 +754,7 @@ void F_Rewind(DFILE *file) F_Seek(file, 0, SEEK_SET); } -/* +/** * Returns the length of the file, in bytes. Stream position is not * affected. */ @@ -758,7 +771,7 @@ int F_Length(DFILE *file) return length; } -/* +/** * Returns the time when the file was last modified, as seconds since * the Epoch. Returns zero if the file is not found. */ @@ -775,7 +788,7 @@ unsigned int F_LastModified(const char *fileName) return modified; } -/* +/** * Returns the number of times the char appears in the path. */ int F_CountPathChars(const char *path, char ch) @@ -788,7 +801,7 @@ int F_CountPathChars(const char *path, char ch) return count; } -/* +/** * Returns true to stop searching when forall_func returns false. */ int F_ZipFinderForAll(const char *zipFileName, void *parm) @@ -809,7 +822,7 @@ static int C_DECL F_EntrySorter(const void* a, const void* b) ((const foundentry_t*)b)->name); } -/* +/** * Descends into 'physical' subdirectories. */ int F_ForAllDescend(const char *pattern, const char *path, void *parm, @@ -827,7 +840,7 @@ int F_ForAllDescend(const char *pattern, const char *path, void *parm, // paths mapped to the current path. count = 0; max = 16; - found = malloc(max * sizeof(*found)); + found = M_Malloc(max * sizeof(*found)); for(i = -1; i < (int)vdMappingsCount; ++i) { @@ -860,7 +873,7 @@ int F_ForAllDescend(const char *pattern, const char *path, void *parm, if(count >= max) { max *= 2; - found = realloc(found, sizeof(*found) * max); + found = M_Realloc(found, sizeof(*found) * max); } memset(&found[count], 0, sizeof(*found)); strncpy(found[count].name, fd.name, @@ -888,7 +901,7 @@ int F_ForAllDescend(const char *pattern, const char *path, void *parm, strcat(fn, DIR_SEP_STR); if(!F_ForAllDescend(pattern, fn, parm, func)) { - free(found); + M_Free(found); return false; } } @@ -900,7 +913,7 @@ int F_ForAllDescend(const char *pattern, const char *path, void *parm, // If the callback returns false, stop immediately. if(!func(fn, FT_NORMAL, parm)) { - free(found); + M_Free(found); return false; } } @@ -908,11 +921,11 @@ int F_ForAllDescend(const char *pattern, const char *path, void *parm, } // Free the memory allocate for the list of found entries. - free(found); + M_Free(found); return true; } -/* +/** * Parm is passed on to the callback, which is called for each file * matching the filespec. Absolute path names are given to the callback. * Zip directory, DD_DIREC and the real files are scanned. @@ -939,7 +952,7 @@ int F_ForAll(const char *filespec, void *parm, f_forall_func_t func) } // Check through the dir/WAD direcs. - for(i = 0; direc[i].path; i++) + for(i = 0; direc[i].path; ++i) if(F_MatchName(direc[i].path, fn)) if(!func(direc[i].path, FT_NORMAL, parm)) //if(!F_ForAllCaller(specdir.path, direc[i].path, func, parm)) diff --git a/doomsday/engine/portable/src/sys_network.c b/doomsday/engine/portable/src/sys_network.c index ce66c2707f..2a61cecdde 100644 --- a/doomsday/engine/portable/src/sys_network.c +++ b/doomsday/engine/portable/src/sys_network.c @@ -425,6 +425,7 @@ boolean N_ReceiveReliably(nodeid_t from) TCPsocket sock = netNodes[from].sock; UDPpacket *packet = NULL; int bytes = 0; + boolean error, read; // TODO: What if we get one byte? How come we are here if there's nothing // to receive? @@ -441,7 +442,9 @@ boolean N_ReceiveReliably(nodeid_t from) // Read the entire packet's data. packet = SDLNet_AllocPacket(size); bytes = 0; - while(bytes < size) + read = false; + error = false; + while(!read) { int received = SDLNet_TCP_Recv(sock, packet->data + bytes, size); if(received == -1) @@ -449,10 +452,15 @@ boolean N_ReceiveReliably(nodeid_t from) SDLNet_FreePacket(packet); Con_Message("N_ReceiveReliably: Error during TCP recv.\n %s (%s)", SDLNet_GetError(), strerror(errno)); - return false; + error = true; + read = true; } bytes += received; + if(!(bytes < size)) + read = true; } + if(error) + return false; // Post the received message. { @@ -822,19 +830,23 @@ Uint16 N_OpenUDPSocket(UDPsocket *sock, Uint16 preferPort, Uint16 defaultPort) { Uint16 port = (!preferPort ? defaultPort : preferPort); int tries = 1000; + boolean found; *sock = NULL; // Try opening the port, advance to next one if the opening fails. - for(; tries > 0; tries--) + for(found = false; tries > 0 && !found; --tries) { if((*sock = SDLNet_UDP_Open(port)) == NULL) port++; else - return port; + found = true; } - // Failure! - return 0; + + if(found) + return port; + else + return 0; // Failure! } /* @@ -947,7 +959,7 @@ void N_ShutdownService(void) serverSock = NULL; // Clear the client nodes. - for(i = 0; i < MAX_NODES; i++) + for(i = 0; i < MAX_NODES; ++i) N_TerminateNode(i); // Free the socket set. @@ -1060,17 +1072,19 @@ void N_TerminateNode(nodeid_t id) memset(node, 0, sizeof(*node)); } -/* +/** * Registers a new TCP socket as a client node. There can only be a * limited number of nodes at a time. This is only used by a server. */ static boolean N_RegisterNewSocket(TCPsocket sock) { - int i; - netnode_t *node; + int i; + netnode_t *node; + boolean found; // Find a free node. - for(i = 1, node = netNodes + 1; i < MAX_NODES; i++, node++) + for(i = 1, node = netNodes + 1, found = false; + i < MAX_NODES && !found; i++, node++) if(!node->sock) { // This'll do. @@ -1082,10 +1096,10 @@ static boolean N_RegisterNewSocket(TCPsocket sock) // Add this socket to the set of client sockets. SDLNet_TCP_AddSocket(sockSet, sock); - return true; + found = true; } - // There were no free nodes. - return false; + + return found; } /* diff --git a/doomsday/engine/portable/src/sys_sock.c b/doomsday/engine/portable/src/sys_sock.c index 1672f09d54..1efd84dca6 100644 --- a/doomsday/engine/portable/src/sys_sock.c +++ b/doomsday/engine/portable/src/sys_sock.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -94,7 +94,7 @@ void N_SockShutdown(void) void N_SockPrintf(socket_t s, const char *format, ...) { char buf[512]; - int length; + size_t length; va_list args; // Print the message into the buffer. diff --git a/doomsday/engine/portable/src/ui_main.c b/doomsday/engine/portable/src/ui_main.c index 31f6fb84be..dd855d6f71 100644 --- a/doomsday/engine/portable/src/ui_main.c +++ b/doomsday/engine/portable/src/ui_main.c @@ -209,7 +209,8 @@ void UI_End(void) rel.type = EV_KEY; rel.state = EVS_UP; rel.data1 = DDKEY_RSHIFT; - rel.useclass = -1; + rel.noclass = true; + rel.useclass = 0; DD_PostEvent(&rel); } } diff --git a/doomsday/engine/unix/src/sys_console.c b/doomsday/engine/unix/src/sys_console.c index 9b80984f41..8e58222b37 100644 --- a/doomsday/engine/unix/src/sys_console.c +++ b/doomsday/engine/unix/src/sys_console.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -190,6 +190,8 @@ void Sys_ConPostEvents(void) ev.type = EV_KEY; ev.state = EVS_DOWN; + ev.noclass = true; + ev.useclass = 0; // initialize with something ev.data1 = Sys_ConTranslateKey(key); DD_PostEvent(&ev); @@ -306,6 +308,7 @@ void Sys_ConUpdateCmdLine(char *text) unsigned int i; char line[LINELEN], *ch; int maxX = Sys_ConGetScreenSize(VX); + int length; if(text == NULL) { @@ -329,7 +332,8 @@ void Sys_ConUpdateCmdLine(char *text) wmove(winCommand, 0, 0); // Can't print longer than the window. - waddnstr(winCommand, line, MIN_OF(maxX, strlen(text) + 1)); + length = strlen(text); + waddnstr(winCommand, line, MIN_OF(maxX, length + 1)); wclrtoeol(winCommand); } wrefresh(winCommand); diff --git a/doomsday/engine/win32/src/sys_console.c b/doomsday/engine/win32/src/sys_console.c index 1696c1be7c..0b4862c4d1 100644 --- a/doomsday/engine/win32/src/sys_console.c +++ b/doomsday/engine/win32/src/sys_console.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -67,7 +67,7 @@ static int needNewLine = false; // CODE -------------------------------------------------------------------- -void Sys_ConInit() +void Sys_ConInit(void) { char title[256]; @@ -99,11 +99,11 @@ void Sys_ConInit() Sys_ConUpdateCmdLine(""); } -void Sys_ConShutdown() +void Sys_ConShutdown(void) { } -void Sys_ConPostEvents() +void Sys_ConPostEvents(void) { event_t ev; DWORD num, read; @@ -117,7 +117,7 @@ void Sys_ConPostEvents() ReadConsoleInput(hcInput, rec, MAXRECS, &read); for(ptr = rec; read > 0; read--, ptr++) { -Con_Message("Sys_ConPostEvents\n"); +//Con_Message("Sys_ConPostEvents\n"); if(ptr->EventType != KEY_EVENT) continue; key = &ptr->Event.KeyEvent; @@ -129,9 +129,10 @@ Con_Message("Sys_ConPostEvents\n"); ev.data1 = DDKEY_DOWNARROW; else ev.data1 = DD_ScanToKey(key->wVirtualScanCode); - ev.useclass = -1; + ev.noclass = true; + ev.useclass = 0; // initialize with something DD_PostEvent(&ev); -Con_Message("Sys_ConPostEvents: Done\n"); +//Con_Message("Sys_ConPostEvents: Done\n"); } } @@ -144,7 +145,7 @@ void Sys_ConSetCursor(int x, int y) SetConsoleCursorPosition(hcScreen, pos); } -void Sys_ConScrollLine() +void Sys_ConScrollLine(void) { SMALL_RECT src; COORD dest; @@ -270,7 +271,7 @@ void Sys_ConUpdateCmdLine(char *text) line[0].Char.AsciiChar = '>'; line[0].Attributes = CMDLINE_ATTRIB; - for(i = 0, ch = line + 1; i < LINELEN - 1; i++, ch++) + for(i = 0, ch = line + 1; i < LINELEN - 1; ++i, ch++) { if(i < strlen(text)) ch->Char.AsciiChar = text[i]; diff --git a/doomsday/plugins/common/include/g_controls.h b/doomsday/plugins/common/include/g_controls.h index a1963f6f7d..5e031fbe27 100644 --- a/doomsday/plugins/common/include/g_controls.h +++ b/doomsday/plugins/common/include/g_controls.h @@ -1,5 +1,10 @@ -/* DE1: $Id: cl_def.h 3323 2006-06-13 17:25:33Z skyjake $ - * Copyright (C) 2005 Jaakko Keränen +/**\file + *\section Copyright and License Summary + * License: GPL + * Online License Link: http://www.gnu.org/licenses/gpl.html + * + *\author Copyright © 2003-2006 Jaakko Keränen + *\author Copyright © 2005-2006 Daniel Swanson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -12,7 +17,9 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not: http://www.opensource.org/ + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA */ /* @@ -36,7 +43,7 @@ CTLCFG_TYPE SCControlConfig(int option, void *data); typedef struct { char *command; // The command to execute. int flags; - int bindClass; // Class it should be bound into + unsigned int bindClass; // Class it should be bound into int defKey; // int defMouse; // Zero means there is no default. int defJoy; // diff --git a/doomsday/plugins/common/src/g_controls.c b/doomsday/plugins/common/src/g_controls.c index fc84e44388..bc169b54b2 100644 --- a/doomsday/plugins/common/src/g_controls.c +++ b/doomsday/plugins/common/src/g_controls.c @@ -98,10 +98,10 @@ extern float turbomul; // multiplier for turbo bindclass_t BindClasses[] = { {"map", GBC_CLASS1, 0, 0}, {"mapfollowoff", GBC_CLASS2, 0, 0}, - {"menu", GBC_CLASS3, 0, 1}, + {"menu", GBC_CLASS3, 0, BCF_ABSOLUTE}, {"menuhotkey", GBC_MENUHOTKEY, 1, 0}, {"chat", GBC_CHAT, 0, 0}, - {"message", GBC_MESSAGE, 0, 1}, + {"message", GBC_MESSAGE, 0, BCF_ABSOLUTE}, {NULL} }; @@ -224,7 +224,7 @@ void G_DefaultBindings(void) // If this command is bound to something, skip it. sprintf(cmd, "%s%s", ctr->flags & CLF_ACTION ? "+" : "", ctr->command); memset(buff, 0, sizeof(buff)); - if(B_BindingsForCommand(cmd, buff, -1)) + if(B_BindingsForCommand(cmd, buff, 0, true)) continue; // This Control has no bindings, set it to the default. diff --git a/doomsday/plugins/common/src/m_ctrl.c b/doomsday/plugins/common/src/m_ctrl.c index 1f80b07323..91d5572f59 100644 --- a/doomsday/plugins/common/src/m_ctrl.c +++ b/doomsday/plugins/common/src/m_ctrl.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ @@ -130,7 +130,7 @@ void M_DrawControlsMenu(void) else strcpy(controlCmd, ctrl->command); // Let's gather all the bindings for this command in all bind classes. - if(!B_BindingsForCommand(controlCmd, buff, -1)) + if(!B_BindingsForCommand(controlCmd, buff, 0, true)) strcpy(buff, "NONE"); // Now we must interpret what the bindings string says. @@ -219,7 +219,7 @@ int D_PrivilegedResponder(event_t *event) memset(buff, 0, sizeof(buff)); // Check for bindings in this class only? - if(B_BindingsForCommand(cmd, buff, grabbing->bindClass)) + if(B_BindingsForCommand(cmd, buff, grabbing->bindClass, false)) if(findtoken(buff, evname, " ")) // Get rid of it? { del = true;