LCOV - code coverage report
Current view: top level - engine/world - entities.cpp (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 47.6 % 126 60
Test Date: 2025-02-18 06:21:28 Functions: 37.5 % 24 9

            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            3 : physent::physent() :
      57            3 :             o(0, 0, 0),
      58            3 :             deltapos(0, 0, 0),
      59            3 :             newpos(0, 0, 0),
      60            3 :             yaw(0),
      61            3 :             pitch(0),
      62            3 :             roll(0),
      63            3 :             maxspeed(35),
      64            3 :             radius(4.0f),
      65            3 :             eyeheight(14),
      66            3 :             maxheight(15),
      67            3 :             aboveeye(2),
      68            3 :             xradius(4.1f),
      69            3 :             yradius(4.1f),
      70            3 :             zmargin(0),
      71            3 :             state(0),
      72            3 :             editstate(0),
      73            3 :             type(PhysEnt_Player),
      74            3 :             collidetype(Collide_Ellipse),
      75            6 :             blocked(false)
      76              : {
      77            3 :     reset();
      78            3 : }
      79              : 
      80            0 : void physent::resetinterp()
      81              : {
      82            0 :     newpos = o;
      83            0 :     deltapos = vec(0, 0, 0);
      84            0 : }
      85              : 
      86            5 : void physent::reset()
      87              : {
      88            5 :     inwater = 0;
      89            5 :     timeinair = 0;
      90            5 :     eyeheight = maxheight;
      91            5 :     jumping = false;
      92            5 :     strafe = move = crouching = 0;
      93            5 :     physstate = PhysEntState_Fall;
      94            5 :     vel = falling = vec(0, 0, 0);
      95            5 :     floor = vec(0, 0, 1);
      96            5 : }
      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            0 : modelattach::modelattach() :
     115            0 :                 tag(nullptr),
     116            0 :                 name(nullptr),
     117            0 :                 anim(-1),
     118            0 :                 basetime(0),
     119            0 :                 pos(nullptr),
     120            0 :                 m(nullptr)
     121              : {
     122            0 : }
     123              : 
     124            0 : modelattach::modelattach(const char *tag, const char *name, int anim, int basetime) :
     125            0 :                 tag(tag),
     126            0 :                 name(name),
     127            0 :                 anim(anim),
     128            0 :                 basetime(basetime),
     129            0 :                 pos(nullptr),
     130            0 :                 m(nullptr)
     131              : {
     132            0 : }
     133              : 
     134            0 : modelattach::modelattach(const char *tag, vec *pos) :
     135            0 :                 tag(tag),
     136            0 :                 name(nullptr),
     137            0 :                 anim(-1),
     138            0 :                 basetime(0),
     139            0 :                 pos(pos),
     140            0 :                 m(nullptr)
     141              : {
     142            0 : }
     143              : 
     144              : //animinfo
     145              : 
     146           12 : animinfo::animinfo() : anim(0), frame(0), range(0), basetime(0), speed(100.0f), varseed(0)
     147              : {
     148           12 : }
     149              : 
     150            0 : bool animinfo::operator==(const animinfo &o) const
     151              : {
     152            0 :     return frame==o.frame
     153            0 :         && range==o.range
     154            0 :         && (anim&(Anim_SetTime | Anim_Dir)) == (o.anim & (Anim_SetTime | Anim_Dir))
     155            0 :         && (anim & Anim_SetTime || basetime == o.basetime)
     156            0 :         && speed == o.speed;
     157              : }
     158              : 
     159            0 : bool animinfo::operator!=(const animinfo &o) const
     160              : {
     161            0 :     return frame!=o.frame
     162            0 :         || range!=o.range
     163            0 :         || (anim&(Anim_SetTime | Anim_Dir)) != (o.anim & (Anim_SetTime | Anim_Dir))
     164            0 :         || (!(anim & Anim_SetTime) && basetime != o.basetime)
     165            0 :         || 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