From 384c95c4e5b2c415db76efe67655b6b4c71ed55a Mon Sep 17 00:00:00 2001 From: skyjake Date: Thu, 3 Jan 2013 22:07:51 +0200 Subject: [PATCH] Added public APIs for Client and Server --- doomsday/engine/api/api_client.h | 54 ++++++++++++++++++++++ doomsday/engine/api/api_server.h | 26 +++++++++++ doomsday/engine/api/apis.h | 38 ++++++++------- doomsday/engine/api/doomsday.h | 46 +----------------- doomsday/engine/engine.pro | 1 + doomsday/engine/include/client/cl_mobj.h | 2 - doomsday/engine/include/client/cl_player.h | 1 - doomsday/engine/include/de_network.h | 1 + doomsday/engine/include/network/net_main.h | 50 -------------------- doomsday/engine/src/client/cl_mobj.c | 15 ++++++ doomsday/engine/src/client/cl_player.c | 1 + doomsday/engine/src/library.cpp | 12 +++++ doomsday/engine/src/map/p_players.c | 6 +-- doomsday/engine/src/server/sv_main.c | 9 ++++ doomsday/plugins/jdoom/include/d_api.h | 2 + doomsday/plugins/jdoom/src/d_api.c | 4 ++ doomsday/server/include/server_dummies.h | 2 + doomsday/server/server.pro | 1 + doomsday/server/src/server_dummies.c | 2 + 19 files changed, 157 insertions(+), 116 deletions(-) create mode 100644 doomsday/engine/api/api_client.h create mode 100644 doomsday/engine/api/api_server.h diff --git a/doomsday/engine/api/api_client.h b/doomsday/engine/api/api_client.h new file mode 100644 index 0000000000..0255b30b43 --- /dev/null +++ b/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 diff --git a/doomsday/engine/api/api_server.h b/doomsday/engine/api/api_server.h new file mode 100644 index 0000000000..354dc463ad --- /dev/null +++ b/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 diff --git a/doomsday/engine/api/apis.h b/doomsday/engine/api/apis.h index aa68b03807..47275ce09d 100644 --- a/doomsday/engine/api/apis.h +++ b/doomsday/engine/api/apis.h @@ -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 }; diff --git a/doomsday/engine/api/doomsday.h b/doomsday/engine/api/doomsday.h index 505b9d66d0..7f0afd1024 100644 --- a/doomsday/engine/api/doomsday.h +++ b/doomsday/engine/api/doomsday.h @@ -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 @@ -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. @@ -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); diff --git a/doomsday/engine/engine.pro b/doomsday/engine/engine.pro index 300a24d992..09de23455b 100644 --- a/doomsday/engine/engine.pro +++ b/doomsday/engine/engine.pro @@ -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 \ diff --git a/doomsday/engine/include/client/cl_mobj.h b/doomsday/engine/include/client/cl_mobj.h index 121cdcbbcb..99bf7bb14b 100644 --- a/doomsday/engine/include/client/cl_mobj.h +++ b/doomsday/engine/include/client/cl_mobj.h @@ -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? @@ -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 diff --git a/doomsday/engine/include/client/cl_player.h b/doomsday/engine/include/client/cl_player.h index b57d18a275..38dc4b142a 100644 --- a/doomsday/engine/include/client/cl_player.h +++ b/doomsday/engine/include/client/cl_player.h @@ -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 diff --git a/doomsday/engine/include/de_network.h b/doomsday/engine/include/de_network.h index cac411b708..8b623dc147 100644 --- a/doomsday/engine/include/de_network.h +++ b/doomsday/engine/include/de_network.h @@ -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" diff --git a/doomsday/engine/include/network/net_main.h b/doomsday/engine/include/network/net_main.h index db4ab5decc..7f02ed7da4 100644 --- a/doomsday/engine/include/network/net_main.h +++ b/doomsday/engine/include/network/net_main.h @@ -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; @@ -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; diff --git a/doomsday/engine/src/client/cl_mobj.c b/doomsday/engine/src/client/cl_mobj.c index c85c47d205..4806ef91f9 100644 --- a/doomsday/engine/src/client/cl_mobj.c +++ b/doomsday/engine/src/client/cl_mobj.c @@ -22,6 +22,8 @@ #include +#define DENG_NO_API_MACROS_CLIENT + #include "de_base.h" #include "de_defs.h" #include "de_system.h" @@ -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 +}; diff --git a/doomsday/engine/src/client/cl_player.c b/doomsday/engine/src/client/cl_player.c index 623a0a573d..8b78b8e9cd 100644 --- a/doomsday/engine/src/client/cl_player.c +++ b/doomsday/engine/src/client/cl_player.c @@ -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); diff --git a/doomsday/engine/src/library.cpp b/doomsday/engine/src/library.cpp index 185d41e80e..583f7017a6 100644 --- a/doomsday/engine/src/library.cpp +++ b/doomsday/engine/src/library.cpp @@ -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"). @@ -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 } } diff --git a/doomsday/engine/src/map/p_players.c b/doomsday/engine/src/map/p_players.c index 9b44adacb2..d03f951406 100644 --- a/doomsday/engine/src/map/p_players.c +++ b/doomsday/engine/src/map/p_players.c @@ -212,9 +212,9 @@ ddplayer_t* DD_GetPlayer(int number) } // net_main.c -const char* Net_GetPlayerName(int player); -ident_t Net_GetPlayerID(int player); -Smoother* Net_PlayerSmoother(int player); +DENG_EXTERN_C const char* Net_GetPlayerName(int player); +DENG_EXTERN_C ident_t Net_GetPlayerID(int player); +DENG_EXTERN_C 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); diff --git a/doomsday/engine/src/server/sv_main.c b/doomsday/engine/src/server/sv_main.c index 20ea5e7588..5c843e98d2 100644 --- a/doomsday/engine/src/server/sv_main.c +++ b/doomsday/engine/src/server/sv_main.c @@ -30,6 +30,9 @@ #include +#define DENG_NO_API_MACROS_SERVER +#include "api_server.h" + #include "de_base.h" #include "de_console.h" #include "de_system.h" @@ -1288,3 +1291,9 @@ D_CMD(Logout) netRemoteUser = 0; return true; } + +DENG_DECLARE_API(Server) = +{ + { DE_API_SERVER_latest }, + Sv_CanTrustClientPos +}; diff --git a/doomsday/plugins/jdoom/include/d_api.h b/doomsday/plugins/jdoom/include/d_api.h index d54ef56d64..e920212e6c 100644 --- a/doomsday/plugins/jdoom/include/d_api.h +++ b/doomsday/plugins/jdoom/include/d_api.h @@ -46,6 +46,7 @@ extern game_export_t gx; DENG_USING_API(Base); DENG_USING_API(B); DENG_USING_API(Busy); +DENG_USING_API(Client); DENG_USING_API(Con); DENG_USING_API(Def); DENG_USING_API(F); @@ -57,6 +58,7 @@ DENG_USING_API(MPE); DENG_USING_API(Player); DENG_USING_API(Plug); DENG_USING_API(S); +DENG_USING_API(Server); DENG_USING_API(Svg); DENG_USING_API(Thinker); DENG_USING_API(Uri); diff --git a/doomsday/plugins/jdoom/src/d_api.c b/doomsday/plugins/jdoom/src/d_api.c index 0c6f5011b6..1c1b369e00 100644 --- a/doomsday/plugins/jdoom/src/d_api.c +++ b/doomsday/plugins/jdoom/src/d_api.c @@ -282,6 +282,7 @@ const char* deng_LibraryType(void) DENG_DECLARE_API(Base); DENG_DECLARE_API(B); DENG_DECLARE_API(Busy); +DENG_DECLARE_API(Client); DENG_DECLARE_API(Con); DENG_DECLARE_API(Def); DENG_DECLARE_API(F); @@ -293,6 +294,7 @@ DENG_DECLARE_API(MPE); DENG_DECLARE_API(Player); DENG_DECLARE_API(Plug); DENG_DECLARE_API(S); +DENG_DECLARE_API(Server); DENG_DECLARE_API(Svg); DENG_DECLARE_API(Thinker); DENG_DECLARE_API(Uri); @@ -302,6 +304,7 @@ DENG_API_EXCHANGE( DENG_GET_API(DE_API_BASE_latest, Base); DENG_GET_API(DE_API_BINDING_latest, B); DENG_GET_API(DE_API_BUSY_latest, Busy); + DENG_GET_API(DE_API_CLIENT_latest, Client); DENG_GET_API(DE_API_CONSOLE_latest, Con); DENG_GET_API(DE_API_DEFINITIONS_latest, Def); DENG_GET_API(DE_API_FILE_SYSTEM_latest, F); @@ -313,6 +316,7 @@ DENG_API_EXCHANGE( DENG_GET_API(DE_API_PLAYER_latest, Player); DENG_GET_API(DE_API_PLUGIN_latest, Plug); DENG_GET_API(DE_API_SOUND_latest, S); + DENG_GET_API(DE_API_SERVER_latest, Server); DENG_GET_API(DE_API_SVG_latest, Svg); DENG_GET_API(DE_API_THINKER_latest, Thinker); DENG_GET_API(DE_API_URI_latest, Uri); diff --git a/doomsday/server/include/server_dummies.h b/doomsday/server/include/server_dummies.h index 54a5caa097..1cf72bf5d2 100644 --- a/doomsday/server/include/server_dummies.h +++ b/doomsday/server/include/server_dummies.h @@ -37,11 +37,13 @@ # error "Attempted to include server's header in a non-server build" #endif +/* DENG_EXTERN_C void ClMobj_EnableLocalActions(struct mobj_s *mo, boolean enable); DENG_EXTERN_C boolean ClMobj_LocalActionsEnabled(struct mobj_s *mo); DENG_EXTERN_C struct mobj_s* ClMobj_Find(thid_t id); DENG_EXTERN_C boolean ClMobj_IsValid(struct mobj_s* mo); DENG_EXTERN_C struct mobj_s* ClPlayer_ClMobj(int plrNum); +*/ DENG_EXTERN_C void GameMap_ClMobjReset(GameMap* map); diff --git a/doomsday/server/server.pro b/doomsday/server/server.pro index f1a9063af1..ac557575d6 100644 --- a/doomsday/server/server.pro +++ b/doomsday/server/server.pro @@ -87,6 +87,7 @@ DENG_API_HEADERS = \ $$SRC/api/api_mapedit.h \ $$SRC/api/api_player.h \ $$SRC/api/api_plugin.h \ + $$SRC/api/api_server.h \ $$SRC/api/api_sound.h \ $$SRC/api/api_svg.h \ $$SRC/api/api_thinker.h \ diff --git a/doomsday/server/src/server_dummies.c b/doomsday/server/src/server_dummies.c index 78d342c3d7..8169efaf4f 100644 --- a/doomsday/server/src/server_dummies.c +++ b/doomsday/server/src/server_dummies.c @@ -30,6 +30,7 @@ void DD_ReadMouse(void) void DD_ReadJoystick(void) {} +/* void ClMobj_EnableLocalActions(struct mobj_s *mo, boolean enable) { // No clmobjs on server. @@ -61,6 +62,7 @@ struct mobj_s* ClPlayer_ClMobj(int plrNum) DENG_UNUSED(plrNum); return 0; } +*/ void GameMap_ClMobjReset(GameMap* map) {