Nuclide
Software Development Kit for id Technology (BETA)
Loading...
Searching...
No Matches
API: Client-side

Client-side Game-Logic APIs. More...

Detailed Description

Client-side Game-Logic APIs.

APIs used by HudC progs and the client progs exclusively.

HudC

By default, a HudC progs is loaded from <gamedir>/hud.dat.

If it is present, it is the chosen default. If it doesn't exist, Nuclide will not display a Heads-Up-Display. The game-specific code (non-Nuclide) can also choose to draw its own HUD by providing implementations of the following functions:

void HUD_Init(void);
void HUD_Draw(void);
void HUD_DrawSpectator(void);
void HUD_SendStat(string statName, string statValue);
float HUD_ClientInputFrame(float inputButtons);
bool HUD_ConsoleCommand(string fullCommandString);
void HUD_WeaponSwitched(string weaponName);

This will force that HUD, if implemented within the game's csprogs.dat.

Example HudC Progs Code

From base/src/client/hud.qc

#pragma PROGS_DAT "../../hud.dat"
#include "../../../src/client/api.h"
const float baseIconSize = 32.0;
const float baseIconPadding = 16.0;
font_s FONT_HUD;
var string g_ammoPic;
void
HUD_Init(void)
{
font.Load("fonts/font16.font", FONT_HUD);
g_ammoPic = 0;
}
void
HUD_Draw(void)
{
vector hud_mins = screen.HUDMins();
vector hud_size = screen.HUDSize();
vector hudSize = hud_size;
vector iconPos = hud_mins + (hudSize / 2);
iconPos[1] = (hudSize[1] - baseIconSize) - baseIconPadding;
string healthValue = ftos(player.GetHealth());
string armorValue = ftos(player.GetArmor());
string ammoValue = ftos(weapon.GetAmmo1());
if (weapon.AmmoRequired() == true) {
draw.RText([hudSize[0] - baseIconPadding - baseIconSize - baseIconPadding, iconPos[1]], ammoValue, FONT_HUD);
}
if (g_ammoPic != "") {
draw.Pic([hudSize[0] - baseIconPadding - baseIconSize, iconPos[1]], g_ammoPic, [baseIconSize, baseIconSize], [1,1,1], 1.0f);
}
draw.RText(iconPos + [-((baseIconSize/2) + (baseIconPadding/2)) - baseIconPadding, 0], healthValue, FONT_HUD);
draw.Pic(iconPos + [-((baseIconSize/2) + (baseIconPadding/2)), 0], "gfx/hud/health", [baseIconSize, baseIconSize], [1,1,1], 1.0f);
draw.Text(iconPos + [(baseIconSize/2) + (baseIconPadding/2) + baseIconSize + baseIconPadding, 0], armorValue, FONT_HUD);
draw.Pic(iconPos + [(baseIconSize/2) + (baseIconPadding/2), 0], "gfx/hud/armor", [baseIconSize, baseIconSize], [1,1,1], 1.0f);
}
void
HUD_WeaponSwitched(string weaponName)
{
g_ammoPic = entityDef.GetString(weaponName, "ammoIcon");
}
var surfaceAPI_t screen
Access surfaceAPI_t functions using this variable.
Definition api_func.h:201
var fontAPI_t font
Access fontAPI_t functions using this variable.
Definition api_func.h:188
var weaponAPI_t weapon
Access weaponAPI_t functions using this variable.
Definition api_func.h:515
var drawAPI_t draw
Access drawAPI_t functions using this variable.
Definition api_func.h:325
var playerAPI_t player
Access playerAPI_t functions using this variable.
Definition api_func.h:421
entityDefAPI_t entityDef
Access entityDefAPI_t functions using this variable.
Definition api.h:437
Representation of a font.
Definition api_func.h:39

As you can see, you'll be primarily using functions from the drawAPI in order to display text and images on screen. You also can load external font definitions and query the display properties using the fontAPI and screenAPI

Classes

struct  fontAPI_t
 Font library. More...
 
struct  surfaceAPI_t
 Surface library. More...
 
struct  drawAPI_t
 Draw library. More...
 
struct  playerAPI_t
 Player library. More...
 
struct  weaponAPI_t
 Weapon library. More...
 
struct  spectatingAPI_t
 Spectating library. More...
 
struct  atlasPicAPI_t
 atlasPic library More...
 
struct  materialAPI_t
 material library More...
 

Variables

var fontAPI_t font
 Access fontAPI_t functions using this variable.
 
var surfaceAPI_t screen
 Access surfaceAPI_t functions using this variable.
 
var drawAPI_t draw
 Access drawAPI_t functions using this variable.
 
var playerAPI_t player
 Access playerAPI_t functions using this variable.
 
var weaponAPI_t weapon
 Access weaponAPI_t functions using this variable.
 
var spectatingAPI_t spectating
 Access spectatingAPI_t functions using this variable.
 
var atlasPicAPI_t atlasPic
 Access atlasPicAPI_t functions using this variable.
 
var materialAPI_t material
 Access atlasPicAPI_t functions using this variable.
 

Variable Documentation

◆ atlasPic

var atlasPicAPI_t atlasPic

Access atlasPicAPI_t functions using this variable.

◆ draw

var drawAPI_t draw

Access drawAPI_t functions using this variable.

◆ font

var fontAPI_t font

Access fontAPI_t functions using this variable.

◆ material

var materialAPI_t material

Access atlasPicAPI_t functions using this variable.

◆ player

var playerAPI_t player

Access playerAPI_t functions using this variable.

◆ screen

var surfaceAPI_t screen

Access surfaceAPI_t functions using this variable.

◆ spectating

var spectatingAPI_t spectating

Access spectatingAPI_t functions using this variable.

◆ weapon

var weaponAPI_t weapon

Access weaponAPI_t functions using this variable.