Support for getting correct light-level for waypoints. Thanks to Immortal_BLG for light-level calculation code.

This commit is contained in:
Dmitry 2019-05-10 01:33:17 +03:00 committed by jeefo
commit 7ebf1b6ef4
10 changed files with 500 additions and 17 deletions

View file

@ -361,6 +361,20 @@ public:
}
};
class SimpleColor final : private NonCopyable
{
public:
int red, green, blue;
inline void reset (void) {
red = green = blue = 0;
}
inline const int avg (void) const {
return (red + green + blue) / (sizeof (SimpleColor) / sizeof (int));
}
};
class Vector final {
public:
float x, y, z;
@ -380,15 +394,15 @@ public:
return &x;
}
inline const Vector operator+ (const Vector &right) const {
inline const Vector operator + (const Vector &right) const {
return Vector (x + right.x, y + right.y, z + right.z);
}
inline const Vector operator- (const Vector &right) const {
inline const Vector operator - (const Vector &right) const {
return Vector (x - right.x, y - right.y, z - right.z);
}
inline const Vector operator- (void) const {
inline const Vector operator - (void) const {
return Vector (-x, -y, -z);
}
@ -396,26 +410,26 @@ public:
return Vector (right.x * vec, right.y * vec, right.z * vec);
}
inline const Vector operator* (float vec) const {
inline const Vector operator * (float vec) const {
return Vector (vec * x, vec * y, vec * z);
}
inline const Vector operator/ (float vec) const {
inline const Vector operator / (float vec) const {
const float inv = 1 / vec;
return Vector (inv * x, inv * y, inv * z);
}
// cross product
inline const Vector operator^ (const Vector &right) const {
inline const Vector operator ^ (const Vector &right) const {
return Vector (y * right.z - z * right.y, z * right.x - x * right.z, x * right.y - y * right.x);
}
// dot product
inline float operator| (const Vector &right) const {
inline float operator | (const Vector &right) const {
return x * right.x + y * right.y + z * right.z;
}
inline const Vector &operator+= (const Vector &right) {
inline const Vector &operator += (const Vector &right) {
x += right.x;
y += right.y;
z += right.z;
@ -423,7 +437,7 @@ public:
return *this;
}
inline const Vector &operator-= (const Vector &right) {
inline const Vector &operator -= (const Vector &right) {
x -= right.x;
y -= right.y;
z -= right.z;
@ -431,7 +445,7 @@ public:
return *this;
}
inline const Vector &operator*= (float vec) {
inline const Vector &operator *= (float vec) {
x *= vec;
y *= vec;
z *= vec;
@ -439,7 +453,7 @@ public:
return *this;
}
inline const Vector &operator/= (float vec) {
inline const Vector &operator /= (float vec) {
const float inv = 1 / vec;
x *= inv;
@ -449,15 +463,15 @@ public:
return *this;
}
inline bool operator== (const Vector &right) const {
inline bool operator == (const Vector &right) const {
return fequal (x, right.x) && fequal (y, right.y) && fequal (z, right.z);
}
inline bool operator!= (const Vector &right) const {
inline bool operator != (const Vector &right) const {
return !fequal (x, right.x) && !fequal (y, right.y) && !fequal (z, right.z);
}
inline const Vector &operator= (const Vector &right) {
inline const Vector &operator = (const Vector &right) {
x = right.x;
y = right.y;
z = right.z;

View file

@ -395,3 +395,43 @@ public:
return cr::clamp <short> (static_cast <short> (value * scale), -32767, 32767);
}
};
class LightMeasure final : public Singleton <LightMeasure> {
private:
lightstyle_t m_lightstyle[MAX_LIGHTSTYLES];
int m_lightstyleValue[MAX_LIGHTSTYLEVALUE];
bool m_doAnimation;
SimpleColor m_point;
model_t *m_worldModel;
public:
LightMeasure (void) : m_worldModel (nullptr), m_doAnimation (false) {
initializeLightstyles ();
m_point.reset ();
}
public:
void initializeLightstyles (void);
void animateLight (void);
bool recursiveLightPoint (const mnode_t *node, const Vector &start, const Vector &end);
float getLightLevel (const Vector &point);
public:
inline void resetWorldModel (void) {
m_worldModel = nullptr;
}
inline void setWorldModel (model_t *model) {
if (m_worldModel) {
return;
}
m_worldModel = model;
}
inline void enableAnimation (bool enable) {
m_doAnimation = enable;
}
};

View file

@ -61,6 +61,7 @@ using namespace cr::types;
#include "const.h"
#include "progdefs.h"
#include "model.h"
#define MAX_ENT_LEAFS 48

218
include/engine/model.h Normal file
View file

@ -0,0 +1,218 @@
/***
*
* Copyright (c) 1999-2005, Valve Corporation. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* This source code contains proprietary and confidential information of
* Valve LLC and its suppliers. Access to this code is restricted to
* persons who have executed a written SDK license with Valve. Any access,
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
// stripped down version of com_model.h & pm_info.h
#ifndef MODEL_H
#define MODEL_H
typedef vec_t vec2_t[2];
typedef vec_t vec4_t[4];
typedef int qboolean;
typedef unsigned char byte;
#define VERTEXSIZE 7
#define MAXLIGHTMAPS 4
#define NUM_AMBIENTS 4
#define MAX_MAP_HULLS 4
#define MAX_PHYSINFO_STRING 256
#define MAX_PHYSENTS 600
#define MAX_MOVEENTS 64
#define MAX_LIGHTSTYLES 64
#define MAX_LIGHTSTYLEVALUE 256
#define SURF_DRAWTILED 0x20
typedef struct mplane_s {
vec3_t normal;
float dist;
byte type; // for fast side tests
byte signbits; // signx + (signy<<1) + (signz<<1)
byte pad[2];
} mplane_t;
typedef struct {
vec3_t position;
} mvertex_t;
typedef struct {
float vecs[2][4]; // [s/t] unit vectors in world space [i][3] is the s/t offset relative to the origin s or t = dot( 3Dpoint, vecs[i] ) + vecs[i][3]
float mipadjust; // mipmap limits for very small surfaces
struct texture_t* texture;
int flags; // sky or slime, no lightmap or 256 subdivision
} mtexinfo_t;
typedef struct mnode_s {
int contents; // 0, to differentiate from leafs
int visframe; // node needs to be traversed if current
float minmaxs[6]; // for bounding box culling
struct mnode_s* parent;
mplane_t* plane;
struct mnode_s* children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct {
byte r, g, b;
} color24;
typedef struct msurface_s {
int visframe; // should be drawn when node is crossed
mplane_t* plane; // pointer to shared plane
int flags; // see SURF_ #defines
int firstedge; // look up in model->surfedges[], negative numbers
int numedges; // are backwards edges
short texturemins[2];
short extents[2];
int light_s, light_t; // gl lightmap coordinates
struct glpoly_t* polys; // multiple if warped
struct msurface_s* texturechain;
mtexinfo_t* texinfo;
int dlightframe; // last frame the surface was checked by an animated light
int dlightbits; // dynamically generated. Indicates if the surface illumination is modified by an animated light.
int lightmaptexturenum;
byte styles[MAXLIGHTMAPS];
int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
msurface_s* lightmapchain; // for new dlights rendering (was cached_dlight)
color24* samples; // note: this is the actual lightmap data for this surface
struct decal_t* pdecals;
} msurface_t;
typedef struct cache_user_s {
void* data; // extradata
} cache_user_t;
typedef struct hull_s {
struct dclipnode_t* clipnodes;
mplane_t* planes;
int firstclipnode;
int lastclipnode;
vec3_t clip_mins;
vec3_t clip_maxs;
} hull_t;
typedef struct model_s {
char name[64]; // model name
qboolean needload; // bmodels and sprites don't cache normally
int type; // model type
int numframes; // sprite's framecount
byte* mempool; // private mempool (was synctype)
int flags; // hl compatibility
vec3_t mins, maxs; // bounding box at angles '0 0 0'
float radius;
int firstmodelsurface;
int nummodelsurfaces;
int numsubmodels;
struct dmodel_t* submodels; // or studio animations
int numplanes;
mplane_t* planes;
int numleafs; // number of visible leafs, not counting 0
struct mleaf_t* leafs;
int numvertexes;
mvertex_t* vertexes;
int numedges;
struct medge_t* edges;
int numnodes;
mnode_t* nodes;
int numtexinfo;
mtexinfo_t* texinfo;
int numsurfaces;
msurface_t* surfaces;
int numsurfedges;
int* surfedges;
int numclipnodes;
struct dclipnode_t* clipnodes;
int nummarksurfaces;
msurface_t** marksurfaces;
hull_t hulls[MAX_MAP_HULLS];
int numtextures;
texture_t** textures;
byte* visdata;
color24* lightdata;
char* entities;
cache_user_t cache; // only access through Mod_Extradata
} model_t;
struct lightstyle_t {
int length;
char map[MAX_LIGHTSTYLES];
};
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
} physent_t;
typedef struct playermove_s {
int player_index; // So we don't try to run the PM_CheckStuck nudging too quickly.
qboolean server; // For debugging, are we running physics code on server side?
qboolean multiplayer; // 1 == multiplayer server
float time; // realtime on host, for reckoning duck timing
float frametime; // Duration of this frame
vec3_t forward, right, up; // Vectors for angles
vec3_t origin; // Movement origin.
vec3_t angles; // Movement view angles.
vec3_t oldangles; // Angles before movement view angles were looked at.
vec3_t velocity; // Current movement direction.
vec3_t movedir; // For waterjumping, a forced forward velocity so we can fly over lip of ledge.
vec3_t basevelocity; // Velocity of the conveyor we are standing, e.g.
vec3_t view_ofs; // Our eye position.
float flDuckTime; // Time we started duck
qboolean bInDuck; // In process of ducking or ducked already?
int flTimeStepSound; // Next time we can play a step sound
int iStepLeft;
float flFallVelocity;
vec3_t punchangle;
float flSwimTime;
float flNextPrimaryAttack;
int effects; // MUZZLE FLASH, e.g.
int flags; // FL_ONGROUND, FL_DUCKING, etc.
int usehull; // 0 = regular player hull, 1 = ducked player hull, 2 = point hull
float gravity; // Our current gravity and friction.
float friction;
int oldbuttons; // Buttons last usercmd
float waterjumptime; // Amount of time left in jumping out of water cycle.
qboolean dead; // Are we a dead player?
int deadflag;
int spectator; // Should we use spectator physics model?
int movetype; // Our movement type, NOCLIP, WALK, FLY
int onground;
int waterlevel;
int watertype;
int oldwaterlevel;
char sztexturename[256];
char chtexturetype;
float maxspeed;
float clientmaxspeed; // Player specific maxspeed
int iuser1;
int iuser2;
int iuser3;
int iuser4;
float fuser1;
float fuser2;
float fuser3;
float fuser4;
vec3_t vuser1;
vec3_t vuser2;
vec3_t vuser3;
vec3_t vuser4;
int numphysent;
physent_t physents[MAX_PHYSENTS];
} playermove_t;
#endif

View file

@ -1431,6 +1431,7 @@ private:
float m_pathDisplayTime;
float m_arrowDisplayTime;
float m_waypointDisplayTime[MAX_WAYPOINTS];
float m_waypointLightLevel[MAX_WAYPOINTS];
int m_findWPIndex;
int m_facingAtIndex;
char m_infoBuffer[MAX_PRINT_BUFFER];
@ -1458,6 +1459,7 @@ public:
void initExperience (void);
void initVisibility (void);
void initTypes (void);
void initLightLevels (void);
void addPath (int addIndex, int pathIndex, float distance);
@ -1544,6 +1546,11 @@ public:
return m_numWaypoints;
}
// get the light level of waypoint
inline float getLightLevel (int id) const {
return m_waypointLightLevel[id];
}
// free's socket handle
void closeSocket (int sock);
@ -1567,6 +1574,7 @@ static auto &waypoints = Waypoint::ref ();
static auto &bots = BotManager::ref ();
static auto &engine = Engine::ref ();
static auto &rng = RandomSequence::ref ();
static auto &illum = LightMeasure::ref ();
// prototypes of bot functions...
extern int getWeaponData (bool isString, const char *weaponAlias, int weaponIndex = -1);