LCOV - code coverage report
Current view: top level - engine/world - entities.cpp (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 76.2 % 126 96
Test Date: 2025-11-24 07:55:42 Functions: 58.3 % 24 14

            Line data    Source code
       1              : /**
       2              :  * @brief Definition of methods in ents.h shared header.
       3              :  *
       4              :  * This file implements the behavior in the ents.h interface header.
       5              :  */
       6              : #include "../libprimis-headers/cube.h"
       7              : #include "../../shared/geomexts.h"
       8              : 
       9              : #include <memory>
      10              : #include <optional>
      11              : 
      12              : #include "entities.h"
      13              : #include "bih.h"
      14              : #include "interface/control.h"
      15              : 
      16              : #include "model/model.h"
      17              : #include "model/ragdoll.h"
      18              : 
      19              : //extentity
      20              : 
      21            0 : extentity::extentity() :
      22            0 :             flags(0),
      23            0 :             attached(nullptr)
      24              : {
      25            0 : }
      26              : 
      27            0 : bool extentity::spawned() const
      28              : {
      29            0 :     return (flags&EntFlag_Spawned) != 0;
      30              : }
      31              : 
      32            0 : void extentity::setspawned(bool val)
      33              : {
      34            0 :     if(val)
      35              :     {
      36            0 :         flags |= EntFlag_Spawned;
      37              :     }
      38              :     else
      39              :     {
      40            0 :         flags &= ~EntFlag_Spawned;
      41              :     }
      42            0 : }
      43              : 
      44            0 : void extentity::setspawned()
      45              : {
      46            0 :     flags |= EntFlag_Spawned;
      47            0 : }
      48              : 
      49            0 : void extentity::clearspawned()
      50              : {
      51            0 :     flags &= ~EntFlag_Spawned;
      52            0 : }
      53              : 
      54              : //physent
      55              : 
      56            4 : physent::physent() :
      57            4 :             o(0, 0, 0),
      58            4 :             deltapos(0, 0, 0),
      59            4 :             newpos(0, 0, 0),
      60            4 :             yaw(0),
      61            4 :             pitch(0),
      62            4 :             roll(0),
      63            4 :             maxspeed(35),
      64            4 :             radius(4.0f),
      65            4 :             eyeheight(14),
      66            4 :             maxheight(15),
      67            4 :             aboveeye(2),
      68            4 :             xradius(4.1f),
      69            4 :             yradius(4.1f),
      70            4 :             zmargin(0),
      71            4 :             state(0),
      72            4 :             editstate(0),
      73            4 :             type(PhysEnt_Player),
      74            4 :             collidetype(Collide_Ellipse),
      75            8 :             blocked(false)
      76              : {
      77            4 :     reset();
      78            4 : }
      79              : 
      80            0 : void physent::resetinterp()
      81              : {
      82            0 :     newpos = o;
      83            0 :     deltapos = vec(0, 0, 0);
      84            0 : }
      85              : 
      86            6 : void physent::reset()
      87              : {
      88            6 :     inwater = 0;
      89            6 :     timeinair = 0;
      90            6 :     eyeheight = maxheight;
      91            6 :     jumping = false;
      92            6 :     strafe = move = crouching = 0;
      93            6 :     physstate = PhysEntState_Fall;
      94            6 :     vel = falling = vec(0, 0, 0);
      95            6 :     floor = vec(0, 0, 1);
      96            6 : }
      97              : 
      98            0 : vec physent::feetpos(float offset) const
      99              : {
     100            0 :     return vec(o).addz(offset - eyeheight);
     101              : }
     102            0 : vec physent::headpos(float offset) const
     103              : {
     104            0 :     return vec(o).addz(offset);
     105              : }
     106              : 
     107            0 : bool physent::crouched() const
     108              : {
     109            0 :     return std::fabs(eyeheight - maxheight*crouchheight) < 1e-4f;
     110              : }
     111              : 
     112              : //modelattach
     113              : 
     114            1 : modelattach::modelattach() :
     115            1 :                 tag(nullptr),
     116            1 :                 name(nullptr),
     117            1 :                 anim(-1),
     118            1 :                 basetime(0),
     119            1 :                 pos(nullptr),
     120            1 :                 m(nullptr)
     121              : {
     122            1 : }
     123              : 
     124            1 : modelattach::modelattach(const char *tag, const char *name, int anim, int basetime) :
     125            1 :                 tag(tag),
     126            1 :                 name(name),
     127            1 :                 anim(anim),
     128            1 :                 basetime(basetime),
     129            1 :                 pos(nullptr),
     130            1 :                 m(nullptr)
     131              : {
     132            1 : }
     133              : 
     134            1 : modelattach::modelattach(const char *tag, vec *pos) :
     135            1 :                 tag(tag),
     136            1 :                 name(nullptr),
     137            1 :                 anim(-1),
     138            1 :                 basetime(0),
     139            1 :                 pos(pos),
     140            1 :                 m(nullptr)
     141              : {
     142            1 : }
     143              : 
     144              : //animinfo
     145              : 
     146           47 : animinfo::animinfo() : anim(0), frame(0), range(0), basetime(0), speed(100.0f), varseed(0)
     147              : {
     148           47 : }
     149              : 
     150           17 : bool animinfo::operator==(const animinfo &o) const
     151              : {
     152           17 :     return frame==o.frame
     153           15 :         && range==o.range
     154           13 :         && (anim&(Anim_SetTime | Anim_Dir)) == (o.anim & (Anim_SetTime | Anim_Dir))
     155            9 :         && (anim & Anim_SetTime || basetime == o.basetime)
     156           32 :         && speed == o.speed;
     157              : }
     158              : 
     159           17 : bool animinfo::operator!=(const animinfo &o) const
     160              : {
     161           17 :     return frame!=o.frame
     162           15 :         || range!=o.range
     163           13 :         || (anim&(Anim_SetTime | Anim_Dir)) != (o.anim & (Anim_SetTime | Anim_Dir))
     164            9 :         || (!(anim & Anim_SetTime) && basetime != o.basetime)
     165           32 :         || speed != o.speed;
     166              : }
     167              : 
     168              : //animinterpinfo
     169              : 
     170            6 : animinterpinfo::animinterpinfo() :
     171            6 :                     lastswitch(-1),
     172            6 :                     lastmodel(nullptr)
     173              : {
     174            6 : }
     175              : 
     176            6 : void animinterpinfo::reset()
     177              : {
     178            6 :     lastswitch = -1;
     179            6 : }
     180              : 
     181              : //dynent
     182              : 
     183            2 : dynent::dynent() :
     184            2 :         ragdoll(nullptr),
     185            2 :         query(nullptr),
     186            8 :         lastrendered(0)
     187              : {
     188            2 :     reset();
     189            2 : }
     190              : 
     191            2 : dynent::~dynent()
     192              : {
     193            2 :     if(ragdoll)
     194              :     {
     195            0 :         cleanragdoll(this);
     196              :     }
     197            2 : }
     198              : 
     199            2 : void dynent::stopmoving()
     200              : {
     201            2 :     k_left = k_right = k_up = k_down = jumping = false;
     202            2 :     move = strafe = crouching = 0;
     203            2 : }
     204              : 
     205            2 : void dynent::reset()
     206              : {
     207            2 :     physent::reset();
     208            2 :     stopmoving();
     209            8 :     for(size_t i = 0; i < maxanimparts; ++i)
     210              :     {
     211            6 :         animinterp[i].reset();
     212              :     }
     213            2 : }
     214              : 
     215            0 : vec dynent::abovehead() const
     216              : {
     217            0 :     return vec(o).addz(aboveeye+4);
     218              : }
        

Generated by: LCOV version 2.0-1