Skip to content

Commit

Permalink
tweak spectate mode
Browse files Browse the repository at this point in the history
cycle through 4 modes instead of 6. The map overview modes can still be seen by pressing E or in the spectator menu.

g_precacheModels changed to a set because model replacements are stored separately.
  • Loading branch information
wootguy committed Nov 4, 2024
1 parent d8e40a9 commit 1d2ba78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
29 changes: 16 additions & 13 deletions dlls/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5291,19 +5291,19 @@ void CBasePlayer::Observer_HandleButtons()
Observer_SetMode(OBS_CHASE_FREE);

else if (pev->iuser1 == OBS_CHASE_FREE)
Observer_SetMode(OBS_IN_EYE);
Observer_SetMode(OBS_ROAMING);

else if (pev->iuser1 == OBS_IN_EYE)
Observer_SetMode(OBS_ROAMING);
Observer_SetMode(OBS_CHASE_LOCKED);

else if (pev->iuser1 == OBS_ROAMING)
Observer_SetMode(OBS_MAP_FREE);
Observer_SetMode(OBS_IN_EYE);

else if (pev->iuser1 == OBS_MAP_FREE)
Observer_SetMode(OBS_MAP_CHASE);
Observer_SetMode(OBS_CHASE_LOCKED);

else
Observer_SetMode(OBS_CHASE_LOCKED); // don't use OBS_CHASE_LOCKED anymore
Observer_SetMode(OBS_CHASE_LOCKED);

m_flNextObserverInput = gpGlobals->time + 0.05;
}
Expand Down Expand Up @@ -5357,6 +5357,9 @@ void CBasePlayer::Observer_CheckTarget()
return;
}

// keep copying origin so that the view doesn't break after teleporting large distances
UTIL_SetOrigin(pev, target->pev->origin);

// check taget
if (target->pev->deadflag == DEAD_DEAD)
{
Expand Down Expand Up @@ -5468,23 +5471,23 @@ void CBasePlayer::Observer_SetMode(int iMode)
// print spepctaor mode on client screen

switch (pev->iuser1) {
case OBS_IN_EYE:
UTIL_ClientPrint(edict(), print_center, "First-Person Cam\n[1/4]");
break;
case OBS_CHASE_LOCKED:
UTIL_ClientPrint(edict(), print_center, "Locked Chase Cam\n[1/6]");
UTIL_ClientPrint(edict(), print_center, "Locked Chase Cam\n[2/4]");
break;
case OBS_CHASE_FREE:
UTIL_ClientPrint(edict(), print_center, "Free Chase Cam\n[2/6]");
break;
case OBS_IN_EYE:
UTIL_ClientPrint(edict(), print_center, "First-Person Cam\n[3/6]");
UTIL_ClientPrint(edict(), print_center, "Free Chase Cam\n[3/4]");
break;
case OBS_ROAMING:
UTIL_ClientPrint(edict(), print_center, "Free-Look\n[4/6]");
UTIL_ClientPrint(edict(), print_center, "Free-Look\n[4/4]");
break;
case OBS_MAP_FREE:
UTIL_ClientPrint(edict(), print_center, "Free Map Overview\n[5/6]");
UTIL_ClientPrint(edict(), print_center, "Free Map Overview\n");
break;
case OBS_MAP_CHASE:
UTIL_ClientPrint(edict(), print_center, "Chase Map Overview\n[6/6]");
UTIL_ClientPrint(edict(), print_center, "Chase Map Overview\n");
break;
}

Expand Down
24 changes: 15 additions & 9 deletions dlls/eng_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "PluginManager.h"
#include <fstream>

std::unordered_map<std::string, std::string> g_precachedModels;
std::unordered_set<std::string> g_precachedModels;
std::unordered_set<std::string> g_missingModels;
std::unordered_set<std::string> g_precachedSounds;
std::unordered_set<std::string> g_precachedGeneric;
Expand Down Expand Up @@ -415,7 +415,7 @@ int PRECACHE_MODEL(const char* path) {
// Tested with sc_darknebula.
if (g_tryPrecacheModels.size() + g_bsp.entityBspModelCount + 1 <= MAX_PRECACHE_MODEL) {
if (g_precachedModels.find(path) == g_precachedModels.end())
g_precachedModels[path] = path;
g_precachedModels.insert(path);
int modelIdx = g_engfuncs.pfnPrecacheModel(path);

std::string pathstr = std::string(path);
Expand Down Expand Up @@ -479,7 +479,7 @@ bool SET_MODEL(edict_t* edict, const char* model) {
CALL_HOOKS(bool, pfnSetModel, edict, model);
g_engfuncs.pfnSetModel(edict, model);
if (!g_serveractive)
g_precachedModels[model] = model; // engine precaches entity BSP models automatically
g_precachedModels.insert(model); // engine precaches entity BSP models automatically
CALL_HOOKS(bool, pfnSetModelPost, edict, model);
return false;
}
Expand Down Expand Up @@ -519,25 +519,31 @@ bool SET_MODEL_MERGED(edict_t* edict, const char* model, int mergeId) {

const char* GET_MODEL(const char* model) {
std::string lowerPath = toLowerCase(model);
model = lowerPath.c_str();

if (g_modelReplacements.find(model) != g_modelReplacements.end()) {
model = g_modelReplacements[model].c_str();
if (g_modelReplacements.find(lowerPath) != g_modelReplacements.end()) {
model = g_modelReplacements[lowerPath].c_str();
}

if (g_precachedModels.find(model) == g_precachedModels.end()) {
model = NOT_PRECACHED_MODEL;
}
else {
model = g_precachedModels[model].c_str();
}

return model;
}

int MODEL_INDEX(const char* model) {
std::string lowerPath = toLowerCase(model);
model = lowerPath.c_str();

if (!model || model[0] == '\0') {
return 0;
}

if (!g_precachedModels.count(lowerPath)) {
ALERT(at_error, "MODEL_INDEX not precached: %s\n", model);
return g_engfuncs.pfnModelIndex(NOT_PRECACHED_MODEL);
}

return g_engfuncs.pfnModelIndex(model);
}

Expand Down
2 changes: 1 addition & 1 deletion dlls/eng_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CBaseEntity;
EXPORT extern Bsp g_bsp;

// resources that were successfully precached
EXPORT extern std::unordered_map<std::string, std::string> g_precachedModels; // storing values so GET_MODEL can be used with MAKE_STRING
EXPORT extern std::unordered_set<std::string> g_precachedModels; // storing values so GET_MODEL can be used with MAKE_STRING
EXPORT extern std::unordered_set<std::string> g_missingModels; // storing values so GET_MODEL can be used with MAKE_STRING
EXPORT extern std::unordered_set<std::string> g_precachedSounds;
EXPORT extern std::unordered_set<std::string> g_precachedGeneric;
Expand Down

0 comments on commit 1d2ba78

Please sign in to comment.