cg_main.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. #include "cg_local.h"
  4. #include "m_flash.h"
  5. cgame_import_t cgi;
  6. cgame_export_t cglobals;
  7. static void *CG_GetExtension(const char *name)
  8. {
  9. return nullptr;
  10. }
  11. void CG_InitScreen();
  12. uint64_t cgame_init_time = 0;
  13. static void InitCGame()
  14. {
  15. CG_InitScreen();
  16. cgame_init_time = cgi.CL_ClientRealTime();
  17. pm_config.n64_physics = !!atoi(cgi.get_configstring(CONFIG_N64_PHYSICS));
  18. pm_config.airaccel = atoi(cgi.get_configstring(CS_AIRACCEL));
  19. }
  20. static void ShutdownCGame()
  21. {
  22. }
  23. void CG_DrawHUD (int32_t isplit, const cg_server_data_t *data, vrect_t hud_vrect, vrect_t hud_safe, int32_t scale, int32_t playernum, const player_state_t *ps);
  24. void CG_TouchPics();
  25. layout_flags_t CG_LayoutFlags(const player_state_t *ps);
  26. int32_t CG_GetActiveWeaponWheelWeapon(const player_state_t *ps)
  27. {
  28. return ps->stats[STAT_ACTIVE_WHEEL_WEAPON];
  29. }
  30. uint32_t CG_GetOwnedWeaponWheelWeapons(const player_state_t *ps)
  31. {
  32. return ((uint32_t) (uint16_t) ps->stats[STAT_WEAPONS_OWNED_1]) | ((uint32_t) (uint16_t) (ps->stats[STAT_WEAPONS_OWNED_2]) << 16);
  33. }
  34. int16_t CG_GetWeaponWheelAmmoCount(const player_state_t *ps, int32_t ammo_id)
  35. {
  36. uint16_t ammo = G_GetAmmoStat((uint16_t *) &ps->stats[STAT_AMMO_INFO_START], ammo_id);
  37. if (ammo == AMMO_VALUE_INFINITE)
  38. return -1;
  39. return ammo;
  40. }
  41. int16_t CG_GetPowerupWheelCount(const player_state_t *ps, int32_t powerup_id)
  42. {
  43. return G_GetPowerupStat((uint16_t *) &ps->stats[STAT_POWERUP_INFO_START], powerup_id);
  44. }
  45. int16_t CG_GetHitMarkerDamage(const player_state_t *ps)
  46. {
  47. return ps->stats[STAT_HIT_MARKER];
  48. }
  49. static void CG_ParseConfigString(int32_t i, const char *s)
  50. {
  51. if (i == CONFIG_N64_PHYSICS)
  52. pm_config.n64_physics = !!atoi(s);
  53. else if (i == CS_AIRACCEL)
  54. pm_config.airaccel = atoi(s);
  55. }
  56. void CG_ParseCenterPrint (const char *str, int isplit, bool instant);
  57. void CG_ClearNotify(int32_t isplit);
  58. void CG_ClearCenterprint(int32_t isplit);
  59. void CG_NotifyMessage(int32_t isplit, const char *msg, bool is_chat);
  60. void CG_GetMonsterFlashOffset(monster_muzzleflash_id_t id, gvec3_ref_t offset)
  61. {
  62. if (id >= q_countof(monster_flash_offset))
  63. cgi.Com_Error("Bad muzzle flash offset");
  64. offset = monster_flash_offset[id];
  65. }
  66. /*
  67. =================
  68. GetCGameAPI
  69. Returns a pointer to the structure with all entry points
  70. and global variables
  71. =================
  72. */
  73. Q2GAME_API cgame_export_t *GetCGameAPI(cgame_import_t *import)
  74. {
  75. cgi = *import;
  76. cglobals.apiversion = CGAME_API_VERSION;
  77. cglobals.Init = InitCGame;
  78. cglobals.Shutdown = ShutdownCGame;
  79. cglobals.Pmove = Pmove;
  80. cglobals.DrawHUD = CG_DrawHUD;
  81. cglobals.LayoutFlags = CG_LayoutFlags;
  82. cglobals.TouchPics = CG_TouchPics;
  83. cglobals.GetActiveWeaponWheelWeapon = CG_GetActiveWeaponWheelWeapon;
  84. cglobals.GetOwnedWeaponWheelWeapons = CG_GetOwnedWeaponWheelWeapons;
  85. cglobals.GetWeaponWheelAmmoCount = CG_GetWeaponWheelAmmoCount;
  86. cglobals.GetPowerupWheelCount = CG_GetPowerupWheelCount;
  87. cglobals.GetHitMarkerDamage = CG_GetHitMarkerDamage;
  88. cglobals.ParseConfigString = CG_ParseConfigString;
  89. cglobals.ParseCenterPrint = CG_ParseCenterPrint;
  90. cglobals.ClearNotify = CG_ClearNotify;
  91. cglobals.ClearCenterprint = CG_ClearCenterprint;
  92. cglobals.NotifyMessage = CG_NotifyMessage;
  93. cglobals.GetMonsterFlashOffset = CG_GetMonsterFlashOffset;
  94. cglobals.GetExtension = CG_GetExtension;
  95. return &cglobals;
  96. }