1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef _PHYSICS_DRIVER_H_
14 #define _PHYSICS_DRIVER_H_
15 
16 #include "common.h"
17 
18 /* system interface headers */
19 #include <string>
20 #include <vector>
21 #include <iostream>
22 
23 
24 class PhysicsDriver
25 {
26 public:
27     PhysicsDriver();
28     ~PhysicsDriver();
29 
30     bool setName(const std::string& name);
31     void setLinear(const float vel[3]);
32     void setAngular(float angleVel, const float pos[2]);
33     void setRadial(float radialVel, const float pos[2]);
34     void setSlideTime(float slideTime);
35     void setDeathMessage(const std::string& msg);
36 
37     void finalize();
38     void update(float time);
39 
40     const std::string& getName() const;
41     const float* getLinearVel() const;
42     float getAngularVel() const;
43     const float* getAngularPos() const;
44     float getRadialVel() const;
45     const float* getRadialPos() const;
46     bool getIsSlide() const;
47     float getSlideTime() const;
48     bool getIsDeath() const;
49     const std::string& getDeathMsg() const;
50 
51     int packSize() const;
52     void* pack(void*) const;
53     const void* unpack(const void*);
54 
55     void print(std::ostream& out, const std::string& indent) const;
56 
57 private:
58     static const float minPeriod;
59 
60     std::string name;
61     float linear[3];
62     float angularVel;
63     float angularPos[2];
64     float radialVel;
65     float radialPos[2];
66     bool slide;
67     float slideTime;
68     bool death;
69     std::string deathMsg;
70 };
71 
getLinearVel()72 inline const float* PhysicsDriver::getLinearVel() const
73 {
74     return linear;
75 }
getAngularVel()76 inline float PhysicsDriver::getAngularVel() const
77 {
78     return angularVel;
79 }
getAngularPos()80 inline const float* PhysicsDriver::getAngularPos() const
81 {
82     return angularPos;
83 }
getRadialVel()84 inline float PhysicsDriver::getRadialVel() const
85 {
86     return radialVel;
87 }
getRadialPos()88 inline const float* PhysicsDriver::getRadialPos() const
89 {
90     return radialPos;
91 }
getIsSlide()92 inline bool PhysicsDriver::getIsSlide() const
93 {
94     return slide;
95 }
getSlideTime()96 inline float PhysicsDriver::getSlideTime() const
97 {
98     return slideTime;
99 }
getIsDeath()100 inline bool PhysicsDriver::getIsDeath() const
101 {
102     return death;
103 }
getDeathMsg()104 inline const std::string& PhysicsDriver::getDeathMsg() const
105 {
106     return deathMsg;
107 }
108 
109 
110 class PhysicsDriverManager
111 {
112 public:
113     PhysicsDriverManager();
114     ~PhysicsDriverManager();
115     void update();
116     void clear();
117     int addDriver(PhysicsDriver* driver);
118     int findDriver(const std::string& name) const;
119     const PhysicsDriver* getDriver(int id) const;
120 
121     int packSize() const;
122     void* pack(void*) const;
123     const void* unpack(const void*);
124 
125     void print(std::ostream& out, const std::string& indent) const;
126 
127 private:
128     std::vector<PhysicsDriver*> drivers;
129 };
130 
getDriver(int id)131 inline const PhysicsDriver* PhysicsDriverManager::getDriver(int id) const
132 {
133     if ((id >= 0) && (id < (int)drivers.size()))
134         return drivers[id];
135     else
136         return NULL;
137 }
138 
139 
140 extern PhysicsDriverManager PHYDRVMGR;
141 
142 
143 #endif //_PHYSICS_DRIVER_H_
144 
145 // Local Variables: ***
146 // mode: C++ ***
147 // tab-width: 4 ***
148 // c-basic-offset: 4 ***
149 // indent-tabs-mode: nil ***
150 // End: ***
151 // ex: shiftwidth=4 tabstop=4
152