Skip to content

Commit

Permalink
Moved public Net_* routines to Base and Player APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 3, 2013
1 parent fbdbe00 commit dd3cf5e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 33 deletions.
16 changes: 14 additions & 2 deletions doomsday/engine/api/api_base.h
Expand Up @@ -127,7 +127,7 @@ DENG_API_TYPEDEF(Base) // v1
*
* @return @c true if successful else @c false (i.e., no game loaded).
*/
boolean (*_GameInfo)(GameInfo* info);
boolean (*gameInfo)(GameInfo* info);

/**
* Determines whether the current run of the thinkers should be considered a
Expand All @@ -141,6 +141,17 @@ DENG_API_TYPEDEF(Base) // v1
* @ingroup playsim
*/
boolean (*IsSharpTick)(void);

/**
* Send a packet over the network.
*
* @param to_player Player number to send to. The server is number zero.
* May include @ref netSendFlags.
* @param type Type of the packet.
* @param data Data of the packet.
* @param length Length of the data.
*/
void (*SendPacket)(int to_player, int type, const void* data, size_t length);
}
DENG_API_T(Base);

Expand All @@ -153,8 +164,9 @@ DENG_API_T(Base);
#define DD_DefineGame _api_Base.DefineGame
#define DD_GameIdForKey _api_Base.GameIdForKey
#define DD_AddGameResource _api_Base.AddGameResource
#define DD_GameInfo _api_Base._GameInfo
#define DD_GameInfo _api_Base.gameInfo
#define DD_IsSharpTick _api_Base.IsSharpTick
#define Net_SendPacket _api_Base.SendPacket
#endif

#ifdef __DOOMSDAY__
Expand Down
19 changes: 19 additions & 0 deletions doomsday/engine/api/api_player.h
Expand Up @@ -2,6 +2,7 @@
#define DOOMSDAY_API_PLAYER_H

#include "apis.h"
#include <de/smoother.h>

/**
* @defgroup player Player
Expand Down Expand Up @@ -124,6 +125,21 @@ DENG_API_TYPEDEF(Player)
{
de_api_t api;

/**
* @return The name of player @a player.
*/
const char* (*GetPlayerName)(int player);

/**
* @return Client identifier for player @a player.
*/
ident_t (*GetPlayerID)(int player);

/**
* Provides access to the player's movement smoother.
*/
Smoother* (*GetSmoother)(int player);

/**
* Gets the data of a player.
*
Expand All @@ -144,6 +160,9 @@ DENG_API_TYPEDEF(Player)
DENG_API_T(Player);

#ifndef DENG_NO_API_MACROS_PLAYER
#define Net_GetPlayerName _api_Player.GetPlayerName
#define Net_GetPlayerID _api_Player.GetPlayerID
#define Net_PlayerSmoother _api_Player.GetSmoother
#define DD_GetPlayer _api_Player.GetPlayer
#define P_NewPlayerControl _api_Player.NewControl
#define P_GetControlState _api_Player.GetControlState
Expand Down
26 changes: 0 additions & 26 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -152,32 +152,6 @@ extern "C" {
/// @addtogroup network
///@{

/**
* Send a packet over the network.
*
* @param to_player Player number to send to. The server is number zero.
* May include @ref netSendFlags.
* @param type Type of the packet.
* @param data Data of the packet.
* @param length Length of the data.
*/
void Net_SendPacket(int to_player, int type, const void* data, size_t length);

/**
* @return The name of player @a player.
*/
const char* Net_GetPlayerName(int player);

/**
* @return Client identifier for player @a player.
*/
ident_t Net_GetPlayerID(int player);

/**
* Provides access to the player's movement smoother.
*/
Smoother* Net_PlayerSmoother(int player);

/**
* Determines whether the coordinates sent by a player are valid at the moment.
*/
Expand Down
4 changes: 0 additions & 4 deletions doomsday/engine/include/network/net_main.h
Expand Up @@ -271,7 +271,6 @@ void Net_Init(void);
void Net_Shutdown(void);
void Net_DestroyArrays(void);
void Net_AllocClientBuffers(int clientId);
void Net_SendPacket(int to_player, int type, const void *data, size_t length);
boolean Net_GetPacket(void);
void Net_SendBuffer(int to_player, int sp_flags);
void Net_SendPlayerInfo(int srcPlrNum, int destPlrNum);
Expand All @@ -295,9 +294,6 @@ void Net_SetAckTime(int clientNumber, uint period);
uint Net_GetAckTime(int clientNumber);
uint Net_GetAckThreshold(int clientNumber);

const char* Net_GetPlayerName(int player);
ident_t Net_GetPlayerID(int player);

void Net_PrintServerInfo(int index, serverinfo_t *info);

#ifdef __cplusplus
Expand Down
6 changes: 5 additions & 1 deletion doomsday/engine/src/dd_main.cpp
Expand Up @@ -2916,6 +2916,9 @@ D_CMD(ReloadGame)
// dd_loop.c
DENG_EXTERN_C boolean DD_IsSharpTick(void);

// net_main.c
DENG_EXTERN_C void Net_SendPacket(int to_player, int type, const void* data, size_t length);

// sys_system.c
DENG_EXTERN_C void Sys_Quit(void);

Expand All @@ -2932,5 +2935,6 @@ DENG_DECLARE_API(Base) =
DD_GameIdForKey,
DD_AddGameResource,
DD_GameInfo,
DD_IsSharpTick
DD_IsSharpTick,
Net_SendPacket
};
8 changes: 8 additions & 0 deletions doomsday/engine/src/map/p_players.c
Expand Up @@ -211,6 +211,11 @@ ddplayer_t* DD_GetPlayer(int number)
return (ddplayer_t *) &ddPlayers[number].shared;
}

// net_main.c
const char* Net_GetPlayerName(int player);
ident_t Net_GetPlayerID(int player);
Smoother* Net_PlayerSmoother(int player);

// p_control.c
DENG_EXTERN_C void P_NewPlayerControl(int id, controltype_t type, const char *name, const char* bindContext);
DENG_EXTERN_C void P_GetControlState(int playerNum, int control, float* pos, float* relativeOffset);
Expand All @@ -220,6 +225,9 @@ DENG_EXTERN_C void P_Impulse(int playerNum, int control);
DENG_DECLARE_API(Player) =
{
{ DE_API_PLAYER_latest },
Net_GetPlayerName,
Net_GetPlayerID,
Net_PlayerSmoother,
DD_GetPlayer,
P_NewPlayerControl,
P_GetControlState,
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/src/network/net_main.c
Expand Up @@ -201,11 +201,13 @@ void Net_Shutdown(void)
Net_DestroyArrays();
}

#undef Net_GetPlayerName
const char* Net_GetPlayerName(int player)
{
return clients[player].name;
}

#undef Net_GetPlayerID
ident_t Net_GetPlayerID(int player)
{
if(!clients[player].connected)
Expand Down Expand Up @@ -289,6 +291,7 @@ boolean Net_GetPacket(void)
return true;
}

#undef Net_PlayerSmoother
Smoother* Net_PlayerSmoother(int player)
{
if(player < 0 || player >= DDMAXPLAYERS)
Expand Down Expand Up @@ -320,6 +323,7 @@ void Net_SendPlayerInfo(int srcPlrNum, int destPlrNum)
/**
* This is the public interface of the message sender.
*/
#undef Net_SendPacket
void Net_SendPacket(int to_player, int type, const void* data, size_t length)
{
unsigned int flags = 0;
Expand Down

0 comments on commit dd3cf5e

Please sign in to comment.