Skip to content

Commit

Permalink
Simple entity editor (#694)
Browse files Browse the repository at this point in the history
Ability to load entites from separate file instead of map content.
Added sv_use_entity_file cvar to toggle entites loading source.
  • Loading branch information
Karaulov authored and LevShisterov committed May 7, 2019
1 parent 998f172 commit 3f809d0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -55,6 +55,7 @@ Bugfixed version of rehlds contains an additional cvars:
<li>sv_rehlds_userinfo_transmitted_fields // Userinfo fields only with these keys will be transmitted to clients via network. If not set then all fields will be transmitted (except prefixed with underscore). Each key must be prefixed by backslash, for example "\name\model\*sid\*hltv\bottomcolor\topcolor". See [wiki](https://github.com/dreamstalker/rehlds/wiki/Userinfo-keys) to collect sufficient set of keys for your server. Default: ""
<li>sv_rehlds_attachedentities_playeranimationspeed_fix // Fixes bug with gait animation speed increase when player has some attached entities (aiments). Can cause animation lags when cl_updaterate is low. Default: 0
<li>sv_rehlds_maxclients_from_single_ip // Limit number of connections from the single ip address. Default: 5
<li>sv_use_entity_file // Use custom entity file for a map. Path to an entity file will be "maps/[map name].ent". Default: 0
</ul>

## Commands
Expand Down
45 changes: 45 additions & 0 deletions rehlds/engine/sv_main.cpp
Expand Up @@ -203,6 +203,7 @@ cvar_t sv_rehlds_attachedentities_playeranimationspeed_fix = {"sv_rehlds_attache
cvar_t sv_rehlds_local_gametime = {"sv_rehlds_local_gametime", "0", 0, 0.0f, nullptr};
cvar_t sv_rehlds_send_mapcycle = { "sv_rehlds_send_mapcycle", "0", 0, 0.0f, nullptr };
cvar_t sv_rehlds_maxclients_from_single_ip = { "sv_rehlds_maxclients_from_single_ip", "5", 0, 5.0f, nullptr };
cvar_t sv_use_entity_file = { "sv_use_entity_file", "0", 0, 0.0f, nullptr };
#endif

delta_t *SV_LookupDelta(char *name)
Expand Down Expand Up @@ -6126,6 +6127,49 @@ int SV_SpawnServer(qboolean bIsDemo, char *server, char *startspot)

void SV_LoadEntities(void)
{
#ifdef REHLDS_FIXES
if (sv_use_entity_file.value > 0.0f)
{
char name[MAX_PATH];
Q_snprintf(name, sizeof(name), "maps/%s.ent", g_psv.name);

if (!FS_FileExists(name))
{
FILE *f = FS_Open(name, "wb");
if (f)
{
FS_Write(g_psv.worldmodel->entities, Q_strlen(g_psv.worldmodel->entities), 1, f);
FS_Close(f);
}
}
else
{
FILE *f = FS_Open(name, "rb");
if (f)
{
Con_Printf("Using custom entity file: %s\n", name);

unsigned int nFileSize = FS_Size(f);
char *pszInputStream = (char *)Mem_Malloc(nFileSize + 1);
if (!pszInputStream)
{
Sys_Error("%s: Could not allocate space for entity file of %i bytes", __func__, nFileSize + 1);
}

FS_Read(pszInputStream, nFileSize, 1, f);
pszInputStream[nFileSize] = '\0';

ED_LoadFromFile(pszInputStream);
Mem_Free(pszInputStream);
FS_Close(f);
return;
}
}

Con_Printf("Using default entities...\n");
}

#endif // REHLDS_FIXES
ED_LoadFromFile(g_psv.worldmodel->entities);
}

Expand Down Expand Up @@ -7863,6 +7907,7 @@ void SV_Init(void)

Cvar_RegisterVariable(&sv_rollspeed);
Cvar_RegisterVariable(&sv_rollangle);
Cvar_RegisterVariable(&sv_use_entity_file);
#endif

for (int i = 0; i < MAX_MODELS; i++)
Expand Down

0 comments on commit 3f809d0

Please sign in to comment.