Skip to content

Commit

Permalink
bot: implemented asynchronous pathfinding
Browse files Browse the repository at this point in the history
nav: floyd-warshall matrices and practice updates are done asynchronously by now
add: yb_threadpool_workers cvar, that controls number of worker threads bot will use
add: cv_autovacate_keep_slots, the amount of slots to keep by auto vacate
aim: enemy prediction is now done asynchronously by now
bot: minor fixes and refactoring, including analyze suspend mistake (ref #441)

note: the master builds are now NOT production ready, please test before installing on real servers!
  • Loading branch information
jeefo committed May 6, 2023
1 parent e7712a5 commit a616f25
Show file tree
Hide file tree
Showing 30 changed files with 737 additions and 415 deletions.
2 changes: 1 addition & 1 deletion ext/crlib
10 changes: 5 additions & 5 deletions ext/hlsdk/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

#ifndef CONST_H
#define CONST_H
//
// Constants shared by the engine and dlls
// This header file included by engine files and DLL files.
// Most came from server.h
//
// Constants shared by the engine and dlls
// This header file included by engine files and DLL files.
// Most came from server.h

#define INTERFACE_VERSION 140

Expand Down Expand Up @@ -842,7 +842,7 @@ typedef enum {
missile = 2
} IGNORE_MONSTERS;

typedef enum {
typedef enum {
ignore_glass = 1,
dont_ignore_glass = 0
} IGNORE_GLASS;
Expand Down
4 changes: 2 additions & 2 deletions ext/hlsdk/eiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct usercmd_s {
byte msec; // Duration in ms of command
vec3_t viewangles; // Command view angles.

// intended velocities
// intended velocities
float forwardmove; // Forward velocity.
float sidemove; // Sideways velocity.
float upmove; // Upward velocity.
Expand All @@ -63,7 +63,7 @@ typedef struct usercmd_s {
byte impulse; // Impulse command issued.
byte weaponselect; // Current weapon id

// Experimental player impact stuff.
// Experimental player impact stuff.
int impact_index;
vec3_t impact_position;
} usercmd_t;
Expand Down
6 changes: 2 additions & 4 deletions ext/hlsdk/extdll.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ class string_t final : public cr::DenyCopying {
estring_t offset;

public:
explicit string_t () : offset (0)
{ }
explicit string_t () : offset (0) {}

string_t (int offset) : offset (offset)
{ }
string_t (int offset) : offset (offset) {}

~string_t () = default;

Expand Down
2 changes: 1 addition & 1 deletion ext/hlsdk/meta_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
*/

// Simplified version by Wei Mingzhi
// Simplified version by Wei Mingzhi

#ifndef META_API_H
#define META_API_H
Expand Down
2 changes: 1 addition & 1 deletion ext/hlsdk/metamod.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
*/

// Simplified version by Wei Mingzhi
// Simplified version by Wei Mingzhi

#ifndef METAMOD_H
#define METAMOD_H
Expand Down
6 changes: 3 additions & 3 deletions ext/hlsdk/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
****/

// stripped down version of com_model.h & pm_info.h
// stripped down version of com_model.h & pm_info.h

#ifndef MODEL_H
#define MODEL_H
Expand Down Expand Up @@ -103,7 +103,7 @@ typedef struct msurface_s {
} msurface_t;

typedef struct cache_user_s {
void* data; // extradata
void *data; // extradata
} cache_user_t;

typedef struct hull_s {
Expand Down Expand Up @@ -166,7 +166,7 @@ typedef struct physent_s {
char name[32]; // name of model, or "player" or "world".
int player;
vec3_t origin; // model's origin in world coordinates.
struct model_s* model; // only for bsp models
struct model_s *model; // only for bsp models
} physent_t;

typedef struct playermove_s {
Expand Down
209 changes: 103 additions & 106 deletions ext/hlsdk/physint.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,117 +48,114 @@ GNU General Public License for more details.
#define LUMP_SAVE_NO_DATA 7
#define LUMP_SAVE_CORRUPTED 8

typedef struct areanode_s
{
int axis; // -1 = leaf node
float dist;
struct areanode_s *children[2];
link_t trigger_edicts;
link_t solid_edicts;
link_t portal_edicts;
typedef struct areanode_s {
int axis; // -1 = leaf node
float dist;
struct areanode_s *children[2];
link_t trigger_edicts;
link_t solid_edicts;
link_t portal_edicts;
} areanode_t;

typedef struct server_physics_api_s
{
// unlink edict from old position and link onto new
void ( *pfnLinkEdict) ( edict_t *ent, qboolean touch_triggers );
double ( *pfnGetServerTime )( void ); // unclamped
double ( *pfnGetFrameTime )( void ); // unclamped
void* ( *pfnGetModel )( int modelindex );
areanode_t* ( *pfnGetHeadnode )( void ); // AABB tree for all physic entities
int ( *pfnServerState )( void );
void ( *pfnHost_Error )( const char *error, ... ); // cause Host Error
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 6
struct triangleapi_s *pTriAPI; // draw coliisions etc. Only for local system

// draw debug messages (must be called from DrawOrthoTriangles). Only for local system
int ( *pfnDrawConsoleString )( int x, int y, char *string );
void ( *pfnDrawSetTextColor )( float r, float g, float b );
void ( *pfnDrawConsoleStringLen )( const char *string, int *length, int *height );
void ( *Con_NPrintf )( int pos, const char *fmt, ... );
void ( *Con_NXPrintf )( struct con_nprint_s *info, const char *fmt, ... );
const char *( *pfnGetLightStyle )( int style ); // read custom appreance for selected lightstyle
void ( *pfnUpdateFogSettings )( unsigned int packed_fog );
char **(*pfnGetFilesList)( const char *pattern, int *numFiles, int gamedironly );
struct msurface_s *(*pfnTraceSurface)( edict_t *pTextureEntity, const float *v1, const float *v2 );
const byte *(*pfnGetTextureData)( unsigned int texnum );

// static allocations
void *(*pfnMemAlloc)( size_t cb, const char *filename, const int fileline );
void (*pfnMemFree)( void *mem, const char *filename, const int fileline );

// trace & contents
int (*pfnMaskPointContents)( const float *pos, int groupmask );
struct trace_t (*pfnTrace)( const float *p0, float *mins, float *maxs, const float *p1, int type, edict_t *e );
struct trace_t (*pfnTraceNoEnts)( const float *p0, float *mins, float *maxs, const float *p1, int type, edict_t *e );
int (*pfnBoxInPVS)( const float *org, const float *boxmins, const float *boxmaxs );

// message handler (missed function to write raw bytes)
void (*pfnWriteBytes)( const byte *bytes, int count );

// BSP lump management
int (*pfnCheckLump)( const char *filename, const int lump, int *lumpsize );
int (*pfnReadLump)( const char *filename, const int lump, void **lumpdata, int *lumpsize );
int (*pfnSaveLump)( const char *filename, const int lump, void *lumpdata, int lumpsize );

// FS tools
int (*pfnSaveFile)( const char *filename, const void *data, int len );
const byte *(*pfnLoadImagePixels)( const char *filename, int *width, int *height );

const char* (*pfnGetModelName)( int modelindex );
typedef struct server_physics_api_s {
// unlink edict from old position and link onto new
void (*pfnLinkEdict) (edict_t *ent, qboolean touch_triggers);
double (*pfnGetServerTime)(void); // unclamped
double (*pfnGetFrameTime)(void); // unclamped
void *(*pfnGetModel)(int modelindex);
areanode_t *(*pfnGetHeadnode)(void); // AABB tree for all physic entities
int (*pfnServerState)(void);
void (*pfnHost_Error)(const char *error, ...); // cause Host Error
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 6
struct triangleapi_s *pTriAPI; // draw coliisions etc. Only for local system

// draw debug messages (must be called from DrawOrthoTriangles). Only for local system
int (*pfnDrawConsoleString)(int x, int y, char *string);
void (*pfnDrawSetTextColor)(float r, float g, float b);
void (*pfnDrawConsoleStringLen)(const char *string, int *length, int *height);
void (*Con_NPrintf)(int pos, const char *fmt, ...);
void (*Con_NXPrintf)(struct con_nprint_s *info, const char *fmt, ...);
const char *(*pfnGetLightStyle)(int style); // read custom appreance for selected lightstyle
void (*pfnUpdateFogSettings)(unsigned int packed_fog);
char **(*pfnGetFilesList)(const char *pattern, int *numFiles, int gamedironly);
struct msurface_s *(*pfnTraceSurface)(edict_t *pTextureEntity, const float *v1, const float *v2);
const byte *(*pfnGetTextureData)(unsigned int texnum);

// static allocations
void *(*pfnMemAlloc)(size_t cb, const char *filename, const int fileline);
void (*pfnMemFree)(void *mem, const char *filename, const int fileline);

// trace & contents
int (*pfnMaskPointContents)(const float *pos, int groupmask);
struct trace_t (*pfnTrace)(const float *p0, float *mins, float *maxs, const float *p1, int type, edict_t *e);
struct trace_t (*pfnTraceNoEnts)(const float *p0, float *mins, float *maxs, const float *p1, int type, edict_t *e);
int (*pfnBoxInPVS)(const float *org, const float *boxmins, const float *boxmaxs);

// message handler (missed function to write raw bytes)
void (*pfnWriteBytes)(const byte *bytes, int count);

// BSP lump management
int (*pfnCheckLump)(const char *filename, const int lump, int *lumpsize);
int (*pfnReadLump)(const char *filename, const int lump, void **lumpdata, int *lumpsize);
int (*pfnSaveLump)(const char *filename, const int lump, void *lumpdata, int lumpsize);

// FS tools
int (*pfnSaveFile)(const char *filename, const void *data, int len);
const byte *(*pfnLoadImagePixels)(const char *filename, int *width, int *height);

const char *(*pfnGetModelName)(int modelindex);
} server_physics_api_t;

// physic callbacks
typedef struct physics_interface_s
{
int version;
// passed through pfnCreate (0 is attempt to create, -1 is reject)
int ( *SV_CreateEntity )( edict_t *pent, const char *szName );
// run custom physics for each entity (return 0 to use built-in engine physic)
int ( *SV_PhysicsEntity )( edict_t *pEntity );
// spawn entities with internal mod function e.g. for re-arrange spawn order (0 - use engine parser, 1 - use mod parser)
int ( *SV_LoadEntities )( const char *mapname, char *entities );
// update conveyor belt for clients
void ( *SV_UpdatePlayerBaseVelocity )( edict_t *ent );
// The game .dll should return 1 if save game should be allowed
int ( *SV_AllowSaveGame )( void );
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 6
// override trigger area checking and touching
int ( *SV_TriggerTouch )( edict_t *pent, edict_t *trigger );
// some engine features can be enabled only through this function
unsigned int ( *SV_CheckFeatures )( void );
// used for draw debug collisions for custom physic engine etc
void ( *DrawDebugTriangles )( void );
// used for draw debug overlay (textured)
void ( *DrawNormalTriangles )( void );
// used for draw debug messages (2d mode)
void ( *DrawOrthoTriangles )( void );
// tracing entities with SOLID_CUSTOM mode on a server (not used by pmove code)
void ( *ClipMoveToEntity)( edict_t *ent, const float *start, float *mins, float *maxs, const float *end, trace_t *trace );
// tracing entities with SOLID_CUSTOM mode on a server (only used by pmove code)
void ( *ClipPMoveToEntity)( struct physent_s *pe, const float *start, float *mins, float *maxs, const float *end, struct pmtrace_s *tr );
// called at end the frame of SV_Physics call
void ( *SV_EndFrame )( void );
// obsolete
void (*pfnPrepWorldFrame)( void );
// called through save\restore process
void (*pfnCreateEntitiesInRestoreList)( SAVERESTOREDATA *pSaveData, int levelMask, qboolean create_world );
// allocate custom string (e.g. using user implementation of stringtable, not engine strings)
string_t (*pfnAllocString)( const char *szValue );
// make custom string (e.g. using user implementation of stringtable, not engine strings)
string_t (*pfnMakeString)( const char *szValue );
// read custom string (e.g. using user implementation of stringtable, not engine strings)
const char* (*pfnGetString)( string_t iString );
// helper for restore custom decals that have custom message (e.g. Paranoia)
int (*pfnRestoreDecal)( struct decallist_s *entry, edict_t *pEdict, qboolean adjacent );
// handle custom trigger touching for player
void (*PM_PlayerTouch)( struct playermove_s *ppmove, edict_t *client );
// alloc or destroy model custom data (called only for dedicated servers, otherwise using an client version)
void (*Mod_ProcessUserData)( struct model_s *mod, qboolean create, const byte *buffer );
// select BSP-hull for trace with specified mins\maxs
void *(*SV_HullForBsp)( edict_t *ent, const float *mins, const float *maxs, float *offset );
// handle player custom think function
int (*SV_PlayerThink)( edict_t *ent, float frametime, double time );
typedef struct physics_interface_s {
int version;
// passed through pfnCreate (0 is attempt to create, -1 is reject)
int (*SV_CreateEntity)(edict_t *pent, const char *szName);
// run custom physics for each entity (return 0 to use built-in engine physic)
int (*SV_PhysicsEntity)(edict_t *pEntity);
// spawn entities with internal mod function e.g. for re-arrange spawn order (0 - use engine parser, 1 - use mod parser)
int (*SV_LoadEntities)(const char *mapname, char *entities);
// update conveyor belt for clients
void (*SV_UpdatePlayerBaseVelocity)(edict_t *ent);
// The game .dll should return 1 if save game should be allowed
int (*SV_AllowSaveGame)(void);
// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 6
// override trigger area checking and touching
int (*SV_TriggerTouch)(edict_t *pent, edict_t *trigger);
// some engine features can be enabled only through this function
unsigned int (*SV_CheckFeatures)(void);
// used for draw debug collisions for custom physic engine etc
void (*DrawDebugTriangles)(void);
// used for draw debug overlay (textured)
void (*DrawNormalTriangles)(void);
// used for draw debug messages (2d mode)
void (*DrawOrthoTriangles)(void);
// tracing entities with SOLID_CUSTOM mode on a server (not used by pmove code)
void (*ClipMoveToEntity)(edict_t *ent, const float *start, float *mins, float *maxs, const float *end, trace_t *trace);
// tracing entities with SOLID_CUSTOM mode on a server (only used by pmove code)
void (*ClipPMoveToEntity)(struct physent_s *pe, const float *start, float *mins, float *maxs, const float *end, struct pmtrace_s *tr);
// called at end the frame of SV_Physics call
void (*SV_EndFrame)(void);
// obsolete
void (*pfnPrepWorldFrame)(void);
// called through save\restore process
void (*pfnCreateEntitiesInRestoreList)(SAVERESTOREDATA *pSaveData, int levelMask, qboolean create_world);
// allocate custom string (e.g. using user implementation of stringtable, not engine strings)
string_t (*pfnAllocString)(const char *szValue);
// make custom string (e.g. using user implementation of stringtable, not engine strings)
string_t (*pfnMakeString)(const char *szValue);
// read custom string (e.g. using user implementation of stringtable, not engine strings)
const char *(*pfnGetString)(string_t iString);
// helper for restore custom decals that have custom message (e.g. Paranoia)
int (*pfnRestoreDecal)(struct decallist_s *entry, edict_t *pEdict, qboolean adjacent);
// handle custom trigger touching for player
void (*PM_PlayerTouch)(struct playermove_s *ppmove, edict_t *client);
// alloc or destroy model custom data (called only for dedicated servers, otherwise using an client version)
void (*Mod_ProcessUserData)(struct model_s *mod, qboolean create, const byte *buffer);
// select BSP-hull for trace with specified mins\maxs
void *(*SV_HullForBsp)(edict_t *ent, const float *mins, const float *maxs, float *offset);
// handle player custom think function
int (*SV_PlayerThink)(edict_t *ent, float frametime, double time);
} physics_interface_t;

#endif//PHYSINT_H
6 changes: 4 additions & 2 deletions inc/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class Game final : public Singleton <Game> {
// initialize levels
void levelInitialize (edict_t *entities, int max);

// shutdown levels
void levelShutdown ();

// display world line
void drawLine (edict_t *ent, const Vector &start, const Vector &end, int width, int noise, const Color &color, int brightness, int speed, int life, DrawLine type = DrawLine::Simple);

Expand Down Expand Up @@ -688,8 +691,7 @@ class EntityLinkage : public Singleton <EntityLinkage> {
int close (DLSYM_HANDLE module) {
if (m_self.handle () == module) {
disable ();

return m_dlclose (module);
return m_dlclose (module);
}
return m_dlclose (module);
}
Expand Down
9 changes: 0 additions & 9 deletions inc/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class BotGraph final : public Singleton <BotGraph> {
int m_lastJumpNode {};
int m_findWPIndex {};
int m_facingAtIndex {};
int m_highestDamage[kGameTeamNum] {};
int m_autoSaveCount {};

float m_timeJumpStarted {};
Expand Down Expand Up @@ -265,14 +264,6 @@ class BotGraph final : public Singleton <BotGraph> {
return m_paths.length () / 2;
}

int getHighestDamageForTeam (int team) const {
return cr::max (1, m_highestDamage[team]);
}

void setHighestDamageForTeam (int team, int value) {
m_highestDamage[team] = value;
}

StringRef getAuthor () const {
return m_graphAuthor;
}
Expand Down
Loading

0 comments on commit a616f25

Please sign in to comment.