RigsofRods
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Character.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2017-2018 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #pragma once
23 
24 #include "ForwardDeclarations.h"
25 #include "SurveyMapEntity.h"
26 
27 #include <OgreMeshManager.h>
28 #include <OgreTimer.h>
29 #include <string>
30 
31 namespace RoR {
32 
35 
38 
39 class Character
40 {
41 public:
42 
43  Character(int source = -1, unsigned int streamid = 0, std::string playerName = "", int color_number = 0, bool is_remote = true);
44  ~Character();
45 
46  int getSourceID() const { return m_source_id; }
47  bool isRemote() const { return m_is_remote; }
48  int GetColorNum() const { return m_color_number; }
49  bool GetIsRemote() const { return m_is_remote; }
50  std::string const& GetNetUsername() { return m_net_username; }
51  std::string const & GetAnimName() const { return m_anim_name; }
52  float GetAnimTime() const { return m_anim_time; }
53  Ogre::Radian getRotation() const { return m_character_rotation; }
55  void setColour(int color) { this->m_color_number = color; }
56  Ogre::Vector3 getPosition();
57  void setPosition(Ogre::Vector3 position);
58  void setRotation(Ogre::Radian rotation);
59  void move(Ogre::Vector3 offset);
60  void update(float dt);
62  void receiveStreamData(unsigned int& type, int& source, unsigned int& streamid, char* buffer);
63  void SetActorCoupling(bool enabled, ActorPtr actor);
65 
66 private:
67 
68  void ReportError(const char* detail);
69  void SendStreamData();
70  void SendStreamSetup();
71  void SetAnimState(std::string mode, float time = 0);
72 
74  Ogre::Radian m_character_rotation;
77  Ogre::Vector3 m_character_position;
78  Ogre::Vector3 m_prev_position;
82  bool m_can_jump;
84  std::string m_anim_name;
85  float m_anim_time;
88  std::string m_instance_name;
89  std::string m_net_username;
90  Ogre::Timer m_net_timer;
91  unsigned long m_net_last_update_time;
93 };
94 
97 
99 {
100  struct SimBuffer
101  {
102  Ogre::Vector3 simbuf_character_pos;
103  Ogre::Radian simbuf_character_rot;
104  std::string simbuf_net_username;
108  std::string simbuf_anim_name;
109  float simbuf_anim_time; // Intentionally left empty = forces initial update.
110  };
111 
112  ~GfxCharacter();
113 
114  void BufferSimulationData();
115  void UpdateCharacterInScene();
116 
117  Ogre::SceneNode* xc_scenenode;
121  std::string xc_instance_name; // TODO: Store MaterialPtr-s directly ~only_a_ptr, 05/2018
123 };
124 
125 } // namespace RoR
126 
RoR::Character::getRotation
Ogre::Radian getRotation() const
Definition: Character.h:53
RoR::GfxCharacter::SimBuffer::simbuf_color_number
int simbuf_color_number
Definition: Character.h:106
RoR::Character::setPosition
void setPosition(Ogre::Vector3 position)
Definition: Character.cpp:85
RoR::Character::setColour
void setColour(int color)
Definition: Character.h:55
ForwardDeclarations.h
Global forward declarations.
RoR::Character::m_character_v_speed
float m_character_v_speed
Definition: Character.h:76
RoR::GfxCharacter::xc_character
Character * xc_character
Definition: Character.h:120
RoR::Character::m_color_number
int m_color_number
Definition: Character.h:79
RoR::Character::GetAnimName
const std::string & GetAnimName() const
Definition: Character.h:51
RoR::Character::SetAnimState
void SetAnimState(std::string mode, float time=0)
Definition: Character.cpp:103
RoR::GfxCharacter::SimBuffer::simbuf_net_username
std::string simbuf_net_username
Definition: Character.h:104
RoR::GfxCharacter::xc_simbuf_prev
SimBuffer xc_simbuf_prev
Definition: Character.h:119
RoR::Character::update
void update(float dt)
Definition: Character.cpp:129
RoR::GfxCharacter::SimBuffer
< Buffered simulation state for async gfx scene update
Definition: Character.h:100
RoR::Character::m_character_position
Ogre::Vector3 m_character_position
Definition: Character.h:77
RoR::GfxCharacter::xc_instance_name
std::string xc_instance_name
Definition: Character.h:121
RoR::Character::SendStreamData
void SendStreamData()
Definition: Character.cpp:446
RoR::Character::m_stream_id
int m_stream_id
Definition: Character.h:80
SurveyMapEntity.h
RoR::GfxCharacter::xc_simbuf
SimBuffer xc_simbuf
Definition: Character.h:118
RoR::Character::GetActorCoupling
ActorPtr GetActorCoupling()
Definition: Character.cpp:547
RoR::Character::m_character_rotation
Ogre::Radian m_character_rotation
Definition: Character.h:74
RoR::Character::GetNetUsername
std::string const & GetNetUsername()
Definition: Character.h:50
RoR::Character::m_net_username
std::string m_net_username
Definition: Character.h:89
RoR::GfxCharacter::UpdateCharacterInScene
void UpdateCharacterInScene()
Definition: Character.cpp:604
RoR::GfxCharacter::SimBuffer::simbuf_anim_name
std::string simbuf_anim_name
Definition: Character.h:108
RefCountingObjectPtr< Actor >
RoR::Character::m_is_remote
bool m_is_remote
Definition: Character.h:83
RoR::Character::SendStreamSetup
void SendStreamSetup()
Definition: Character.cpp:426
RoR::Character::GetAnimTime
float GetAnimTime() const
Definition: Character.h:52
RoR::GfxCharacter::SimBuffer::simbuf_character_rot
Ogre::Radian simbuf_character_rot
When on foot.
Definition: Character.h:103
RoR::GfxCharacter::SimBuffer::simbuf_actor_coupling
ActorPtr simbuf_actor_coupling
Definition: Character.h:107
RoR::Character::GetColorNum
int GetColorNum() const
Definition: Character.h:48
RoR::GfxCharacter::xc_scenenode
Ogre::SceneNode * xc_scenenode
Definition: Character.h:117
RoR::Character::move
void move(Ogre::Vector3 offset)
Definition: Character.cpp:401
RoR::GfxCharacter::SimBuffer::simbuf_character_pos
Ogre::Vector3 simbuf_character_pos
Definition: Character.h:102
RoR::GfxCharacter
Definition: Character.h:98
RoR::Character
Definition: Character.h:39
RoR::Character::receiveStreamData
void receiveStreamData(unsigned int &type, int &source, unsigned int &streamid, char *buffer)
Definition: Character.cpp:473
RoR::Character::m_anim_time
float m_anim_time
Definition: Character.h:85
RoR::Character::m_net_last_anim_time
float m_net_last_anim_time
Definition: Character.h:86
RoR::Character::getPosition
Ogre::Vector3 getPosition()
Definition: Character.cpp:92
RoR::GfxCharacter::xc_surveymap_entity
SurveyMapEntity xc_surveymap_entity
Definition: Character.h:122
RoR::Character::m_instance_name
std::string m_instance_name
Definition: Character.h:88
RoR::GfxCharacter::SimBuffer::simbuf_is_remote
bool simbuf_is_remote
Definition: Character.h:105
RoR::Character::isRemote
bool isRemote() const
Definition: Character.h:47
RoR::Character::GetIsRemote
bool GetIsRemote() const
Definition: Character.h:49
RoR::Character::Character
Character(int source=-1, unsigned int streamid=0, std::string playerName="", int color_number=0, bool is_remote=true)
Definition: Character.cpp:43
RoR::Character::m_source_id
int m_source_id
Definition: Character.h:81
RoR::GfxCharacter::BufferSimulationData
void BufferSimulationData()
Definition: Character.cpp:590
RoR::Character::m_driving_anim_length
float m_driving_anim_length
Definition: Character.h:87
RoR::GfxCharacter::~GfxCharacter
~GfxCharacter()
Definition: Character.cpp:581
RoR::GfxCharacter::SimBuffer::simbuf_anim_time
float simbuf_anim_time
Definition: Character.h:109
RoR::Character::updateCharacterRotation
void updateCharacterRotation()
Definition: Character.cpp:80
RoR::Character::SetActorCoupling
void SetActorCoupling(bool enabled, ActorPtr actor)
Definition: Character.cpp:523
RoR::Character::m_character_h_speed
float m_character_h_speed
Definition: Character.h:75
RoR::Character::m_gfx_character
GfxCharacter * m_gfx_character
Definition: Character.h:92
RoR::Character::m_anim_name
std::string m_anim_name
Definition: Character.h:84
RoR::Character::m_can_jump
bool m_can_jump
Definition: Character.h:82
RoR::Character::~Character
~Character()
Definition: Character.cpp:71
RoR::Character::m_net_timer
Ogre::Timer m_net_timer
Definition: Character.h:90
RoR::Character::getSourceID
int getSourceID() const
Definition: Character.h:46
RoR::Character::m_prev_position
Ogre::Vector3 m_prev_position
Definition: Character.h:78
RoR::SurveyMapEntity
Definition: SurveyMapEntity.h:35
RoR
Definition: AppContext.h:36
RoR::Character::m_actor_coupling
ActorPtr m_actor_coupling
The vehicle or machine which the character occupies.
Definition: Character.h:73
RoR::Character::ReportError
void ReportError(const char *detail)
Definition: Character.cpp:407
RoR::Character::setRotation
void setRotation(Ogre::Radian rotation)
Definition: Character.cpp:98
RoR::Character::m_net_last_update_time
unsigned long m_net_last_update_time
Definition: Character.h:91
RoR::Character::SetupGfx
GfxCharacter * SetupGfx()
Definition: Character.cpp:552