Skip to content

Commit

Permalink
Fix QCVM bug, add worldtext scale, localcmd buttons, and vrstart map …
Browse files Browse the repository at this point in the history
…as default
  • Loading branch information
vittorioromeo committed Oct 12, 2023
1 parent dd16d27 commit fbcf673
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 33 deletions.
1 change: 1 addition & 0 deletions QC/builtins.qc
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ float(float v) sqrt = #108;

float(float x, float y) atan2 = #109;

void(float h, float v) worldtext_hsetscale = #110;
15 changes: 15 additions & 0 deletions QC/buttons.qc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ void() button_fire =
{
bprint("Congratulations! You have hands.\n");
}
else if(self.buttonEffect == 3) // Command button
{
localcmd(self.targetname);
}
};

void() button_use =
Expand Down Expand Up @@ -209,6 +213,12 @@ void() func_button =
worldtext_hsettext(wth, self.worldtext);
worldtext_hsetpos(wth, realorigin(self) + '0 0 12' - dir * 6.0);
worldtext_hsetangles(wth, ang);
worldtext_hsethalign(wth, self.worldtext_halign);

if(self.worldtext_scale != 0)
{
worldtext_hsetscale(wth, self.worldtext_scale);
}
}
};

Expand Down Expand Up @@ -338,6 +348,11 @@ void() func_worldtext_banner =
worldtext_hsetangles(wth, self.angles + '0 180 0');
worldtext_hsethalign(wth, self.worldtext_halign);

if(self.worldtext_scale != 0)
{
worldtext_hsetscale(wth, self.worldtext_scale);
}

if(self.lip > 1)
{
self.think = func_worldtext_banner_think;
Expand Down
1 change: 1 addition & 0 deletions QC/vr_fields.qc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@

.string worldtext;
.float worldtext_halign;
.float worldtext_scale;
.float angle;

//
Expand Down
45 changes: 28 additions & 17 deletions Quake/cl_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const char* svc_strings[128] = {
"svc_sellscreen", "svc_cutscene",
// johnfitz -- new server messages
"35 svc_worldtext_hsethalign", // 35
"36", // 36
"36 svc_worldtext_hsetscale", // 36
"svc_skybox_fitz", // 37 // [string] skyname
"38", // 38
"39", // 39
Expand Down Expand Up @@ -191,6 +191,11 @@ extern qvec3 v_punchangles[2]; // johnfitz

//=============================================================================

template <typename T>
static void readAndDrop(const T&)
{
}

/*
===============
CL_EntityNum
Expand Down Expand Up @@ -344,19 +349,19 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,

if(predbits & UFP_FORWARD)
{ /*news->movement[0] =*/
MSG_ReadShort();
readAndDrop(MSG_ReadShort());
}
// else
// news->movement[0] = 0;
if(predbits & UFP_SIDE)
{ /*news->movement[1] =*/
MSG_ReadShort();
readAndDrop(MSG_ReadShort());
}
// else
// news->movement[1] = 0;
if(predbits & UFP_UP)
{ /*news->movement[2] =*/
MSG_ReadShort();
readAndDrop(MSG_ReadShort());
}
// else
// news->movement[2] = 0;
Expand Down Expand Up @@ -397,12 +402,12 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
{
if(bits & UF_ANGLESXZ)
{
/*news->vangle[0] =*/MSG_ReadShort();
/*news->vangle[2] =*/MSG_ReadShort();
/*news->vangle[0] =*/readAndDrop(MSG_ReadShort());
/*news->vangle[2] =*/readAndDrop(MSG_ReadShort());
}
if(bits & UF_ANGLESY)
{ /*news->vangle[1] =*/
MSG_ReadShort();
readAndDrop(MSG_ReadShort());
}
}
}
Expand Down Expand Up @@ -486,11 +491,11 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
else if(enc == 16)
{
/*solidsize = */
MSG_ReadShort(); // MSG_ReadSize16(&net_message);
readAndDrop(MSG_ReadShort()); // MSG_ReadSize16(&net_message);
}
else if(enc == 32)
{
/*solidsize = */ MSG_ReadLong();
/*solidsize = */ readAndDrop(MSG_ReadShort());
}
else
{
Expand All @@ -499,7 +504,7 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
}
else
{
/*solidsize =*/MSG_ReadShort(); // MSG_ReadSize16(&net_message);
/*solidsize =*/readAndDrop(MSG_ReadShort()); // MSG_ReadSize16(&net_message);
}
// news->solidsize = solidsize;
}
Expand Down Expand Up @@ -529,7 +534,7 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
// &news->boneoffset);
for(i = 0; i < bonecount * 7; i++)
{ /*bonedata[i] =*/
MSG_ReadShort();
readAndDrop(MSG_ReadShort());
}
// news->bonecount = bonecount;
}
Expand All @@ -538,7 +543,7 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
if(fl & 0x40)
{
/*news->basebone =*/MSG_ReadByte();
/*news->baseframe =*/MSG_ReadShort();
/*news->baseframe =*/readAndDrop(MSG_ReadShort());
}
/*else
{
Expand Down Expand Up @@ -577,10 +582,10 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
}
if(bits & UF_LIGHT)
{
/*news->light[0] =*/MSG_ReadShort();
/*news->light[1] =*/MSG_ReadShort();
/*news->light[2] =*/MSG_ReadShort();
/*news->light[3] =*/MSG_ReadShort();
/*news->light[0] =*/readAndDrop(MSG_ReadShort());
/*news->light[1] =*/readAndDrop(MSG_ReadShort());
/*news->light[2] =*/readAndDrop(MSG_ReadShort());
/*news->light[3] =*/readAndDrop(MSG_ReadShort());
/*news->lightstyle =*/MSG_ReadByte();
/*news->lightpflags =*/MSG_ReadByte();
}
Expand Down Expand Up @@ -625,7 +630,7 @@ static unsigned int CLFTE_ReadDelta(unsigned int entnum, entity_state_t* news,
{
if(bits & UF_16BIT)
{
/*news->modelindex2 =*/MSG_ReadShort();
/*news->modelindex2 =*/readAndDrop(MSG_ReadShort());
}
else
{
Expand Down Expand Up @@ -3362,6 +3367,12 @@ void CL_ParseServerMessage()
break;
}

case svc_worldtext_hsetscale:
{
cl.OnMsg_WorldTextHSetScale();
break;
}

// voicechat, because we can. why reduce packet sizes if you're not
// going to use that extra space?!?
case svcfte_voicechat:
Expand Down
13 changes: 13 additions & 0 deletions Quake/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ void client_state_t::OnMsg_WorldTextHSetHAlign() noexcept
cl.worldTexts[wth]._hAlign = v;
}
}

void client_state_t::OnMsg_WorldTextHSetScale() noexcept
{
const WorldTextHandle wth = MSG_ReadShort();
assert(isValidWorldTextHandle(wth));

const auto f = MSG_ReadFloat();

if(isValidWorldTextHandle(wth))
{
cl.worldTexts[wth]._scale = f;
}
}
1 change: 1 addition & 0 deletions Quake/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ struct client_state_t
void OnMsg_WorldTextHSetPos() noexcept;
void OnMsg_WorldTextHSetAngles() noexcept;
void OnMsg_WorldTextHSetHAlign() noexcept;
void OnMsg_WorldTextHSetScale() noexcept;
};

template <typename F>
Expand Down
2 changes: 1 addition & 1 deletion Quake/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ static void COM_Game_f()

if(vr_enabled.value)
{
Cbuf_AddText("map start\n");
Cbuf_AddText("map vrstart\n");
VR_ModAllModels();
}
}
Expand Down
9 changes: 5 additions & 4 deletions Quake/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ void R_DrawWorldText()

const auto drawString = [&](const qvec3& originalpos, const qvec3& angles,
const std::string_view str,
const WorldText::HAlign hAlign)
const WorldText::HAlign hAlign, const float scale)
{
static std::vector<std::string_view> lines;

Expand All @@ -899,8 +899,9 @@ void R_DrawWorldText()

// Angles and offsets
const auto [fwd, right, up] = quake::util::getAngledVectors(angles);
const auto hInc = right * 8.f;
const auto zInc = qvec3{0, 0, -8.f} * up;
const auto charSize = 8.f * scale;
const auto hInc = right * charSize;
const auto zInc = qvec3{0, 0, -charSize} * up;

// Bounds
const auto absmins = originalpos;
Expand Down Expand Up @@ -966,7 +967,7 @@ void R_DrawWorldText()

for(const WorldText& wt : cl.worldTexts)
{
drawString(wt._pos, wt._angles, wt._text, wt._hAlign);
drawString(wt._pos, wt._angles, wt._text, wt._hAlign, wt._scale);
}

glEnd();
Expand Down
2 changes: 2 additions & 0 deletions Quake/gl_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,10 +1472,12 @@ void SCR_UpdateScreen()
// be split accordingly and cleaned up.

qcvm_t* oldvm = qcvm;
PR_SwitchQCVM(nullptr);
PR_SwitchQCVM(&sv.qcvm);

VR_UpdateScreenContent(); // phoboslab

PR_SwitchQCVM(nullptr);
PR_SwitchQCVM(oldvm);
}
else
Expand Down
1 change: 1 addition & 0 deletions Quake/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ void Host_ShutdownServer(bool crash)
}

// QSS
PR_SwitchQCVM(nullptr);
PR_SwitchQCVM(&sv.qcvm);

{
Expand Down
4 changes: 3 additions & 1 deletion Quake/host_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ bool Host_Loadgame(const char* filename, const bool hasTimestamp)

CL_Disconnect_f();

PR_SwitchQCVM(nullptr);
PR_SwitchQCVM(&sv.qcvm);
SV_SpawnServer(mapname, SpawnServerSrc::FromSaveFile);

Expand Down Expand Up @@ -2420,6 +2421,7 @@ void Host_Spawn_f()
sv.SendMsg_WorldTextHSetPos(*host_client, wth, wt._pos);
sv.SendMsg_WorldTextHSetAngles(*host_client, wth, wt._angles);
sv.SendMsg_WorldTextHSetHAlign(*host_client, wth, wt._hAlign);
sv.SendMsg_WorldTextHSetScale(*host_client, wth, wt._scale);

++wth;
}
Expand Down Expand Up @@ -3107,7 +3109,7 @@ void Host_Startdemos_f()
Cbuf_AddText("maxplayers 1\n");
Cbuf_AddText("deathmatch 0\n");
Cbuf_AddText("coop 0\n");
Cbuf_AddText("map start\n");
Cbuf_AddText("map vrstart\n");
Cbuf_AddText("centerview\n");
}

Expand Down
1 change: 1 addition & 0 deletions Quake/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ void M_Main_Key(int key)
{
quake::menu m{"Single Player", &M_Menu_Main_f};

m.add_action_entry("VR Hub", [] { M_Menu_NewGame_f("vrstart"); });
m.add_action_entry("Tutorial", [] { M_Menu_NewGame_f("vrtutorial"); });
m.add_action_entry("Sandbox", [] { M_Menu_NewGame_f("vrfiringrange"); });

Expand Down
19 changes: 19 additions & 0 deletions Quake/pr_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,23 @@ static void PF_worldtext_hsethalign()
{ sv.SendMsg_WorldTextHSetHAlign(client, wth, hAlign); });
}

static void PF_worldtext_hsetscale()
{
const WorldTextHandle wth = G_INT(OFS_PARM0);
const float scale = G_FLOAT(OFS_PARM1);

if(!sv.isValidWorldTextHandle(wth))
{
Host_Error("Invalid world text handle '%d'", wth);
return;
}

sv.getWorldText(wth)._scale = scale;

forAllActiveOrSpawnedClients([&](client_t& client)
{ sv.SendMsg_WorldTextHSetScale(client, wth, scale); });
}

static void PF_strlen()
{
G_FLOAT(OFS_RETURN) = std::strlen(G_STRING(OFS_PARM0));
Expand Down Expand Up @@ -2412,6 +2429,8 @@ builtin_t pr_ssqcbuiltins[] = {

PF_sqrt, // #108
PF_atan2, // #109

PF_worldtext_hsetscale, // #110
};

int pr_ssqcnumbuiltins = sizeof(pr_ssqcbuiltins) / sizeof(pr_ssqcbuiltins[0]);
Expand Down
1 change: 1 addition & 0 deletions Quake/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define svc_worldtext_hsetpos 48
#define svc_worldtext_hsetangles 49
#define svc_worldtext_hsethalign 35
#define svc_worldtext_hsetscale 36
// johnfitz

// spike -- some extensions for particles.
Expand Down
8 changes: 8 additions & 0 deletions Quake/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ void server_t::SendMsg_WorldTextHSetHAlign(client_t& client,
MSG_WriteShort(&client.message, wth);
MSG_WriteByte(&client.message, static_cast<int>(hAlign));
}

void server_t::SendMsg_WorldTextHSetScale(client_t& client,
const WorldTextHandle wth, const float scale) noexcept
{
MSG_WriteByte(&client.message, svc_worldtext_hsetscale);
MSG_WriteShort(&client.message, wth);
MSG_WriteFloat(&client.message, scale);
}
3 changes: 3 additions & 0 deletions Quake/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ struct server_t

void SendMsg_WorldTextHSetHAlign(client_t& client,
const WorldTextHandle wth, const WorldText::HAlign hAlign) noexcept;

void SendMsg_WorldTextHSetScale(client_t& client,
const WorldTextHandle wth, float scale) noexcept;
};

#define NUM_PING_TIMES 16
Expand Down
Loading

0 comments on commit fbcf673

Please sign in to comment.