Implemented operator overloads for Reflection

This commit is contained in:
Vulpovile
2023-11-05 00:37:25 -07:00
parent 901539e594
commit cab66d1152
8 changed files with 273 additions and 59 deletions

View File

@@ -382,6 +382,9 @@
<File <File
RelativePath=".\src\include\Reflection\ReflectionProperty_impl.h"> RelativePath=".\src\include\Reflection\ReflectionProperty_impl.h">
</File> </File>
<File
RelativePath=".\src\include\Reflection\ReflectionProperty_op_overload.h">
</File>
</Filter> </Filter>
<Filter <Filter
Name="DataModelV3" Name="DataModelV3"

View File

@@ -20,8 +20,19 @@ namespace B3D{
ReflectionProperty(std::string key, T defaultValue, ReflectionType type, ReflectionDataTable * containerTable, void* extData = NULL, bool archivable = true, bool locked = false, bool propertyHidden = false); ReflectionProperty(std::string key, T defaultValue, ReflectionType type, ReflectionDataTable * containerTable, void* extData = NULL, bool archivable = true, bool locked = false, bool propertyHidden = false);
ReflectionProperty(void); ReflectionProperty(void);
~ReflectionProperty(void); ~ReflectionProperty(void);
T getValue();
T getValueClone();
T* getValuePtr();
void setValue(T);
void dispose(); void dispose();
//Too many
#include "ReflectionProperty_op_overload.h"
private: private:
std::string propertyName; std::string propertyName;
bool archivable; bool archivable;

View File

@@ -48,3 +48,26 @@ void ReflectionProperty<T>::dispose()
extData = NULL; extData = NULL;
} }
} }
template<class T>
T ReflectionProperty<T>::getValueClone()
{
return T(value);
}
template<class T>
T ReflectionProperty<T>::getValue()
{
return *value;
}
template<class T>
T* ReflectionProperty<T>::getValuePtr()
{
return value;
}
template<class T>
void ReflectionProperty<T>::setValue(T value){
this=value;
}

View File

@@ -0,0 +1,175 @@
//Operator Overloads
T operator()()
{
return *value;
}
//Assignment Operators
T operator=(T nVal)
{
(*value) = nVal;
return *value;
}
T operator+=(T nVal)
{
(*value) += nVal;
return *value;
}
T operator-=(T nVal)
{
(*value)-= nVal;
return *value;
}
T operator/=(T nVal)
{
(*value) /= nVal;
return *value;
}
T operator*=(T nVal)
{
(*value) *= nVal;
return *value;
}
T operator%=(T nVal)
{
(*value) %= nVal;
return *value;
}
T operator^=(T nVal)
{
(*value) ^= nVal;
return *value;
}
T operator&=(T nVal)
{
(*value) &= nVal;
return *value;
}
T operator|=(T nVal)
{
(*value) |= nVal;
return *value;
}
T operator>>=(T nVal)
{
(*value) >>= nVal;
return *value;
}
T operator<<=(T nVal)
{
(*value) <<= nVal;
return *value;
}
//Mathematical Operations
T operator+(T nVal)
{
return (*value) + nVal;
}
T operator-(T nVal)
{
return (*value) - nVal;
}
T operator*(T nVal)
{
return (*value) - nVal;
}
T operator/(T nVal)
{
return (*value) / nVal;
}
T operator%(T nVal)
{
return (*value) % nVal;
}
//Boolean operations
bool operator==(T nVal)
{
return (*value) == nVal;
}
bool operator!=(T nVal)
{
return (*value) != nVal;
}
bool operator<(T nVal)
{
return (*value) < nVal;
}
bool operator<=(T nVal)
{
return (*value) <= nVal;
}
bool operator>(T nVal)
{
return (*value) > nVal;
}
bool operator>=(T nVal)
{
return (*value) >= nVal;
}
T operator&&(T nVal)
{
return (*value) && nVal;
}
T operator||(T nVal)
{
return (*value) && nVal;
}
T operator!()
{
return !(*value);
}
//Bitwise operations
T operator&(T nVal)
{
return (*value) && nVal;
}
T operator|(T nVal)
{
return (*value) && nVal;
}
T operator>>(T nVal)
{
return (*value) >> nVal;
}
T operator<<(T nVal)
{
return (*value) << nVal;
}
T operator^(T nVal)
{
return (*value) ^ nVal;
}
T operator~()
{
return ~(*value);
}

View File

@@ -5,6 +5,8 @@ DataModelInstance::DataModelInstance(void)
{ {
// Instances // Instances
Instance::Instance("DataModel"); Instance::Instance("DataModel");
name = "Level";
parentDataModel = this; parentDataModel = this;
//workspace = new WorkspaceInstance(); //workspace = new WorkspaceInstance();
//guiRoot = new GuiRootInstance(); //guiRoot = new GuiRootInstance();

View File

@@ -5,7 +5,7 @@ using namespace B3D;
LevelInstance::LevelInstance(void) LevelInstance::LevelInstance(void)
{ {
Instance::Instance("LevelService"); Instance::Instance("LevelService");
*name.value = "Level"; name = "Level";
//Reflection values //Reflection values
winMessage = Reflection::ReflectionProperty<std::string>("WinMessage", "You Won!", TYPE_STRING, this->dataTable); winMessage = Reflection::ReflectionProperty<std::string>("WinMessage", "You Won!", TYPE_STRING, this->dataTable);
@@ -54,24 +54,24 @@ void LevelInstance::drawCondition()
void LevelInstance::Step(SimTime sdt) void LevelInstance::Step(SimTime sdt)
{ {
switch(*timerAffectsScore.value) switch(timerAffectsScore.getValue())
{ {
case Enum::AffectType::NoChange: case Enum::AffectType::NoChange:
break; break;
case Enum::AffectType::Increase: case Enum::AffectType::Increase:
*score.value += 1; score += 1;
break; break;
case Enum::AffectType::Decrease: case Enum::AffectType::Decrease:
if (*score.value > 0) if (score > 0)
*score.value -= 1; score -= 1;
break; break;
} }
if (*timer.value >= sdt){ if (timer >= sdt){
*score.value -= sdt; score -= sdt;
} }
else{ else{
*timer.value = 0.0f; timer = 0.0f;
switch(*timerUpAction.value) switch(timerUpAction.getValue())
{ {
case Enum::ActionType::Nothing: case Enum::ActionType::Nothing:
break; break;

View File

@@ -17,7 +17,7 @@ PartInstance::PartInstance(void)
{ {
PVInstance::PVInstance("Part"); PVInstance::PVInstance("Part");
*(name.value) = "Unnamed PVItem"; name = "Unnamed PVItem";
canCollide = ReflectionProperty<bool>("CanCollide", true, TYPE_BOOLEAN, this->dataTable); canCollide = ReflectionProperty<bool>("CanCollide", true, TYPE_BOOLEAN, this->dataTable);
anchored = ReflectionProperty<bool>("Anchored", false, TYPE_BOOLEAN, this->dataTable); anchored = ReflectionProperty<bool>("Anchored", false, TYPE_BOOLEAN, this->dataTable);
size = ReflectionProperty<Vector3>("Size", Vector3(2,1,4), TYPE_VECTOR3, this->dataTable); size = ReflectionProperty<Vector3>("Size", Vector3(2,1,4), TYPE_VECTOR3, this->dataTable);
@@ -71,7 +71,7 @@ void PartInstance::setDragging(bool value)
float PartInstance::getMass() float PartInstance::getMass()
{ {
if(*(shape.value) == Enum::Shape::Block) if(shape == Enum::Shape::Block)
return size.value->x*size.value->y*size.value->z*0.7F; return size.value->x*size.value->y*size.value->z*0.7F;
else else
return 1.3333333333333333333333333333333F*(size.value->x/2)*(size.value->y/2)*(size.value->z/2)*0.7F; return 1.3333333333333333333333333333333F*(size.value->x/2)*(size.value->y/2)*(size.value->z/2)*0.7F;
@@ -79,46 +79,46 @@ float PartInstance::getMass()
Vector3 PartInstance::getVelocity() Vector3 PartInstance::getVelocity()
{ {
return *(velocity.value); return velocity.getValue();
} }
Vector3 PartInstance::getRotVelocity() Vector3 PartInstance::getRotVelocity()
{ {
return *(rotVelocity.value); return rotVelocity.getValue();
} }
// OnTouch // OnTouch
bool PartInstance::isSingleShot() bool PartInstance::isSingleShot()
{ {
return *(singleShot.value); return singleShot.getValue();
} }
int PartInstance::getTouchesToTrigger() int PartInstance::getTouchesToTrigger()
{ {
return *(touchesToTrigger.value); return touchesToTrigger.getValue();
} }
int PartInstance::getUniqueObjectsToTrigger() int PartInstance::getUniqueObjectsToTrigger()
{ {
return *(uniqueObjectsToTrigger.value); return uniqueObjectsToTrigger.getValue();
} }
int PartInstance::getChangeScore() int PartInstance::getChangeScore()
{ {
return *(changeScore.value); return changeScore.getValue();
} }
float PartInstance::getChangeTimer() float PartInstance::getChangeTimer()
{ {
return *(changeTimer.value); return changeTimer.getValue();
} }
void PartInstance::setVelocity(Vector3 v) void PartInstance::setVelocity(Vector3 v)
{ {
*(velocity.value) = v; velocity = v;
} }
void PartInstance::setRotVelocity(Vector3 v) void PartInstance::setRotVelocity(Vector3 v)
{ {
*(rotVelocity.value) = v; rotVelocity = v;
} }
void PartInstance::postRender(RenderDevice *rd) void PartInstance::postRender(RenderDevice *rd)
@@ -128,7 +128,7 @@ void PartInstance::postRender(RenderDevice *rd)
void PartInstance::renderName(RenderDevice *rd) void PartInstance::renderName(RenderDevice *rd)
{ {
if(!*(nameShown.value)) if(!nameShown)
return; return;
G3D::GFontRef fnt = NULL; G3D::GFontRef fnt = NULL;
Instance* dm = parent; Instance* dm = parent;
@@ -143,7 +143,7 @@ void PartInstance::renderName(RenderDevice *rd)
} }
if(!fnt.isNull()) if(!fnt.isNull())
{ {
Vector3 gamepoint = *(position.value) + Vector3(0,1.5,0); Vector3 gamepoint = position + Vector3(0,1.5,0);
Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 100 && distance > -100) if(distance < 100 && distance > -100)
@@ -151,7 +151,7 @@ void PartInstance::renderName(RenderDevice *rd)
if(distance < 0) if(distance < 0)
distance = distance*-1; distance = distance*-1;
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
fnt->draw3D(rd, *(name.value), CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.03*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); fnt->draw3D(rd, name.getValue(), CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.03*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }
} }
@@ -167,22 +167,22 @@ void PartInstance::setSurface(int face, Enum::SurfaceType::Value surface)
switch(face) switch(face)
{ {
case TOP: case TOP:
*(top.value) = surface; top = surface;
break; break;
case BOTTOM: case BOTTOM:
*(bottom.value) = surface; bottom = surface;
break; break;
case LEFT: case LEFT:
*(left.value) = surface; left = surface;
break; break;
case RIGHT: case RIGHT:
*(right.value) = surface; right = surface;
break; break;
case FRONT: case FRONT:
*(front.value) = surface; front = surface;
break; break;
default: default:
*(back.value) = surface; back = surface;
} }
changed = true; changed = true;
} }
@@ -243,7 +243,7 @@ void PartInstance::setSize(Vector3 newSize)
if(sizez > 512) if(sizez > 512)
sizez = 512; sizez = 512;
if(*(shape.value) != Enum::Shape::Block) if(shape != Enum::Shape::Block)
{ {
int max = sizex; int max = sizex;
if(sizey > max) if(sizey > max)
@@ -253,28 +253,28 @@ void PartInstance::setSize(Vector3 newSize)
sizex = sizey = sizez = max; sizex = sizey = sizez = max;
} }
*(size.value) = Vector3(sizex, sizey, sizez); size = Vector3(sizex, sizey, sizez);
if(this->physBody != NULL && getParentDataModel() != NULL) if(this->physBody != NULL && getParentDataModel() != NULL)
getParentDataModel()->getEngine()->resetBody(this); getParentDataModel()->getEngine()->resetBody(this);
} }
Vector3 PartInstance::getSize() Vector3 PartInstance::getSize()
{ {
return *(size.value); return size.getValue();
} }
Vector3 PartInstance::getPosition() Vector3 PartInstance::getPosition()
{ {
return *(position.value); return position.getValue();
} }
void PartInstance::setShape(Enum::Shape::Value shape) void PartInstance::setShape(Enum::Shape::Value shape)
{ {
switch(shape) switch(shape)
{ {
case Enum::Shape::Block: case Enum::Shape::Block:
*(this->shape.value) = shape; this->shape = shape;
break; break;
default: default:
*(this->shape.value) = shape; this->shape = shape;
this->setSize(this->getSize()); this->setSize(this->getSize());
} }
if(this->physBody != NULL && getParentDataModel() != NULL) if(this->physBody != NULL && getParentDataModel() != NULL)
@@ -285,23 +285,23 @@ void PartInstance::setShape(Enum::Shape::Value shape)
void PartInstance::setPosition(Vector3 pos) void PartInstance::setPosition(Vector3 pos)
{ {
*(position.value) = pos; position = pos;
setCFrame(CoordinateFrame(cFrame.value->rotation, pos)); setCFrame(CoordinateFrame(cFrame.value->rotation, pos));
if (*(anchored.value) && getParentDataModel() != NULL) if (anchored && getParentDataModel() != NULL)
getParentDataModel()->getEngine()->resetBody(this); getParentDataModel()->getEngine()->resetBody(this);
} }
void PartInstance::setAnchored(bool anchored) void PartInstance::setAnchored(bool anchored)
{ {
*(this->anchored.value) = anchored; this->anchored = anchored;
if(this->physBody != NULL && getParentDataModel() != NULL) if(this->physBody != NULL && getParentDataModel() != NULL)
getParentDataModel()->getEngine()->resetBody(this); getParentDataModel()->getEngine()->resetBody(this);
} }
bool PartInstance::isAnchored() bool PartInstance::isAnchored()
{ {
return *(this->anchored.value); return this->anchored.getValue();
} }
@@ -318,22 +318,22 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
void PartInstance::setCFrameNoSync(CoordinateFrame coordinateFrame) void PartInstance::setCFrameNoSync(CoordinateFrame coordinateFrame)
{ {
*(cFrame.value) = coordinateFrame; cFrame = coordinateFrame;
*(position.value) = coordinateFrame.translation; position = coordinateFrame.translation;
} }
bool PartInstance::collides(PartInstance * part) bool PartInstance::collides(PartInstance * part)
{ {
if(*(shape.value) == Enum::Shape::Block) if(shape == Enum::Shape::Block)
{ {
if(*(part->shape.value) == Enum::Shape::Block) if(part->shape == Enum::Shape::Block)
return G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), part->getBox()); return G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), part->getBox());
else else
return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(part->getSphere(), getBox()); return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(part->getSphere(), getBox());
} }
else else
{ {
if(*(part->shape.value) == Enum::Shape::Block) if(part->shape == Enum::Shape::Block)
return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(getSphere(), part->getBox()); return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(getSphere(), part->getBox());
else else
return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidSphere(getSphere(), part->getSphere()); return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidSphere(getSphere(), part->getSphere());
@@ -364,18 +364,18 @@ void PartInstance::render(RenderDevice* rd) {
if (changed) if (changed)
{ {
changed=false; changed=false;
Vector3 renderSize = *(size.value)/2; Vector3 renderSize = size.getValue()/2;
glNewList(glList, GL_COMPILE); glNewList(glList, GL_COMPILE);
renderShape(*(this->shape.value), renderSize, *(color.value)); renderShape(this->shape.getValue(), renderSize, color.getValue());
renderSurface(TOP, *(this->top.value), renderSize, *(this->controller.value), *(color.value)); renderSurface(TOP, this->top.getValue(), renderSize, this->controller.getValue(), color.getValue());
renderSurface(FRONT, *(this->front.value), renderSize, *(this->controller.value), *(color.value)); renderSurface(FRONT, this->front.getValue(), renderSize, this->controller.getValue(), color.getValue());
renderSurface(RIGHT, *(this->right.value), renderSize, *(this->controller.value), *(color.value)); renderSurface(RIGHT, this->right.getValue(), renderSize, this->controller.getValue(), color.getValue());
renderSurface(BACK, *(this->back.value), renderSize, *(this->controller.value), *(color.value)); renderSurface(BACK, this->back.getValue(), renderSize, this->controller.getValue(), color.getValue());
renderSurface(LEFT, *(this->left.value), renderSize, *(this->controller.value), *(color.value)); renderSurface(LEFT, this->left.getValue(), renderSize, this->controller.getValue(), color.getValue());
renderSurface(BOTTOM, *(this->bottom.value), renderSize, *(this->controller.value), *(color.value)); renderSurface(BOTTOM, this->bottom.getValue(), renderSize, this->controller.getValue(), color.getValue());
glEndList(); glEndList();
} }
rd->setObjectToWorldMatrix(*(cFrame.value)); rd->setObjectToWorldMatrix(cFrame.getValue());
glCallList(glList); glCallList(glList);
postRender(rd); postRender(rd);
} }
@@ -399,16 +399,16 @@ void PartInstance::onTouch()
{ {
if(getParentDataModel() == NULL) if(getParentDataModel() == NULL)
return; return;
if(*(singleShot.value) && _touchedOnce) if(singleShot && _touchedOnce)
return; return;
if(*(singleShot.value) && !_touchedOnce) if(singleShot && !_touchedOnce)
_touchedOnce = true; _touchedOnce = true;
*(getParentDataModel()->getLevel()->score.value) += *(changeScore.value); getParentDataModel()->getLevel()->score += changeScore.getValue();
*(getParentDataModel()->getLevel()->timer.value) += *(changeTimer.value); getParentDataModel()->getLevel()->timer += changeTimer.getValue();
switch(*(onTouchAction.value)) switch(onTouchAction.getValue())
{ {
case Enum::ActionType::Nothing: case Enum::ActionType::Nothing:
break; break;

View File

@@ -22,7 +22,7 @@ XplicitNgine::XplicitNgine()
dWorldSetAutoDisableAngularThreshold(physWorld, 0.5F); dWorldSetAutoDisableAngularThreshold(physWorld, 0.5F);
dWorldSetAutoDisableSteps(physWorld, 20); dWorldSetAutoDisableSteps(physWorld, 20);
*(this->name.value) = "PhysicsService"; this->name = "PhysicsService";
} }
XplicitNgine::~XplicitNgine() XplicitNgine::~XplicitNgine()