RigsofRods
Soft-body Physics Simulation
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 <OgreUTFString.h>
28 #include <OgreMeshManager.h>
29 #include <OgreTimer.h>
30 #include <string>
31 
32 namespace RoR {
33 
36 
39 
40 class Character
41 {
42 public:
43 
44  Character(int source = -1, unsigned int streamid = 0, Ogre::UTFString playerName = "", int color_number = 0, bool is_remote = true);
45  ~Character();
46 
47  int getSourceID() const { return m_source_id; }
48  bool isRemote() const { return m_is_remote; }
49  int GetColorNum() const { return m_color_number; }
50  bool GetIsRemote() const { return m_is_remote; }
51  Ogre::UTFString const& GetNetUsername() { return m_net_username; }
52  std::string const & GetAnimName() const { return m_anim_name; }
53  float GetAnimTime() const { return m_anim_time; }
54  Ogre::Radian getRotation() const { return m_character_rotation; }
56  void setColour(int color) { this->m_color_number = color; }
57  Ogre::Vector3 getPosition();
58  void setPosition(Ogre::Vector3 position);
59  void setRotation(Ogre::Radian rotation);
60  void move(Ogre::Vector3 offset);
61  void update(float dt);
63  void receiveStreamData(unsigned int& type, int& source, unsigned int& streamid, char* buffer);
64  void SetActorCoupling(bool enabled, ActorPtr actor);
66 
67 private:
68 
69  void ReportError(const char* detail);
70  void SendStreamData();
71  void SendStreamSetup();
72  void SetAnimState(std::string mode, float time = 0);
73 
75  Ogre::Radian m_character_rotation;
78  Ogre::Vector3 m_character_position;
79  Ogre::Vector3 m_prev_position;
83  bool m_can_jump;
85  std::string m_anim_name;
86  float m_anim_time;
89  std::string m_instance_name;
90  Ogre::UTFString m_net_username;
91  Ogre::Timer m_net_timer;
92  unsigned long m_net_last_update_time;
94 };
95 
98 
100 {
101  struct SimBuffer
102  {
103  Ogre::Vector3 simbuf_character_pos;
104  Ogre::Radian simbuf_character_rot;
105  Ogre::UTFString simbuf_net_username;
109  std::string simbuf_anim_name;
110  float simbuf_anim_time; // Intentionally left empty = forces initial update.
111  };
112 
113  ~GfxCharacter();
114 
115  void BufferSimulationData();
116  void UpdateCharacterInScene();
117 
118  Ogre::SceneNode* xc_scenenode;
122  std::string xc_instance_name; // TODO: Store MaterialPtr-s directly ~only_a_ptr, 05/2018
124 };
125 
126 } // namespace RoR
127 
RoR::Character::getRotation
Ogre::Radian getRotation() const
Definition: Character.h:54
RoR::Character::m_net_username
Ogre::UTFString m_net_username
Definition: Character.h:90
RoR::GfxCharacter::SimBuffer::simbuf_color_number
int simbuf_color_number
Definition: Character.h:107
RoR::Character::setPosition
void setPosition(Ogre::Vector3 position)
Definition: Character.cpp:85
RoR::Character::setColour
void setColour(int color)
Definition: Character.h:56
ForwardDeclarations.h
Global forward declarations.
RoR::Character::m_character_v_speed
float m_character_v_speed
Definition: Character.h:77
RoR::GfxCharacter::xc_character
Character * xc_character
Definition: Character.h:121
RoR::GfxCharacter::SimBuffer::simbuf_net_username
Ogre::UTFString simbuf_net_username
Definition: Character.h:105
RoR::Character::m_color_number
int m_color_number
Definition: Character.h:80
RoR::Character::GetAnimName
const std::string & GetAnimName() const
Definition: Character.h:52
RoR::Character::SetAnimState
void SetAnimState(std::string mode, float time=0)
Definition: Character.cpp:103
RoR::GfxCharacter::xc_simbuf_prev
SimBuffer xc_simbuf_prev
Definition: Character.h:120
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:101
RoR::Character::m_character_position
Ogre::Vector3 m_character_position
Definition: Character.h:78
RoR::GfxCharacter::xc_instance_name
std::string xc_instance_name
Definition: Character.h:122
RoR::Character::SendStreamData
void SendStreamData()
Definition: Character.cpp:446
RoR::Character::m_stream_id
int m_stream_id
Definition: Character.h:81
SurveyMapEntity.h
RoR::GfxCharacter::xc_simbuf
SimBuffer xc_simbuf
Definition: Character.h:119
RoR::Character::GetActorCoupling
ActorPtr GetActorCoupling()
Definition: Character.cpp:547
RoR::Character::GetNetUsername
Ogre::UTFString const & GetNetUsername()
Definition: Character.h:51
RoR::Character::m_character_rotation
Ogre::Radian m_character_rotation
Definition: Character.h:75
RoR::GfxCharacter::UpdateCharacterInScene
void UpdateCharacterInScene()
Definition: Character.cpp:604
RoR::GfxCharacter::SimBuffer::simbuf_anim_name
std::string simbuf_anim_name
Definition: Character.h:109
RefCountingObjectPtr< Actor >
RoR::Character::m_is_remote
bool m_is_remote
Definition: Character.h:84
RoR::Character::SendStreamSetup
void SendStreamSetup()
Definition: Character.cpp:426
RoR::Character::GetAnimTime
float GetAnimTime() const
Definition: Character.h:53
RoR::GfxCharacter::SimBuffer::simbuf_character_rot
Ogre::Radian simbuf_character_rot
When on foot.
Definition: Character.h:104
RoR::GfxCharacter::SimBuffer::simbuf_actor_coupling
ActorPtr simbuf_actor_coupling
Definition: Character.h:108
RoR::Character::GetColorNum
int GetColorNum() const
Definition: Character.h:49
RoR::GfxCharacter::xc_scenenode
Ogre::SceneNode * xc_scenenode
Definition: Character.h:118
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:103
RoR::GfxCharacter
Definition: Character.h:99
RoR::Character::Character
Character(int source=-1, unsigned int streamid=0, Ogre::UTFString playerName="", int color_number=0, bool is_remote=true)
Definition: Character.cpp:43
RoR::Character
Definition: Character.h:40
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:86
RoR::Character::m_net_last_anim_time
float m_net_last_anim_time
Definition: Character.h:87
RoR::Character::getPosition
Ogre::Vector3 getPosition()
Definition: Character.cpp:92
RoR::GfxCharacter::xc_surveymap_entity
SurveyMapEntity xc_surveymap_entity
Definition: Character.h:123
RoR::Character::m_instance_name
std::string m_instance_name
Definition: Character.h:89
RoR::GfxCharacter::SimBuffer::simbuf_is_remote
bool simbuf_is_remote
Definition: Character.h:106
RoR::Character::isRemote
bool isRemote() const
Definition: Character.h:48
RoR::Character::GetIsRemote
bool GetIsRemote() const
Definition: Character.h:50
RoR::Character::m_source_id
int m_source_id
Definition: Character.h:82
RoR::GfxCharacter::BufferSimulationData
void BufferSimulationData()
Definition: Character.cpp:590
RoR::Character::m_driving_anim_length
float m_driving_anim_length
Definition: Character.h:88
RoR::GfxCharacter::~GfxCharacter
~GfxCharacter()
Definition: Character.cpp:581
RoR::GfxCharacter::SimBuffer::simbuf_anim_time
float simbuf_anim_time
Definition: Character.h:110
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:76
RoR::Character::m_gfx_character
GfxCharacter * m_gfx_character
Definition: Character.h:93
RoR::Character::m_anim_name
std::string m_anim_name
Definition: Character.h:85
RoR::Character::m_can_jump
bool m_can_jump
Definition: Character.h:83
RoR::Character::~Character
~Character()
Definition: Character.cpp:71
RoR::Character::m_net_timer
Ogre::Timer m_net_timer
Definition: Character.h:91
RoR::Character::getSourceID
int getSourceID() const
Definition: Character.h:47
RoR::Character::m_prev_position
Ogre::Vector3 m_prev_position
Definition: Character.h:79
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:74
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:92
RoR::Character::SetupGfx
GfxCharacter * SetupGfx()
Definition: Character.cpp:552