This commit is contained in:
floralrainfall 2023-07-18 01:19:57 -04:00
parent a74117d95f
commit e1415e917f
13 changed files with 129 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,23 +1,34 @@
#pragma once #pragma once
#include <App/V8/Tree/Instance.hpp> #include <App/V8/Tree/Instance.hpp>
#include <App/V8/DataModel/PartInstance.hpp>
namespace RNR namespace RNR
{ {
class Humanoid : Instance class Humanoid : public Instance
{ {
public: public:
Humanoid(); Humanoid();
~Humanoid(); ~Humanoid();
virtual std::string getClassName() { return "Humanoid"; }
bool canSit(); bool canSit();
void buildJoints(); void buildJoints();
void checkForJointDeath(); void checkForJointDeath();
void computeForce(float force, bool throttling); void computeForce(float force, bool throttling);
void getTorso(); PartInstance* getTorso();
void getHead(); PartInstance* getHead();
void createHealthBar();
float getHealth() { return m_health; };
void setHealth(float health) { m_health = health; }
float getMaxHealth() { return m_maxHealth; }
void setMaxHealth(float maxHealth) { m_maxHealth = maxHealth; }
private: private:
virtual void deserializeProperty(char* prop_name, pugi::xml_node prop);
virtual void addProperties(std::vector<ReflectionProperty>& properties);
float m_health; float m_health;
float m_maxHealth; float m_maxHealth;
float m_walkRotationalVelocity; float m_walkRotationalVelocity;

View File

@ -40,6 +40,7 @@ namespace RNR
PROPERTY_VECTOR3, PROPERTY_VECTOR3,
PROPERTY_CFRAME, PROPERTY_CFRAME,
PROPERTY_INSTANCE, PROPERTY_INSTANCE,
PROPERTY_FLOAT,
}; };
class ReflectionProperty class ReflectionProperty

View File

@ -11,6 +11,8 @@ namespace RNR
NormalId m_face; NormalId m_face;
public: public:
FaceInstance();
virtual void build() = 0;
}; };
} }

View File

@ -40,6 +40,10 @@ namespace RNR
bool contains(RNR::Instance* child); bool contains(RNR::Instance* child);
bool isAncestorOf(RNR::Instance* instance); bool isAncestorOf(RNR::Instance* instance);
bool isA(std::string type);
Instance* findFirstChild(std::string name);
Instance* findFirstChildOfType(std::string type);
static World* getWorld() { return Instance::world; } static World* getWorld() { return Instance::world; }
static void setWorld(World* world) { Instance::world = world; } static void setWorld(World* world) { Instance::world = world; }

View File

@ -11,6 +11,7 @@ namespace RNR
virtual void build(); virtual void build();
Ogre::AxisAlignedBox getBoundingBox() { return m_boundingbox; } Ogre::AxisAlignedBox getBoundingBox() { return m_boundingbox; }
virtual std::string getClassName() { return "Model"; } virtual std::string getClassName() { return "Model"; }
virtual void onChildAdded(Instance* instance);
private: private:
Ogre::AxisAlignedBox m_boundingbox; Ogre::AxisAlignedBox m_boundingbox;

View File

@ -1,4 +1,5 @@
#include <App/Humanoid/Humanoid.hpp> #include <App/Humanoid/Humanoid.hpp>
#include <App/V8/World/World.hpp>
namespace RNR namespace RNR
{ {
@ -32,13 +33,59 @@ namespace RNR
// //
} }
void Humanoid::getTorso() void Humanoid::createHealthBar()
{ {
// if(!getHead())
{
printf("Humanoid::createHealthBar: no head\n");
return;
}
if(getNode())
world->getOgreSceneManager()->destroySceneNode(getNode());
setNode(world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode());
Ogre::BillboardSet* healthBarSet = world->getOgreSceneManager()->createBillboardSet("HumanoidHealth" + getParent()->getName());
Ogre::Billboard* healthBarBillboard = healthBarSet->createBillboard(Ogre::Vector3(100, 0, 200));
getNode()->attachObject(healthBarSet);
getNode()->setPosition(getHead()->getPosition());
printf("Humanoid::createHealthBar: WIP");
} }
void Humanoid::getHead() void Humanoid::deserializeProperty(char* prop_name, pugi::xml_node prop)
{ {
// if(prop_name == std::string("Health"))
{
setHealth(prop.text().as_float());
}
else if(prop_name == std::string("MaxHealth"))
{
setMaxHealth(prop.text().as_float());
}
}
void Humanoid::addProperties(std::vector<ReflectionProperty>& properties)
{
ReflectionProperty _properties[] = {
{ this, std::string("Health"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_FLOAT,
REFLECTION_GETTER(Humanoid* instance = (Humanoid*)object; return &instance->m_health; ),
REFLECTION_SETTER(Humanoid* instance = (Humanoid*)object; instance->setHealth(*(float*)value); ) },
{ this, std::string("MaxHealth"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_FLOAT,
REFLECTION_GETTER(Humanoid* instance = (Humanoid*)object; return &instance->m_maxHealth; ),
REFLECTION_SETTER(Humanoid* instance = (Humanoid*)object; instance->setMaxHealth(*(float*)value); ) },
};
properties.insert(properties.end(), _properties, _properties+(sizeof(_properties)/sizeof(ReflectionProperty)));
}
PartInstance* Humanoid::getTorso()
{
return (PartInstance*)getParent()->findFirstChild("Torso");
}
PartInstance* Humanoid::getHead()
{
return (PartInstance*)getParent()->findFirstChild("Head");
} }
} }

View File

@ -47,12 +47,15 @@ namespace RNR
vector.y, vector.y,
vector.z); vector.z);
} }
case PROPERTY_FLOAT:
return Strings::string_format("%f",
*(float*)m_getter(m_object));
case PROPERTY_CFRAME: case PROPERTY_CFRAME:
{ {
CoordinateFrame cframe = *(CoordinateFrame*)m_getter(m_object); CoordinateFrame cframe = *(CoordinateFrame*)m_getter(m_object);
Ogre::Vector3 cframe_position = cframe.getPosition(); Ogre::Vector3 cframe_position = cframe.getPosition();
Ogre::Quaternion cframe_rotation = Ogre::Quaternion(cframe.getRotation()); Ogre::Quaternion cframe_rotation = Ogre::Quaternion(cframe.getRotation());
return Strings::string_format("(%f,%f,%f)), (%f,%f,%f,%f)", return Strings::string_format("(%f,%f,%f), (%f,%f,%f,%f)",
cframe_position.x, cframe_position.x,
cframe_position.y, cframe_position.y,
cframe_position.z, cframe_position.z,

View File

@ -1,7 +1,15 @@
#include <App/V8/Tree/Instance.hpp> #include <App/V8/Tree/Instance.hpp>
#include <App/V8/DataModel/FaceInstance.hpp>
#include <App/V8/World/World.hpp>
#include <Helpers/NormalId.hpp> #include <Helpers/NormalId.hpp>
#include <Helpers/Strings.hpp>
namespace RNR namespace RNR
{ {
FaceInstance::FaceInstance() : Ogre::ManualObject(Strings::random_hex(8))
{
setNode(world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode());
getNode()->attachObject(this);
build();
}
} }

View File

@ -159,4 +159,29 @@ namespace RNR
{ {
} }
bool Instance::isA(std::string type)
{
if (type == getClassName()); // TODO: check if type is any of parent types
}
Instance* Instance::findFirstChild(std::string name)
{
for(auto& child : m_children)
{
if(child->getName() == name)
return child;
}
return NULL;
}
Instance* Instance::findFirstChildOfType(std::string type)
{
for(auto& child : m_children)
{
if(child->isA(type))
return child;
}
return NULL;
}
} }

View File

@ -1,5 +1,6 @@
#include <App/V8/Tree/ModelInstance.hpp> #include <App/V8/Tree/ModelInstance.hpp>
#include <App/V8/DataModel/PartInstance.hpp> #include <App/V8/DataModel/PartInstance.hpp>
#include <App/Humanoid/Humanoid.hpp>
namespace RNR namespace RNR
{ {
@ -27,4 +28,13 @@ namespace RNR
m_boundingbox.merge(child_pv->getPosition() - size); m_boundingbox.merge(child_pv->getPosition() - size);
} }
} }
void ModelInstance::onChildAdded(Instance* instance)
{
if(instance->getClassName() == "Humanoid")
{
Humanoid* instance_humanoid = (Humanoid*)instance;
instance_humanoid->createHealthBar();
}
}
} }

View File

@ -1,4 +1,5 @@
#include <App/V8/Tree/PVInstance.hpp> #include <App/V8/Tree/PVInstance.hpp>
#include <App/V8/World/World.hpp>
#include <Helpers/XML.hpp> #include <Helpers/XML.hpp>
namespace RNR namespace RNR

View File

@ -1,6 +1,7 @@
#include <App/V8/World/World.hpp> #include <App/V8/World/World.hpp>
#include <App/V8/DataModel/PartInstance.hpp> #include <App/V8/DataModel/PartInstance.hpp>
#include <App/GUI/SelectionBox.hpp> #include <App/GUI/SelectionBox.hpp>
#include <App/Humanoid/Humanoid.hpp>
#include <pugixml.hpp> #include <pugixml.hpp>
namespace RNR namespace RNR
@ -46,6 +47,10 @@ namespace RNR
{ {
instance = new ModelInstance(); instance = new ModelInstance();
} }
else if(class_attr.as_string() == std::string("Humanoid"))
{
instance = new Humanoid();
}
else else
{ {
instance = new Instance(); instance = new Instance();
@ -67,11 +72,6 @@ namespace RNR
{ {
xmlAddItem(item, instance); xmlAddItem(item, instance);
} }
if(class_attr.as_string() == std::string("Model"))
{
((ModelInstance*)instance)->build();
}
} }
void World::load(char* path) void World::load(char* path)