Skip to content

Commit

Permalink
Proof of concept: character anim config system.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Sep 24, 2022
1 parent ec463eb commit ec69f42
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 99 deletions.
2 changes: 2 additions & 0 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ set(SOURCE_FILES
resources/skin_fileformat/SkinFileFormat.{h,cpp}
resources/terrn2_fileformat/Terrn2FileFormat.{h,cpp}
resources/tobj_fileformat/TObjFileFormat.{h,cpp}
resources/character_def_fileformat/CharacterDefFileFormat.h
system/AppCommandLine.cpp
system/AppConfig.cpp
system/Console.{h,cpp}
Expand Down Expand Up @@ -334,6 +335,7 @@ target_include_directories(${BINNAME} PRIVATE
physics/utils
physics/water
resources
resources/character_def_fileformat
resources/odef_fileformat/
resources/otc_fileformat/
resources/rig_def_fileformat
Expand Down
3 changes: 2 additions & 1 deletion source/main/gameplay/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
using namespace Ogre;
using namespace RoR;

Character::Character(int source, unsigned int streamid, UTFString player_name, int color_number, bool is_remote) :
Character::Character(CharacterDefPtr def, int source, unsigned int streamid, UTFString player_name, int color_number, bool is_remote) :
m_actor_coupling(nullptr)
, m_character_rotation(0.0f)
, m_character_h_speed(2.0f)
Expand All @@ -50,6 +50,7 @@ Character::Character(int source, unsigned int streamid, UTFString player_name, i
, m_is_remote(is_remote)
, m_source_id(source)
, m_stream_id(streamid)
, m_character_def(def)
{
static int id_counter = 0;
m_instance_name = "Character" + TOSTRING(id_counter);
Expand Down
6 changes: 4 additions & 2 deletions source/main/gameplay/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#pragma once

#include "CharacterDefFileFormat.h"
#include "ForwardDeclarations.h"
#include "SimBuffers.h"

Expand All @@ -36,6 +37,7 @@ namespace RoR {

/// @addtogroup Character
/// @{
///

/// Character uses simplified physics and occupies single point in space.
/// Note on animations:
Expand Down Expand Up @@ -66,7 +68,7 @@ class Character
static const BitMask_t SITUATION_IN_AIR = BITMASK(4);
static const BitMask_t SITUATION_DRIVING = BITMASK(5);

Character(int source = -1, unsigned int streamid = 0, Ogre::UTFString playerName = "", int color_number = 0, bool is_remote = true);
Character(CharacterDefPtr def, int source = -1, unsigned int streamid = 0, Ogre::UTFString playerName = "", int color_number = 0, bool is_remote = true);
~Character();

// get state
Expand All @@ -78,7 +80,6 @@ class Character
void setRotation(Ogre::Radian rotation);
void move(Ogre::Vector3 offset);
void updateLocal(float dt);
void upateRemote(float dt);
void updateCharacterRotation();
void SetActorCoupling(bool enabled, Actor* actor);

Expand All @@ -97,6 +98,7 @@ class Character
void SendStreamSetup();

// attributes
CharacterDefPtr m_character_def;
std::string m_instance_name;

// transforms
Expand Down
173 changes: 171 additions & 2 deletions source/main/gameplay/CharacterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,175 @@

using namespace RoR;

CharacterFactory::CharacterFactory()
{
// set up definitions
// NOTE each anim is evaluated separately, there is no either-or relation,
// so you must set each anim's conditions to avoid conflicts.

CharacterDefPtr rorbot = std::make_shared<CharacterDef>();
rorbot->mesh_name = "character.mesh";
rorbot->name = "Classic RORBot";

{ // driving
CharacterAnimDef def;
BITMASK_SET_1(def.for_situations, Character::SITUATION_DRIVING);
def.anim_name = "Driving";
def.playback_time_ratio = 0.f;
def.playback_steering_ratio = -1.f;
def.anim_continuous = false;
def.source_percentual = true;
def.anim_neutral_mid = true;
def.playback_trim = 0.01f;
rorbot->anims.push_back(def);
}

{ // swimming
CharacterAnimDef def;
BITMASK_SET_1(def.for_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.for_actions, Character::ACTION_MOVE_FORWARD);
def.anim_name = "Swim_loop";
def.playback_h_speed_ratio = 1.f;
def.playback_time_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // floating in water
CharacterAnimDef def;
BITMASK_SET_1(def.for_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
def.anim_name = "Spot_swim";
def.playback_time_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // running
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.for_actions, Character::ACTION_RUN);
def.anim_name = "Run";
def.playback_time_ratio = 1.f;
def.playback_h_speed_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // walking forward
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Walk";
def.playback_time_ratio = 1.f;
def.playback_h_speed_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // walking backward
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_MOVE_BACKWARD);
def.anim_name = "Walk";
def.playback_time_ratio = -1.f;
def.playback_h_speed_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // side stepping left (-time)
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_TURN_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_BACKWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Side_step";
def.playback_time_ratio = -1.f;
rorbot->anims.push_back(def);
}

{ // side stepping right (+time)
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_SIDESTEP_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_BACKWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_TURN_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_TURN_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Side_step";
def.playback_time_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // side stepping left (-time)
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_SIDESTEP_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_BACKWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_TURN_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_TURN_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Side_step";
def.playback_time_ratio = -1.f;
rorbot->anims.push_back(def);
}

{ // turning left (+time)
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_TURN_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_SIDESTEP_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_SIDESTEP_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_BACKWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Turn";
def.playback_time_ratio = 1.f;
rorbot->anims.push_back(def);
}

{ // turning right (-time)
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.for_actions, Character::ACTION_TURN_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_SIDESTEP_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_SIDESTEP_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_BACKWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Turn";
def.playback_time_ratio = -1.f;
rorbot->anims.push_back(def);
}

{ // idle
CharacterAnimDef def;
BITMASK_SET_1(def.except_situations, Character::SITUATION_IN_DEEP_WATER);
BITMASK_SET_1(def.except_situations, Character::SITUATION_DRIVING);
BITMASK_SET_1(def.except_actions, Character::ACTION_TURN_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_TURN_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_SIDESTEP_LEFT);
BITMASK_SET_1(def.except_actions, Character::ACTION_SIDESTEP_RIGHT);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_FORWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_MOVE_BACKWARD);
BITMASK_SET_1(def.except_actions, Character::ACTION_RUN);
def.anim_name = "Idle_sway";
def.playback_time_ratio = 1.f;
rorbot->anims.push_back(def);
}

m_character_defs.push_back(rorbot);
}

Character* CharacterFactory::CreateLocalCharacter()
{
int colourNum = -1;
Expand All @@ -42,7 +211,7 @@ Character* CharacterFactory::CreateLocalCharacter()
}
#endif // USE_SOCKETW

m_local_character = std::unique_ptr<Character>(new Character(-1, 0, playerName, colourNum, false));
m_local_character = std::unique_ptr<Character>(new Character(m_character_defs[0], -1, 0, playerName, colourNum, false));
App::GetGfxScene()->RegisterGfxCharacter(m_local_character.get());
return m_local_character.get();
}
Expand All @@ -57,7 +226,7 @@ void CharacterFactory::createRemoteInstance(int sourceid, int streamid)

LOG(" new character for " + TOSTRING(sourceid) + ":" + TOSTRING(streamid) + ", colour: " + TOSTRING(colour));

Character* ch = new Character(sourceid, streamid, name, colour, true);
Character* ch = new Character(m_character_defs[0], sourceid, streamid, name, colour, true);
App::GetGfxScene()->RegisterGfxCharacter(ch);
m_remote_characters.push_back(std::unique_ptr<Character>(ch));
#endif // USE_SOCKETW
Expand Down
5 changes: 4 additions & 1 deletion source/main/gameplay/CharacterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Application.h"

#include "Character.h"
#include "CharacterDefFileFormat.h"
#include "Network.h"

#include <memory>
Expand All @@ -39,7 +40,7 @@ namespace RoR {
class CharacterFactory
{
public:
CharacterFactory() {}
CharacterFactory();
Character* CreateLocalCharacter();
Character* GetLocalCharacter() { return m_local_character.get(); }
void DeleteAllCharacters();
Expand All @@ -51,6 +52,8 @@ class CharacterFactory

private:

std::vector<CharacterDefPtr> m_character_defs;

std::unique_ptr<Character> m_local_character;
std::vector<std::unique_ptr<Character>> m_remote_characters;

Expand Down
Loading

0 comments on commit ec69f42

Please sign in to comment.