Skip to content

Commit

Permalink
Added public APIs for Client and Server
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 3, 2013
1 parent dd3cf5e commit 384c95c
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 116 deletions.
54 changes: 54 additions & 0 deletions doomsday/engine/api/api_client.h
@@ -0,0 +1,54 @@
#ifndef DOOMSDAY_API_CLIENT_H
#define DOOMSDAY_API_CLIENT_H

#include "apis.h"

struct mobj_s;

DENG_API_TYPEDEF(Client)
{
de_api_t api;

/**
* Searches through the client mobj hash table for the CURRENT map and
* returns the clmobj with the specified ID, if that exists. Note that
* client mobjs are also linked to the thinkers list.
*
* @param id Mobj identifier.
*
* @return Pointer to the mobj.
*/
struct mobj_s* (*Mobj_Find)(thid_t id);

/**
* Enables or disables local action function execution on the client.
*
* @param mo Client mobj.
* @param enable @c true to enable local actions, @c false to disable.
*/
void (*Mobj_EnableLocalActions)(struct mobj_s* mo, boolean enable);

/**
* Determines if local action functions are enabled for client mobj @a mo.
*/
boolean (*Mobj_LocalActionsEnabled)(struct mobj_s* mo);

boolean (*Mobj_IsValid)(struct mobj_s* mo);

struct mobj_s* (*Mobj_PlayerMobj)(int plrNum);
}
DENG_API_T(Client);

#ifndef DENG_NO_API_MACROS_CLIENT
#define ClMobj_Find _api_Client.Mobj_Find
#define ClMobj_EnableLocalActions _api_Client.Mobj_EnableLocalActions
#define ClMobj_LocalActionsEnabled _api_Client.Mobj_LocalActionsEnabled
#define ClMobj_IsValid _api_Client.Mobj_IsValid
#define ClPlayer_ClMobj _api_Client.Mobj_PlayerMobj
#endif

#ifdef __DOOMSDAY__
DENG_USING_API(Client);
#endif

#endif // DOOMSDAY_API_CLIENT_H
26 changes: 26 additions & 0 deletions doomsday/engine/api/api_server.h
@@ -0,0 +1,26 @@
#ifndef DOOMSDAY_API_SERVER_H
#define DOOMSDAY_API_SERVER_H

#include "apis.h"

DENG_API_TYPEDEF(Server)
{
de_api_t api;

/**
* Determines whether the coordinates sent by a player are valid at the
* moment.
*/
boolean (*CanTrustClientPos)(int player);
}
DENG_API_T(Server);

#ifndef DENG_NO_API_MACROS_SERVER
#define Sv_CanTrustClientPos _api_Server.CanTrustClientPos
#endif

#ifdef __DOOMSDAY__
DENG_USING_API(Server);
#endif

#endif // DOOMSDAY_API_SERVER_H
38 changes: 22 additions & 16 deletions doomsday/engine/api/apis.h
Expand Up @@ -33,52 +33,58 @@ enum {
DE_API_BUSY_v1 = 200, // 1.10
DE_API_BUSY_latest = DE_API_BUSY_v1,

DE_API_CONSOLE_v1 = 300, // 1.10
DE_API_CLIENT_v1 = 300, // 1.10
DE_API_CLIENT_latest = DE_API_CLIENT_v1,

DE_API_CONSOLE_v1 = 400, // 1.10
DE_API_CONSOLE_latest = DE_API_CONSOLE_v1,

DE_API_DEFINITIONS_v1 = 400, // 1.10
DE_API_DEFINITIONS_v1 = 500, // 1.10
DE_API_DEFINITIONS_latest = DE_API_DEFINITIONS_v1,

DE_API_DIRECT_DATA_ACCESS_v1 = 500, // 1.10
DE_API_DIRECT_DATA_ACCESS_v1 = 600, // 1.10
DE_API_DIRECT_DATA_ACCESS_latest = DE_API_DIRECT_DATA_ACCESS_v1,

DE_API_FILE_SYSTEM_v1 = 600, // 1.10
DE_API_FILE_SYSTEM_v1 = 700, // 1.10
DE_API_FILE_SYSTEM_latest = DE_API_FILE_SYSTEM_v1,

DE_API_FONT_RENDER_v1 = 700, // 1.10
DE_API_FONT_RENDER_v1 = 800, // 1.10
DE_API_FONT_RENDER_latest = DE_API_FONT_RENDER_v1,

DE_API_INFINE_v1 = 800, // 1.10
DE_API_INFINE_v1 = 900, // 1.10
DE_API_INFINE_latest = DE_API_INFINE_v1,

DE_API_MAP_v1 = 900, // 1.10
DE_API_MAP_v1 = 1000, // 1.10
DE_API_MAP_latest = DE_API_MAP_v1,

DE_API_MAP_EDIT_v1 = 1000, // 1.10
DE_API_MAP_EDIT_v1 = 1100, // 1.10
DE_API_MAP_EDIT_latest = DE_API_MAP_EDIT_v1,

DE_API_MATERIALS_v1 = 1100, // 1.10
DE_API_MATERIALS_v1 = 1200, // 1.10
DE_API_MATERIALS_latest = DE_API_MATERIALS_v1,

DE_API_PLAYER_v1 = 1200, // 1.10
DE_API_PLAYER_v1 = 1300, // 1.10
DE_API_PLAYER_latest = DE_API_PLAYER_v1,

DE_API_PLUGIN_v1 = 1300, // 1.10
DE_API_PLUGIN_v1 = 1400, // 1.10
DE_API_PLUGIN_latest = DE_API_PLUGIN_v1,

DE_API_SOUND_v1 = 1400, // 1.10
DE_API_SERVER_v1 = 1500, // 1.10
DE_API_SERVER_latest = DE_API_SERVER_v1,

DE_API_SOUND_v1 = 1600, // 1.10
DE_API_SOUND_latest = DE_API_SOUND_v1,

DE_API_SVG_v1 = 1500, // 1.10
DE_API_SVG_v1 = 1700, // 1.10
DE_API_SVG_latest = DE_API_SVG_v1,

DE_API_THINKER_v1 = 1600, // 1.10
DE_API_THINKER_v1 = 1800, // 1.10
DE_API_THINKER_latest = DE_API_THINKER_v1,

DE_API_URI_v1 = 1700, // 1.10
DE_API_URI_v1 = 1900, // 1.10
DE_API_URI_latest = DE_API_URI_v1,

DE_API_WAD_v1 = 1800, // 1.10
DE_API_WAD_v1 = 2000, // 1.10
DE_API_WAD_latest = DE_API_WAD_v1
};

Expand Down
46 changes: 2 additions & 44 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -96,6 +96,8 @@ struct font_s;
#include "api_sound.h"
#include "api_map.h"
#include "api_mapedit.h"
#include "api_client.h"
#include "api_server.h"

#include "filehandle.h"
#include <de/memoryzone.h>
Expand Down Expand Up @@ -143,46 +145,6 @@ extern "C" {
* Functionality provided by or related to the operating system.
*/

//------------------------------------------------------------------------
//
// Networking.
//
//------------------------------------------------------------------------

/// @addtogroup network
///@{

/**
* Determines whether the coordinates sent by a player are valid at the moment.
*/
boolean Sv_CanTrustClientPos(int player);

/**
* Searches through the client mobj hash table for the CURRENT map and
* returns the clmobj with the specified ID, if that exists. Note that
* client mobjs are also linked to the thinkers list.
*
* @param id Mobj identifier.
*
* @return Pointer to the mobj.
*/
struct mobj_s* ClMobj_Find(thid_t id);

/**
* Enables or disables local action function execution on the client.
*
* @param mo Client mobj.
* @param enable @c true to enable local actions, @c false to disable.
*/
void ClMobj_EnableLocalActions(struct mobj_s* mo, boolean enable);

/**
* Determines if local action functions are enabled for client mobj @a mo.
*/
boolean ClMobj_LocalActionsEnabled(struct mobj_s* mo);

///@}

//------------------------------------------------------------------------
//
// Playsim.
Expand Down Expand Up @@ -283,10 +245,6 @@ void Mobj_OriginSmoothed(struct mobj_s* mobj, coord_t origin[3]);

angle_t Mobj_AngleSmoothed(struct mobj_s* mobj);

boolean ClMobj_IsValid(struct mobj_s* mo);

struct mobj_s* ClPlayer_ClMobj(int plrNum);

// Mobj linked object iterators.
int P_MobjLinesIterator(struct mobj_s* mo, int (*callback) (struct linedef_s*, void*), void* parameters);

Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/engine.pro
Expand Up @@ -82,6 +82,7 @@ DENG_API_HEADERS = \
api/api_audiod_sfx.h \
api/api_base.h \
api/api_busy.h \
api/api_client.h \
api/api_console.h \
api/api_def.h \
api/api_event.h \
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/include/client/cl_mobj.h
Expand Up @@ -70,7 +70,6 @@ void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientM
mobj_t *ClMobj_Create(thid_t id);
void ClMobj_Destroy(mobj_t *mo);
clmoinfo_t *ClMobj_GetInfo(mobj_t* mo);
struct mobj_s *ClMobj_Find(thid_t id);
mobj_t *ClMobj_MobjForInfo(clmoinfo_t* info);
void ClMobj_Unlink(mobj_t *cmo); // needed?
void ClMobj_Link(mobj_t *cmo); // needed?
Expand All @@ -91,6 +90,5 @@ void ClMobj_ReadDelta2(boolean skip);
void ClMobj_ReadNullDelta2(boolean skip);

boolean Cl_IsClientMobj(mobj_t* mo); // public
boolean ClMobj_IsValid(mobj_t* mo); // public

#endif
1 change: 0 additions & 1 deletion doomsday/engine/include/client/cl_player.h
Expand Up @@ -80,7 +80,6 @@ void ClPlayer_ApplyPendingFixes(int plrNum);
void ClPlayer_ReadDelta2(boolean skip);
clplayerstate_t *ClPlayer_State(int plrNum);
mobj_t *ClPlayer_LocalGameMobj(int plrNum);
struct mobj_s *ClPlayer_ClMobj(int plrNum);
boolean ClPlayer_IsFreeToMove(int plrnum);

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/include/de_network.h
Expand Up @@ -36,6 +36,7 @@
#include "network/protocol.h"
#ifdef __CLIENT__
# include "network/net_demo.h"
# include "api_client.h"
#endif

#include "server/sv_def.h"
Expand Down
50 changes: 0 additions & 50 deletions doomsday/engine/include/network/net_main.h
Expand Up @@ -148,49 +148,15 @@ typedef struct {
// ID number. Each client has a unique ID number.
ident_t id;

// Ticcmd buffer. The server uses this when clients send it ticcmds.
//byte *ticCmds;

// Number of tics in the buffer.
//int numTics;

// Index of the first tic in the buffer.
//int firstTic;

/*
// Last command executed, reused if a new one isn't found.
ticcmd_t *lastCmd;
// Clients merge several ticcmds into this one, which is them sent
// periodically to the server.
ticcmd_t *aggregateCmd;
*/

int lastTransmit;

// If >0, the server will send the next world frame to the client.
// This is set when input is received from the client.
//int updateCount;

// Seconds when the client entered the game (Sys_GetRealSeconds()).
double enterTime;

// Client-reported time of the last processed ticcmd.
// Older or as old tics than this are discarded.
//int runTime;

// Bandwidth rating for connection. Determines how much information
// can be sent to the client. Determined dynamically.
int bandwidthRating;

// During the adjust period, raising the BWR is allowed (hitting max
// frame size).
//int bwrAdjustTime;

// A record of the past few acknowledgement times.
//uint ackTimes[NUM_ACK_TIMES];
//int ackIdx;

// Clients use this to determine how long ago they received the
// last update of this client.
int age;
Expand Down Expand Up @@ -235,22 +201,6 @@ typedef struct {
int viewConsole;
} client_t;

/*
// Packets.
typedef struct {
byte version;
unsigned short playerMask; // 16 players.
byte yourConsole; // Which one's you?
int gameTime;
} handshake_packet_t;
*/
/*
typedef struct {
byte console;
char name[PLAYERNAMELEN];
} playerinfo_packet_t;
*/

extern boolean firstNetUpdate;
extern int resendStart; // set when server needs our tics
extern int resendCount;
Expand Down
15 changes: 15 additions & 0 deletions doomsday/engine/src/client/cl_mobj.c
Expand Up @@ -22,6 +22,8 @@

#include <math.h>

#define DENG_NO_API_MACROS_CLIENT

#include "de_base.h"
#include "de_defs.h"
#include "de_system.h"
Expand Down Expand Up @@ -1071,3 +1073,16 @@ void ClMobj_ReadNullDelta2(boolean skip)
checkMobjHash();
#endif
}

// cl_player.c
DENG_EXTERN_C struct mobj_s* ClPlayer_ClMobj(int plrNum);

DENG_DECLARE_API(Client) =
{
{ DE_API_CLIENT_latest },
ClMobj_Find,
ClMobj_EnableLocalActions,
ClMobj_LocalActionsEnabled,
ClMobj_IsValid,
ClPlayer_ClMobj
};
1 change: 1 addition & 0 deletions doomsday/engine/src/client/cl_player.c
Expand Up @@ -108,6 +108,7 @@ void Cl_Thrust(mobj_t *mo, angle_t angle, float move)
*
* @return The engineside client mobj of a player, representing a remote mobj on the server.
*/
#undef ClPlayer_ClMobj
struct mobj_s* ClPlayer_ClMobj(int plrNum)
{
assert(plrNum >= 0 && plrNum < DDMAXPLAYERS);
Expand Down
12 changes: 12 additions & 0 deletions doomsday/engine/src/library.cpp
Expand Up @@ -37,6 +37,12 @@
#include "api_sound.h"
#include "api_fontrender.h"
#include "api_svg.h"
#ifdef __CLIENT__
# include "api_client.h"
#endif
#ifdef __SERVER__
# include "api_server.h"
#endif

struct library_s { // typedef Library
Str* path; ///< de::FS path of the library (e.g., "/bin/doom.dll").
Expand Down Expand Up @@ -196,9 +202,15 @@ void Library_PublishAPIs(Library *lib)

#ifdef __CLIENT__
// Client-only APIs.
PUBLISH(_api_Client);
PUBLISH(_api_FR);
PUBLISH(_api_Svg);
#endif

#ifdef __SERVER__
// Server-only APIs.
PUBLISH(_api_Server);
#endif
}
}

Expand Down

0 comments on commit 384c95c

Please sign in to comment.