Skip to content

Commit

Permalink
Add tests. Run them in CI. Make soundscripts use fixed_vector instead…
Browse files Browse the repository at this point in the history
… of std::array
  • Loading branch information
FreeSlave committed Nov 18, 2024
1 parent f69fcea commit 4938da4
Show file tree
Hide file tree
Showing 42 changed files with 1,861 additions and 457 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ jobs:
Remove-Item -Force -Path dist/${{ steps.extract_gamedir.outputs.gamedir }}/cl_dlls/client.lib
Remove-Item -Force -Path dist/${{ steps.extract_gamedir.outputs.gamedir }}/dlls/hl.lib
- name: Install Google Test
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt -y install libgtest-dev

- name: Run tests
if: startsWith(matrix.os, 'ubuntu')
working-directory: ./tests
run: |
cmake -GNinja -B build -S .
cmake --build build --target all
./build/test
- name: Upload linux artifact
if: startsWith(matrix.os, 'ubuntu')
uses: actions/upload-artifact@v4
Expand Down
3 changes: 3 additions & 0 deletions cl_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ set (CLDLL_SOURCES
../game_shared/tex_materials.cpp
../game_shared/parsetext.cpp
../game_shared/error_collector.cpp
../game_shared/file_utils.cpp
../game_shared/fx_types.cpp
../game_shared/json_config.cpp
../game_shared/json_utils.cpp
../game_shared/random_utils.cpp
../game_shared/util_shared.cpp
saytext.cpp
scoreboard.cpp
Expand Down
5 changes: 5 additions & 0 deletions dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ project (SVDLL)

set (SVDLL_LIBRARY server)

add_definitions(-DSERVER_DLL)

if(NOT MSVC)
add_compile_options(-fno-exceptions) # GCC/Clang flag
add_compile_options(-fno-rtti) # GCC/Clang flag
Expand Down Expand Up @@ -201,8 +203,11 @@ set (SVDLL_SOURCES
../game_shared/tex_materials.cpp
../game_shared/parsetext.cpp
../game_shared/error_collector.cpp
../game_shared/file_utils.cpp
../game_shared/fx_types.cpp
../game_shared/json_config.cpp
../game_shared/json_utils.cpp
../game_shared/random_utils.cpp
../game_shared/util_shared.cpp
../game_shared/vcs_info.cpp
)
Expand Down
6 changes: 3 additions & 3 deletions dlls/agrunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ void CAGrunt::PrescheduleThink( void )
const SoundScript* myIdleSoundScript = GetSoundScript(idleSoundScript.name);
if (myIdleSoundScript)
{
if (myIdleSoundScript->waveCount == 1)
if (myIdleSoundScript->waves.size() == 1)
{
num = 0;
}
else if (myIdleSoundScript->waveCount > 1)
else if (myIdleSoundScript->waves.size() > 1)
{
do
{
num = RANDOM_LONG(0, myIdleSoundScript->waveCount-1);
num = RANDOM_LONG(0, myIdleSoundScript->waves.size()-1);
}
while( num == m_iLastWord );
}
Expand Down
26 changes: 8 additions & 18 deletions dlls/ammoregistry.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
#include <cstring>

#include "ammoregistry.h"

#if CLIENT_DLL
#include "cl_dll.h"
#define AMMO_LOG gEngfuncs.Con_DPrintf
#define AMMO_ERROR gEngfuncs.Con_Printf
#else
#include "util.h"
#define AMMO_LOG(...) ALERT(at_aiconsole, ##__VA_ARGS__ )
#define AMMO_ERROR(...) ALERT(at_error, ##__VA_ARGS__ )
#endif
#include "arraysize.h"

#include "logger.h"
#include "string_utils.h"

void AmmoType::SetName(const char *ammoName)
{
#if CLIENT_DLL
strncpy(name, ammoName, sizeof(name));
name[sizeof(name)-1] = '\0';
strncpyEnsureTermination(name, ammoName);
#else
name = ammoName;
#endif
Expand All @@ -42,20 +32,20 @@ int AmmoRegistry::Register(const char *name, int maxAmmo, bool exhaustible)
const AmmoType* type = GetByIndex(index);
if (type->maxAmmo != maxAmmo || type->exhaustible != exhaustible)
{
AMMO_ERROR("Trying to re-register ammo '%s' with different parameters\n", name);
LOG_ERROR("Trying to re-register ammo '%s' with different parameters\n", name);
}
return index;
}

if (lastAmmoIndex >= MAX_AMMO_TYPES - 1)
{
AMMO_ERROR("Too many ammo types. Max is %d\n", MAX_AMMO_TYPES-1);
LOG_ERROR("Too many ammo types. Max is %d\n", MAX_AMMO_TYPES-1);
return -1;
}

if (maxAmmo <= 0)
{
AMMO_ERROR("Invalid max ammo (%d) for '%s'\n", maxAmmo, name);
LOG_ERROR("Invalid max ammo (%d) for '%s'\n", maxAmmo, name);
return -1;
}

Expand All @@ -74,7 +64,7 @@ void AmmoRegistry::RegisterOnClient(const char *name, int maxAmmo, int index, bo
return;
if (index <= 0 || index >= MAX_AMMO_TYPES)
{
AMMO_ERROR("Invalid ammo index %d\n", index);
LOG_ERROR("Invalid ammo index %d\n", index);
return;
}
AmmoType& type = ammoTypes[index - 1];
Expand Down Expand Up @@ -158,7 +148,7 @@ void AmmoRegistry::ReportRegisteredTypes()

void AmmoRegistry::ReportRegisteredType(const AmmoType& ammoType)
{
AMMO_LOG("%s. Max ammo: %d. Index: %d. %s\n", ammoType.name, ammoType.maxAmmo, ammoType.id, ammoType.exhaustible ? "Exhaustible" : "");
LOG_DEV("%s. Max ammo: %d. Index: %d. %s\n", ammoType.name, ammoType.maxAmmo, ammoType.id, ammoType.exhaustible ? "Exhaustible" : "");
}

AmmoRegistry g_AmmoRegistry;
Expand Down
2 changes: 1 addition & 1 deletion dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ void CBaseEntity::EmitSoundScriptAmbient(const Vector& vecOrigin, const char *na

void CBaseEntity::PrecacheSoundScript(const SoundScript& soundScript)
{
for (size_t i=0; i<soundScript.waveCount; ++i)
for (size_t i=0; i<soundScript.waves.size(); ++i)
{
PRECACHE_SOUND(soundScript.waves[i]);
}
Expand Down
1 change: 0 additions & 1 deletion dlls/cdll_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#if !defined(CDLL_DLL_H)
#define CDLL_DLL_H
#include "player_items.h"
#include "mod_features.h"

#define MAX_WEAPONS 32

Expand Down
40 changes: 20 additions & 20 deletions dlls/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2943,20 +2943,20 @@ class CEnvWarpBall : public CBaseEntity
pev->message = warpTarget;
}

inline string_t WarpballSound1() {
inline const char* WarpballSound1() {
if (!FStringNull(pev->noise1))
return pev->noise1;
return g_modFeatures.alien_teleport_sound ? MAKE_STRING(ALIEN_TELEPORT_SOUND) : MAKE_STRING(WARPBALL_SOUND1);
return STRING(pev->noise1);
return g_modFeatures.alien_teleport_sound ? ALIEN_TELEPORT_SOUND : WARPBALL_SOUND1;
}
inline string_t WarpballSound2() {
inline const char* WarpballSound2() {
if (FStringNull(pev->noise2))
{
if (g_modFeatures.alien_teleport_sound)
return iStringNull;
return FStringNull(pev->noise1) ? MAKE_STRING(WARPBALL_SOUND2) : iStringNull;
return nullptr;
return FStringNull(pev->noise1) ? WARPBALL_SOUND2 : nullptr;
}
else
return pev->noise2;
return STRING(pev->noise2);
}
inline float SoundAttenuation() {
return ::SoundAttenuation(m_soundRadius);
Expand Down Expand Up @@ -3107,11 +3107,11 @@ void CEnvWarpBall::Precache( void )
PRECACHE_MODEL( STRING(model2) );
}

PRECACHE_SOUND(STRING(WarpballSound1()));
PRECACHE_SOUND(WarpballSound1());

string_t sound2 = WarpballSound2();
if (!FStringNull(sound2))
PRECACHE_SOUND(STRING(sound2));
const char* sound2 = WarpballSound2();
if (sound2 != nullptr)
PRECACHE_SOUND(sound2);

UTIL_PrecacheOther("warpball_hurt");
}
Expand Down Expand Up @@ -3173,13 +3173,13 @@ void CEnvWarpBall::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE

if (!FBitSet(pev->spawnflags, SF_WARPBALL_NOSOUND))
{
w.sound1.soundName = WarpballSound1();
w.sound1.sound = WarpballSound1();
w.sound1.volume = SoundVolume();
w.sound1.attenuation = SoundAttenuation();

if (WarpballSound2())
{
w.sound2.soundName = WarpballSound2();
w.sound2.sound = WarpballSound2();
w.sound2.volume = SoundVolume();
w.sound2.attenuation = SoundAttenuation();
}
Expand All @@ -3192,7 +3192,7 @@ void CEnvWarpBall::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE
w.shake.radius = Radius();
}

w.sprite1.spriteName = pev->model ? pev->model : MAKE_STRING(WARPBALL_SPRITE);
w.sprite1.sprite = pev->model ? STRING(pev->model) : WARPBALL_SPRITE;
w.sprite1.framerate = SpriteFramerate();

int red = pev->rendercolor.x;
Expand All @@ -3210,7 +3210,7 @@ void CEnvWarpBall::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE
w.sprite1.scale = Scale();

if (!FStringNull(model2)) {
w.sprite2.spriteName = model2;
w.sprite2.sprite = STRING(model2);
w.sprite2.framerate = framerate2 > 0 ? framerate2 : SpriteFramerate();
int red2, green2, blue2;
if (rendercolor2 == g_vecZero)
Expand Down Expand Up @@ -3556,13 +3556,13 @@ void CEnvXenMaker::TrySpawn()

WarpballTemplate w;

w.sprite1.spriteName = MAKE_STRING(XENMAKER_SPRITE1);
w.sprite1.sprite = XENMAKER_SPRITE1;
w.sprite1.color = Color(m_vStartSpriteColor.x, m_vStartSpriteColor.y, m_vStartSpriteColor.z);
w.sprite1.alpha = m_iStartSpriteAlpha;
w.sprite1.scale = m_flStartSpriteScale;
w.sprite1.framerate = m_flStartSpriteFramerate;

w.sprite2.spriteName = MAKE_STRING(XENMAKER_SPRITE2);
w.sprite2.sprite = XENMAKER_SPRITE2;
w.sprite2.color = Color(m_vEndSpriteColor.x, m_vEndSpriteColor.y, m_vEndSpriteColor.z);
w.sprite2.alpha = m_iEndSpriteAlpha;
w.sprite2.scale = m_flEndSpriteScale;
Expand All @@ -3580,15 +3580,15 @@ void CEnvXenMaker::TrySpawn()
w.light.radius = m_flLightRadius;

if (g_modFeatures.alien_teleport_sound)
w.sound1.soundName = MAKE_STRING(ALIEN_TELEPORT_SOUND);
w.sound1.sound = ALIEN_TELEPORT_SOUND;
else
w.sound1.soundName = MAKE_STRING(XENMAKER_SOUND1);
w.sound1.sound = XENMAKER_SOUND1;

if (!g_modFeatures.alien_teleport_sound)
{
if (asTemplate)
{
w.sound2.soundName = MAKE_STRING(XENMAKER_SOUND2);
w.sound2.sound = XENMAKER_SOUND2;
}
else
{
Expand Down
39 changes: 33 additions & 6 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "inventory.h"
#include "soundscripts.h"
#include "visuals.h"
#include "warpball.h"
#include "ent_templates.h"
#include "followers.h"
#include "savetitles.h"
Expand Down Expand Up @@ -1361,7 +1362,34 @@ void ReportSoundReplacements()
g_soundReplacement.ReportSoundReplacements();
}

extern void DumpWarpballTemplates();
void ReportSoundScripts()
{
int argc = CMD_ARGC();
if (argc > 1)
{
for (int i=1; i<argc; ++i)
g_SoundScriptSystem.DumpSoundScript(CMD_ARGV(i));
}
else
g_SoundScriptSystem.DumpSoundScripts();
}

void ReportVisuals()
{
int argc = CMD_ARGC();
if (argc > 1)
{
for (int i=1; i<argc; ++i)
g_VisualSystem.DumpVisual(CMD_ARGV(i));
}
else
g_VisualSystem.DumpVisuals();
}

void ReportWarpballTemplates()
{
g_WarpballCatalog.DumpWarpballTemplates();
}

static void CVAR_REGISTER_INTEGER( cvar_t* cvar, int value )
{
Expand Down Expand Up @@ -1396,7 +1424,6 @@ cvar_t sv_busters = { "sv_busters", "0" };

extern void RegisterAmmoTypes();
extern void ReportRegisteredAmmoTypes();
extern void LoadWarpballTemplates();

// Register your console variables here
// This gets called one time when the game is initialied
Expand All @@ -1409,7 +1436,7 @@ void GameDLLInit( void )
ReadAmmoAmounts();

RegisterAmmoTypes();
LoadWarpballTemplates();
g_WarpballCatalog.ReadFromFile("templates/warpball.json");
ReadInventorySpec();
g_SoundScriptSystem.ReadFromFile("sound/soundscripts.json");
g_VisualSystem.ReadFromFile("templates/visuals.json");
Expand Down Expand Up @@ -2041,12 +2068,12 @@ void GameDLLInit( void )
g_engfuncs.pfnAddServerCommand("calc_velocity", Cmd_CalcVelocity);
g_engfuncs.pfnAddServerCommand("calc_state", Cmd_CalcState);
g_engfuncs.pfnAddServerCommand("dump_ammo_types", ReportRegisteredAmmoTypes);
g_engfuncs.pfnAddServerCommand("dump_warpballs", DumpWarpballTemplates);
g_engfuncs.pfnAddServerCommand("dump_warpballs", ReportWarpballTemplates);
g_engfuncs.pfnAddServerCommand("dump_precached_models", ReportPrecachedModels);
g_engfuncs.pfnAddServerCommand("dump_precached_sounds", ReportPrecachedSounds);
g_engfuncs.pfnAddServerCommand("dump_sound_replacements", ReportSoundReplacements);
g_engfuncs.pfnAddServerCommand("dump_soundscripts", DumpSoundScripts);
g_engfuncs.pfnAddServerCommand("dump_visuals", DumpVisuals);
g_engfuncs.pfnAddServerCommand("dump_soundscripts", ReportSoundScripts);
g_engfuncs.pfnAddServerCommand("dump_visuals", ReportVisuals);
}

bool ItemsPickableByTouch()
Expand Down
6 changes: 3 additions & 3 deletions dlls/monstermaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void CMonsterMaker::Precache( void )
m_childIsValid = UTIL_PrecacheMonster( STRING(m_iszMonsterClassname), m_reverseRelationship, &m_defaultMinHullSize, &m_defaultMaxHullSize, entityOverrides );

if (!FStringNull(WarpballName()))
PrecacheWarpballTemplate(STRING(WarpballName()), STRING(m_iszMonsterClassname));
g_WarpballCatalog.PrecacheWarpballTemplate(STRING(WarpballName()), STRING(m_iszMonsterClassname));

UTIL_PrecacheOther("monstermaker_hull");
}
Expand Down Expand Up @@ -855,7 +855,7 @@ CBaseEntity* CMonsterMaker::SpawnMonster(const Vector &placePosition, const Vect
void CMonsterMaker::StartWarpballEffect(const Vector &vecPosition, edict_t* warpballSoundEnt)
{
const char* warpballName = STRING(WarpballName());
const WarpballTemplate* warpballTemplate = FindWarpballTemplate(warpballName, STRING(m_iszMonsterClassname));
const WarpballTemplate* warpballTemplate = g_WarpballCatalog.FindWarpballTemplate(warpballName, STRING(m_iszMonsterClassname));
if (warpballTemplate)
{
PlayWarpballEffect(*warpballTemplate, vecPosition, warpballSoundEnt);
Expand Down Expand Up @@ -912,7 +912,7 @@ int CMonsterMaker::MakeMonster( void )

if (!FStringNull(warpballName))
{
const WarpballTemplate* w = FindWarpballTemplate(STRING(warpballName), STRING(m_iszMonsterClassname));
const WarpballTemplate* w = g_WarpballCatalog.FindWarpballTemplate(STRING(warpballName), STRING(m_iszMonsterClassname));
if (w)
{
if (spawnDelay == 0.0f)
Expand Down
14 changes: 2 additions & 12 deletions dlls/soundent.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,9 @@
#if !defined(SOUNDENT_H)
#define SOUNDENT_H

#define MAX_WORLD_SOUNDS 64 // maximum number of sounds handled by the world at one time.

#define bits_SOUND_NONE 0
#define bits_SOUND_COMBAT ( 1 << 0 )// gunshots, explosions
#define bits_SOUND_WORLD ( 1 << 1 )// door opening/closing, glass breaking
#define bits_SOUND_PLAYER ( 1 << 2 )// all noises generated by player. walking, shooting, falling, splashing
#define bits_SOUND_CARCASS ( 1 << 3 )// dead body
#define bits_SOUND_MEAT ( 1 << 4 )// gib or pork chop
#define bits_SOUND_DANGER ( 1 << 5 )// pending danger. Grenade that is about to explode, explosive barrel that is damaged, falling crate
#define bits_SOUND_GARBAGE ( 1 << 6 )// trash cans, banana peels, old fast food bags.
#include "soundent_bits.h"

#define bits_SOUND_REMOVE_FROM_DEFAULT ( 1 << 10 )
#define bits_ALL_SOUNDS 0xFFFFFFFF
#define MAX_WORLD_SOUNDS 64 // maximum number of sounds handled by the world at one time.

#define SOUNDLIST_EMPTY -1

Expand Down
Loading

0 comments on commit 4938da4

Please sign in to comment.