This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+424
View File
@@ -0,0 +1,424 @@
#include "stdafx.h"
#include "V8Tree/Property.h"
#include "rbx/Debug.h"
#include "Util/BrickColor.h"
#include "Util/Region3.h"
#include "Util/Region3int16.h"
#include "util/CellID.h"
#include "util/PhysicalProperties.h"
using namespace G3D;
/*
// Stub function. Should never get called
template<>
bool XmlElement::getValue(Color3& value) const
{
RBXASSERT(false);
return false;
}
// Stub function. Should never get called
template<>
void XmlElement::setValue(Color3 value)
{
RBXASSERT(false);
}
*/
namespace RBX {
template<>
std::string StringConverter<G3D::Vector2int16>::convertToString(const G3D::Vector2int16& value)
{
std::string result = StringConverter<int>::convertToString(value[0]);
result += ", ";
result += StringConverter<int>::convertToString(value[1]);
return result;
}
template<>
bool StringConverter<G3D::Vector2int16>::convertToValue(const std::string& text, G3D::Vector2int16& value)
{
int pos = text.find_first_of(",;", 0);
if (pos<0)
return false;
value[0] = atoi(text.substr(0, pos).c_str());
int last = pos+1;
pos = text.length();
if (pos<last)
return false;
value[1] = atoi(text.substr(last, pos-last).c_str());
return true;
}
template<>
std::string StringConverter<G3D::Vector3int16>::convertToString(const G3D::Vector3int16& value)
{
std::string result = StringConverter<int>::convertToString(value[0]);
result += ", ";
result += StringConverter<int>::convertToString(value[1]);
result += ", ";
result += StringConverter<int>::convertToString(value[2]);
return result;
}
template<>
bool StringConverter<G3D::Vector3int16>::convertToValue(const std::string& text, G3D::Vector3int16& value)
{
int pos = text.find_first_of(",;", 0);
if (pos<0)
return false;
value[0] = atoi(text.substr(0, pos).c_str());
int last = pos+1;
pos = text.find_first_of(",;", last);
if (pos<last)
return false;
value[1] = atoi(text.substr(last, pos-last).c_str());
last = pos+1;
pos = text.length();
if (pos<last)
return false;
value[2] = atoi(text.substr(last, pos-last).c_str());
return true;
}
template<>
std::string StringConverter<G3D::Vector3>::convertToString(const G3D::Vector3& value)
{
std::string result = StringConverter<float>::convertToString(value[0]);
result += ", ";
result += StringConverter<float>::convertToString(value[1]);
result += ", ";
result += StringConverter<float>::convertToString(value[2]);
return result;
}
template<>
std::string StringConverter<RBX::Vector2>::convertToString(const RBX::Vector2& value)
{
std::string result = StringConverter<float>::convertToString(value[0]);
result += ", ";
result += StringConverter<float>::convertToString(value[1]);
return result;
}
template<>
std::string StringConverter<RBX::Rect2D>::convertToString(const RBX::Rect2D& value)
{
std::string result = StringConverter<float>::convertToString(value.x0());
result += ", ";
result += StringConverter<float>::convertToString(value.y0());
result += ", ";
result += StringConverter<float>::convertToString(value.x1());
result += ", ";
result += StringConverter<float>::convertToString(value.y1());
return result;
}
template<>
std::string StringConverter<PhysicalProperties>::convertToString(const PhysicalProperties& value)
{
if (value.getCustomEnabled())
{
std::string result = StringConverter<float>::convertToString(value.getDensity());
result +=", ";
result += StringConverter<float>::convertToString(value.getFriction());
result +=", ";
result += StringConverter<float>::convertToString(value.getElasticity());
result +=", ";
result += StringConverter<float>::convertToString(value.getFrictionWeight());
result +=", ";
result += StringConverter<float>::convertToString(value.getElasticityWeight());
return result;
}
return std::string("default");
}
template<>
bool StringConverter<PhysicalProperties>::convertToValue(const std::string& text, PhysicalProperties& value)
{
return false;
}
template<>
std::string StringConverter<G3D::CoordinateFrame>::convertToString(const G3D::CoordinateFrame& value)
{
std::string result = StringConverter<G3D::Vector3>::convertToString(value.translation);
for (int i=0; i<3; ++i)
for (int j=0; j<3; ++j)
{
result += ", ";
result += StringConverter<float>::convertToString(value.rotation[i][j]);
}
return result;
}
template<>
bool StringConverter<RBX::CoordinateFrame>::convertToValue(const std::string& text, RBX::CoordinateFrame& value)
{
return false;
}
template<>
std::string StringConverter<RBX::Region3>::convertToString(const RBX::Region3& value)
{
std::string result = StringConverter<RBX::CoordinateFrame>::convertToString(value.getCFrame());
result += "; ";
result += StringConverter<RBX::Vector3>::convertToString(value.getSize());
return result;
}
template<>
bool StringConverter<RBX::Region3>::convertToValue(const std::string& text, RBX::Region3& value)
{
return false;
}
template<>
std::string StringConverter<RBX::Region3int16>::convertToString(const RBX::Region3int16& value)
{
std::string result = StringConverter<G3D::Vector3int16>::convertToString(value.getMinPos());
result += "; ";
result += StringConverter<Vector3int16>::convertToString(value.getMaxPos());
return result;
}
template<>
bool StringConverter<RBX::Region3int16>::convertToValue(const std::string& text, RBX::Region3int16& value)
{
return false;
}
template<>
bool StringConverter<G3D::Vector3>::convertToValue(const std::string& text, G3D::Vector3& value)
{
int pos = text.find_first_of(",;", 0);
if (pos<0)
return false;
value[0] = (float)atof(text.substr(0, pos).c_str());
int last = pos+1;
pos = text.find_first_of(",;", last);
if (pos<last)
return false;
value[1] = (float)atof(text.substr(last, pos-last).c_str());
last = pos+1;
pos = text.length();
if (pos<last)
return false;
value[2] = (float)atof(text.substr(last, pos-last).c_str());
return true;
}
template<>
bool StringConverter<RBX::Vector2>::convertToValue(const std::string& text, RBX::Vector2& value)
{
int pos = text.find_first_of(",;", 0);
if (pos<0)
return false;
value[0] = (float)atof(text.substr(0, pos).c_str());
int last = pos+1;
pos = text.length();
if (pos<last)
return false;
value[1] = (float)atof(text.substr(last, pos-last).c_str());
return true;
}
template<>
bool StringConverter<G3D::Rect2D>::convertToValue(const std::string& text, G3D::Rect2D& value)
{
float x0,y0,x1,y1;
int pos = text.find_first_of(",;", 0);
if (pos<0)
return false;
x0 = (float)atof(text.substr(0, pos).c_str());
int last = pos+1;
pos = text.find_first_of(",;", last);
if (pos<last)
return false;
y0 = (float)atof(text.substr(last, pos).c_str());
last = pos+1;
pos = text.find_first_of(",;", last);
if (pos<last)
return false;
x1 = (float)atof(text.substr(last, pos).c_str());
last = pos+1;
pos = text.length();
if (pos<last)
return false;
y1 = (float)atof(text.substr(last, pos-last).c_str());
value = G3D::Rect2D::xyxy(x0, y0, x1, y1);
return true;
}
template<>
std::string RBX::StringConverter<RBX::RbxRay>::convertToString(const RBX::RbxRay& value)
{
std::string result = "{" + RBX::StringConverter<RBX::Vector3>::convertToString(value.origin()) + "}";
result += ", ";
result += "{" + RBX::StringConverter<RBX::Vector3>::convertToString(value.direction()) + "}";
return result;
}
template<>
bool RBX::StringConverter<RBX::RbxRay>::convertToValue(const std::string& text, RBX::RbxRay& value)
{
int openBracket = text.find_first_of("{", 0);
if (openBracket < 0)
return false;
int closeBracket = text.find_first_of("}", openBracket);
if(closeBracket < 0)
return false;
if(!RBX::StringConverter<RBX::Vector3>::convertToValue(text.substr(openBracket+1, closeBracket-openBracket-1), value.origin()))
return false;
int last = closeBracket+1;
openBracket = text.find_first_of("{", last);
if (openBracket < 0)
return false;
closeBracket = text.find_first_of("}", openBracket);
if(closeBracket < 0)
return false;
if(!RBX::StringConverter<RBX::Vector3>::convertToValue(text.substr(openBracket+1, closeBracket-openBracket-1), value.direction()))
return false;
return true;
}
template<>
std::string StringConverter<RBX::BrickColor>::convertToString(const RBX::BrickColor& value)
{
return value.name();
}
////////////////////////////////////////////////////////////////////////////////
//
// StringConverter<CellID>
//
template<>
std::string RBX::StringConverter<RBX::CellID>::convertToString(const RBX::CellID& value)
{
std::string result = "{" + RBX::StringConverter<bool>::convertToString(value.getIsNil()) + "}";
result += ", ";
result += "{" + RBX::StringConverter<RBX::Vector3>::convertToString(value.getLocation()) + "}";
return result;
}
template<>
bool RBX::StringConverter<RBX::CellID>::convertToValue(const std::string& text, RBX::CellID& value)
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
//
// StringConverter<G3D::Color3>
//
template<>
std::string StringConverter<G3D::Color3>::convertToString(const G3D::Color3& value)
{
char szText[64];
#ifdef _WIN32
_snprintf(szText, 64, "%g, %g, %g", value[0], value[1], value[2]);
#else
snprintf(szText, 64, "%g, %g, %g", value[0], value[1], value[2]);
#endif
return szText;
}
template<>
bool StringConverter<G3D::Color3>::convertToValue(const std::string& text, G3D::Color3& value)
{
if (text[0]=='#')
{
// This is an HTML color: #rrggbb
if (text.size()!=7)
return false;
value[0] = static_cast<float>(strtol(text.substr(1,2).c_str(), NULL, 16))/255.0f;
value[1] = static_cast<float>(strtol(text.substr(3,2).c_str(), NULL, 16))/255.0f;
value[2] = static_cast<float>(strtol(text.substr(5,2).c_str(), NULL, 16))/255.0f;
return true;
}
if (text.substr(0,2)=="0x")
{
// This is a color of the form 0xrrggbb
if (text.size()!=8)
return false;
value[0] = static_cast<float>(strtol(text.substr(2,2).c_str(), NULL, 16))/255.0f;
value[1] = static_cast<float>(strtol(text.substr(4,2).c_str(), NULL, 16))/255.0f;
value[2] = static_cast<float>(strtol(text.substr(6,2).c_str(), NULL, 16))/255.0f;
return true;
}
int pos = text.find_first_of(",;", 0);
if (pos<0)
return false;
value[0] = static_cast<float>(atof(text.substr(0, pos).c_str()));
int last = pos+1;
pos = text.find_first_of(",;", last);
if (pos<last)
return false;
value[1] = static_cast<float>(atof(text.substr(last, pos-last).c_str()));
last = pos+1;
pos = text.length();
if (pos<last)
return false;
value[2] = static_cast<float>(atof(text.substr(last, pos-last).c_str()));
return true;
}
template<>
bool StringConverter<RBX::ContentId>::convertToValue(const std::string& text, RBX::ContentId& value)
{
value = ContentId(text);
return true;
}
template<>
bool StringConverter<RBX::BrickColor>::convertToValue(const std::string& text, RBX::BrickColor& value)
{
// TODO: Is this the right thing to do? Maybe we should just return false
value = RBX::BrickColor::parse(text.c_str());
return true;
}
template<>
std::string StringConverter< RBX::ContentId >::convertToString(const RBX::ContentId& value)
{
return value.toString();
}
} // namespace RBX
+156
View File
@@ -0,0 +1,156 @@
#include "stdafx.h"
#include "v8tree/service.h"
#include "boost/cast.hpp"
#include "rbx/atomic.h"
namespace RBX
{
const char* const sServiceProvider = "ServiceProvider";
REFLECTION_BEGIN();
Reflection::BoundFuncDesc<ServiceProvider, shared_ptr<Instance>(std::string)> ServiceProvider::func_FindService(&ServiceProvider::findPublicServiceByClassNameString, "FindService", "className", Security::None);
Reflection::BoundFuncDesc<ServiceProvider, shared_ptr<Instance>(std::string)> ServiceProvider::func_GetService(&ServiceProvider::getPublicServiceByClassNameString, "GetService", "className", Security::None);
Reflection::BoundFuncDesc<ServiceProvider, shared_ptr<Instance>(std::string)> ServiceProvider::dep_service(&ServiceProvider::getPublicServiceByClassNameString, "service", "className", Security::None, Reflection::Descriptor::Attributes::deprecated(ServiceProvider::func_GetService));
Reflection::BoundFuncDesc<ServiceProvider, shared_ptr<Instance>(std::string)> ServiceProvider::dep_GetService(&ServiceProvider::getPublicServiceByClassNameString, "getService", "className", Security::None, Reflection::Descriptor::Attributes::deprecated(ServiceProvider::func_GetService));
static Reflection::EventDesc<ServiceProvider, void()> event_Closing(&ServiceProvider::closingSignal, "Close");
static Reflection::EventDesc<ServiceProvider, void()> event_ClosingLate(&ServiceProvider::closingLateSignal, "CloseLate", Security::LocalUser);
static Reflection::EventDesc<ServiceProvider, void(shared_ptr<Instance>)> event_ServiceAdded(&ServiceProvider::serviceAddedSignal, "ServiceAdded", "service");
static Reflection::EventDesc<ServiceProvider, void(shared_ptr<Instance>)> event_ServiceRemoving(&ServiceProvider::serviceRemovingSignal, "ServiceRemoving", "service");
REFLECTION_END();
ServiceProvider::ServiceProvider()
{
}
ServiceProvider::ServiceProvider(const char* name): Super(name)
{
}
size_t ServiceProvider::newIndex()
{
static rbx::atomic<int> index(-1);
return ++index;
}
shared_ptr<Instance> ServiceProvider::getPublicServiceByClassNameString(std::string sName)
{
const Name& serviceName = RBX::Name::lookup(sName);
if (serviceName.empty())
throw RBX::runtime_error("'%s' is not a valid Service name", sName.c_str());
shared_ptr<Instance> result = ServiceProvider::create(this, serviceName);
if(Service* service = dynamic_cast<Service*>(result.get())){
if(service->isPublic){
return result;
}
}
return shared_ptr<Instance>();
}
shared_ptr<Instance> ServiceProvider::findPublicServiceByClassNameString(std::string sName)
{
const Name& serviceName = RBX::Name::lookup(sName);
if (serviceName.empty())
throw RBX::runtime_error("'%s' is not a valid Service name", sName.c_str());
shared_ptr<Instance> result = findServiceByClassName(serviceName);
if(Service* service = dynamic_cast<Service*>(result.get())){
if(service->isPublic){
return result;
}
}
return shared_ptr<Instance>();
}
shared_ptr<Instance> ServiceProvider::findServiceByClassName(const RBX::Name& className) const
{
std::map<const RBX::Name*, shared_ptr<Instance> >::iterator iter = serviceMap.find(&className);
if (iter!=serviceMap.end())
return iter->second;
else
return shared_ptr<Instance>();
}
void ServiceProvider::onDescendantRemoving(const shared_ptr<Instance>& instance)
{
instance->onServiceProvider(this, NULL);
Super::onDescendantRemoving(instance);
}
void ServiceProvider::onDescendantAdded(Instance* instance)
{
Super::onDescendantAdded(instance);
instance->onServiceProvider(NULL, this);
}
void ServiceProvider::onChildRemoving(Instance* instance)
{
std::map<const RBX::Name*, shared_ptr<Instance> >::iterator iter = serviceMap.find(&instance->getClassName());
if (iter!=serviceMap.end())
serviceRemovingSignal(iter->second);
Super::onChildRemoving(instance);
}
void ServiceProvider::clearServices()
{
RBXASSERT(numChildren()==0);
serviceArray.clear();
serviceMap.clear();
}
void ServiceProvider::onChildAdded(Instance* instance)
{
// There should be only one ServiceProvider, I think
RBXASSERT(Instance::fastDynamicCast<ServiceProvider>(instance)==NULL);
Super::onChildAdded(instance);
Service* service = dynamic_cast<Service*>(instance);
if (service!=NULL)
{
shared_ptr<Instance> i = shared_from(instance);
if (instance->getClassName()!=RBX::Name::getNullName())
{
RBXASSERT_SLOW(findServiceByClassName(instance->getClassName())==NULL);
instance->lockParent();
serviceMap[&instance->getClassName()] = i;
}
serviceAddedSignal(i);
}
}
shared_ptr<Instance> ServiceProvider::createChild(const RBX::Name& className, RBX::CreatorRole creatorRole)
{
// If the childElement is data for a Service, then have an existing Service read the data
// rather than creating a new Service.
shared_ptr<Instance> instance = findServiceByClassName(className);
if (instance)
return instance;
else
return Super::createChild(className, creatorRole);
}
shared_ptr<Instance> ServiceProvider::create(Instance* context, const RBX::Name& name)
{
while (context!=NULL)
{
ServiceProvider* serviceProvider = context->fastDynamicCast<ServiceProvider>();
if (serviceProvider!=NULL)
{
shared_ptr<Instance> child = serviceProvider->createChild(name, EngineCreator);
if(dynamic_cast<Service*>(child.get())){
child->setParent(serviceProvider);
return child;
}
return shared_ptr<Instance>();
}
context = context->getParent();
}
return shared_ptr<Instance>();
}
}
+117
View File
@@ -0,0 +1,117 @@
#include "stdafx.h"
#include "v8tree/Verb.h"
#include "util/Name.h"
namespace RBX {
Verb::Verb(VerbContainer* container, const std::string& name, bool blacklisted)
: name(Name::declare(name.c_str()))
, container(container)
, verbSecurity(blacklisted)
{
if(container)
{
if (!blacklisted)
container->addWhitelistVerb(this);
else
container->addBlacklistVerb(this);
}
}
Verb::~Verb()
{
if (container!=NULL)
container->removeVerb(this);
}
VerbContainer::VerbContainer(VerbContainer* parent)
: parent(parent)
{
}
void VerbContainer::setVerbParent(VerbContainer* parent)
{
this->parent = parent;
}
VerbContainer::~VerbContainer()
{
// delete any remaining verbs
while (whitelistVerbs.begin()!=whitelistVerbs.end())
delete whitelistVerbs.begin()->second;
while (blacklistVerbs.begin()!=blacklistVerbs.end())
delete blacklistVerbs.begin()->second;
}
Verb* VerbContainer::getVerb(const std::string& name)
{
return getVerb(Name::lookup(name));
}
Verb* VerbContainer::getWhitelistVerb(const std::string& name)
{
return getWhitelistVerb(Name::lookup(name));
}
Verb* VerbContainer::getWhitelistVerb(const std::string& prefix, const std::string& name, const std::string& suffix)
{
return getWhitelistVerb(Name::lookup(prefix + name + suffix));
}
Verb* VerbContainer::getVerb(const Name& name)
{
if (name.empty())
return NULL;
std::map<const Name*, Verb*>::iterator iter = whitelistVerbs.find(&name);
if (iter!=whitelistVerbs.end())
return iter->second;
iter = blacklistVerbs.find(&name);
if (iter!=blacklistVerbs.end())
return iter->second;
if (parent!=NULL)
return parent->getVerb(name);
else
return NULL;
}
Verb* VerbContainer::getWhitelistVerb(const Name& name)
{
if (name.empty())
return NULL;
std::map<const Name*, Verb*>::iterator iter = whitelistVerbs.find(&name);
if (iter!=whitelistVerbs.end())
return iter->second;
if (parent!=NULL)
return parent->getWhitelistVerb(name);
else
return NULL;
}
void VerbContainer::addWhitelistVerb(Verb* verb)
{
RBXASSERT((whitelistVerbs.find(&verb->getName())==whitelistVerbs.end())
&& (blacklistVerbs.find(&verb->getName())==blacklistVerbs.end()));
whitelistVerbs[&verb->getName()] = verb;
}
void VerbContainer::addBlacklistVerb(Verb* verb)
{
RBXASSERT((whitelistVerbs.find(&verb->getName())==whitelistVerbs.end())
&& (blacklistVerbs.find(&verb->getName())==blacklistVerbs.end()));
blacklistVerbs[&verb->getName()] = verb;
}
void VerbContainer::removeVerb(Verb* verb)
{
int verEraseCount = whitelistVerbs.erase(&verb->getName()) + blacklistVerbs.erase(&verb->getName());
RBXASSERT(verEraseCount==1);
}
} // namespace RBX