Skip to content

Commit

Permalink
allow --objecthost plugin to pass options to various graphics subsyst…
Browse files Browse the repository at this point in the history
…ems. Add a new option to allow search paths to be passed in from the command line so that out-of-tree builds may actually pull in the correct javascript, thereby reenabling the mouse and iinput since the chrome done triggers were caused by successful javascript loads which required the appropriate symlinks, or better yet, the actual correct paths to be generated by the command line. This will also allow us to set width and height from the command line as well as other ogregraphics options.

The example mechanism for doing so is:
./cppoh_d --oh.plugin-search=/home/daniel/dev/elysia/externals/sirikata/..:/home/daniel/dev/elysia/externals/sirikata --oh.plugins=weight-exp,oh-sqlite,oh-file,weight-sqr,tcpsst,weight-const,ogregraphics,colladamodels,nvtt,common-filters,csvfactory,scripting-js,simplecamera --objecthost='--scriptManagers=simplecamera:{},js:{--import-paths=../../../externals/sirikata/liboh/plugins/js/scripts} --simOptions=ogregraphics:{--search_path=../../../externals/sirikata/libproxyobject/plugins/}' --object-factory-opts=--db=../scene.db
that runs it from out of tree where ../../../externals has the appropriate items
  • Loading branch information
danielrh committed Jun 18, 2011
1 parent e336d44 commit aa2e7e2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion libogre/include/sirikata/ogre/OgreRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class SIRIKATA_OGRE_EXPORT OgreRenderer : public TimeSteppedQueryableSimulation,
OptionValue *mParallaxShadowSteps;
OptionValue* mModelLights; // Use model or basic lights
OptionSet* mOptions;

std::vector<String> mSearchPaths;
Vector4f mBackgroundColor;
Vector3d mFloatingPointOffset;

Expand Down
54 changes: 37 additions & 17 deletions libogre/src/OgreRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ namespace {
// This is a generic search method. It searches upwards from the current
// directory for any of the specified files and returns the first path it finds
// that contains one of them.
std::string findResource(boost::filesystem::path* search_paths, uint32 nsearch_paths, bool want_dir = true, const std::string& start_path = ".", boost::filesystem::path default_ = boost::filesystem::complete(boost::filesystem::path("."))) {
std::string findResource(boost::filesystem::path* search_paths, uint32 nsearch_paths, const std::vector<String>&searchPoints, bool want_dir = true, const std::string& start_path = ".", boost::filesystem::path default_ = boost::filesystem::complete(boost::filesystem::path("."))) {
using namespace boost::filesystem;

path start_path_path = boost::filesystem::complete(start_path);

// FIXME there probably need to be more of these, including
// some absolute paths of expected installation locations.
// It should also be possible to add some from the options.
for(size_t offset = 0; offset < searchPoints.size(); offset++) {
for(uint32 spath = 0; spath < nsearch_paths; spath++) {
path full = start_path_path / searchPoints[offset] / search_paths[spath];
if (exists(full) && (!want_dir || is_directory(full)))
return full.string();
}
}

path search_offsets[] = {
path("."),
path(".."),
Expand All @@ -102,6 +107,7 @@ std::string findResource(boost::filesystem::path* search_paths, uint32 nsearch_p
};
uint32 nsearch_offsets = sizeof(search_offsets)/sizeof(*search_offsets);


for(uint32 offset = 0; offset < nsearch_offsets; offset++) {
for(uint32 spath = 0; spath < nsearch_paths; spath++) {
path full = start_path_path / search_offsets[offset] / search_paths[spath];
Expand All @@ -115,7 +121,7 @@ std::string findResource(boost::filesystem::path* search_paths, uint32 nsearch_p
}

// FIXME we really need a better way to figure out where our data is
std::string getOgreResourcesDir() {
std::string getOgreResourcesDir(const std::vector<String>&searchPoints) {
using namespace boost::filesystem;

// FIXME there probably need to be more of these
Expand All @@ -128,11 +134,11 @@ std::string getOgreResourcesDir() {
};
uint32 nsearch_paths = sizeof(search_paths)/sizeof(*search_paths);

return findResource(search_paths, nsearch_paths);
return findResource(search_paths, nsearch_paths, searchPoints);
}

// FIXME we really need a better way to figure out where our data is
std::string getBerkeliumBinaryDir() {
std::string getBerkeliumBinaryDir(const std::vector<String>&searchPoints) {
using namespace boost::filesystem;

// FIXME there probably need to be more of these
Expand All @@ -153,13 +159,13 @@ std::string getBerkeliumBinaryDir() {
};
uint32 nsearch_paths = sizeof(search_paths)/sizeof(*search_paths);

return findResource(search_paths, nsearch_paths);
return findResource(search_paths, nsearch_paths,searchPoints);
}

std::string getChromeResourcesDir() {
std::string getChromeResourcesDir(const std::vector<String>&searchPoints) {
using namespace boost::filesystem;

return (path(getOgreResourcesDir()) / "chrome").string();
return (path(getOgreResourcesDir(searchPoints)) / "chrome").string();
}

} // namespace
Expand Down Expand Up @@ -251,7 +257,6 @@ OgreRenderer::OgreRenderer(Context* ctx)
mSuspended(false),
mFloatingPointOffset(0,0,0),
mLastFrameTime(Task::LocalTime::now()),
mResourcesDir(getOgreResourcesDir()),
mModelParser( ModelsSystemFactory::getSingleton ().getConstructor ( "any" ) ( "" ) ),
mNextFrameScreenshotFile("")
{
Expand Down Expand Up @@ -287,7 +292,7 @@ bool OgreRenderer::initialize(const String& options, bool with_berkelium) {
OptionValue*renderBufferAutoMipmap;
OptionValue*grabCursor;
OptionValue* backColor;

OptionValue *searchPaths;
InitializeClassOptions("ogregraphics",this,
pluginFile=new OptionValue("pluginfile","",OptionValueType<String>(),"sets the file ogre should read options from."),
configFile=new OptionValue("configfile","ogre.cfg",OptionValueType<String>(),"sets the ogre config file for config options"),
Expand Down Expand Up @@ -315,14 +320,29 @@ bool OgreRenderer::initialize(const String& options, bool with_berkelium) {
mParallaxShadowSteps=new OptionValue("parallax-shadow-steps","10",OptionValueType<int>(),"Total number of steps for shadow parallax mapping (default 10)"),
new OptionValue("nearplane",".125",OptionValueType<float32>(),"The min distance away you can see"),
new OptionValue("farplane","5000",OptionValueType<float32>(),"The max distance away you can see"),
searchPaths=new OptionValue("search_path","../..",OptionValueType<String>(),"Colon separated list of places to search for Ogre data (eg ogre/data/chrome/js or ogre/data/chrome/ui)"),
mModelLights = new OptionValue("model-lights","false",OptionValueType<bool>(),"Whether to use a base set of lights or load lights dynamically from loaded models."),
backColor = new OptionValue("back-color","<.71,.785,.91,1>",OptionValueType<Vector4f>(),"Background color to clear render viewport to."),

NULL);
bool userAccepted=true;

(mOptions=OptionSet::getOptions("ogregraphics",this))->parse(options);


String search_path=searchPaths->as<String>();
if (search_path.length()) {
while (true) {
String::size_type where=search_path.find(":");
if (where==String::npos) {
mSearchPaths.push_back(search_path);
break;
}else {
mSearchPaths.push_back(search_path.substr(0,where));
search_path=search_path.substr(where+1);
}
}
}
mResourcesDir=getOgreResourcesDir(mSearchPaths);

mBackgroundColor = backColor->as<Vector4f>();

// Initialize this first so we can get it to not spit out to stderr
Expand Down Expand Up @@ -351,7 +371,7 @@ bool OgreRenderer::initialize(const String& options, bool with_berkelium) {
mCDNArchivePlugin = new CDNArchivePlugin;
sRoot->installPlugin(&*mCDNArchivePlugin);
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("", "CDN", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(getOgreResourcesDir(), "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(getOgreResourcesDir(mSearchPaths), "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(".", "FileSystem", "General");//FIXME get rid of this line of code: we don't want to load resources from $PWD

Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); /// Although t //just to test if the cam is setup ok ==>
Expand Down Expand Up @@ -474,7 +494,7 @@ bool OgreRenderer::initialize(const String& options, bool with_berkelium) {
sActiveOgreScenes.push_back(this);

if (with_berkelium)
new WebViewManager(0, mInputManager, getBerkeliumBinaryDir(), getOgreResourcesDir());
new WebViewManager(0, mInputManager, getBerkeliumBinaryDir(mSearchPaths), getOgreResourcesDir(mSearchPaths));

loadSystemLights();

Expand Down Expand Up @@ -515,7 +535,7 @@ bool ogreLoadPlugin(const String& _filename, const String& root = "") {
uint32 nsearch_paths = sizeof(search_paths)/sizeof(*search_paths);

path not_found;
path plugin_path = path(findResource(search_paths, nsearch_paths, false, root, not_found));
path plugin_path = path(findResource(search_paths, nsearch_paths, std::vector<String>(), false, root, not_found));
if (plugin_path == not_found)
return false;

Expand Down
4 changes: 3 additions & 1 deletion liboh/include/sirikata/oh/ObjectHost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ class SIRIKATA_OH_EXPORT ObjectHost : public ConnectionEventProvider, public Ser
ScriptManagerMap mScriptManagers;

std::tr1::unordered_map<String,OptionSet*> mSpaceConnectionProtocolOptions;

///options passed to initialization of scripts (usually path information)
std::map<std::string, std::string > mSimOptions;
typedef std::tr1::function<void(const SpaceID&, const ObjectReference&, ServerID, const TimedMotionVector3f&, const TimedMotionQuaternion&, const BoundingSphere3f&, const String&, const String&)> SessionConnectedCallback;
public:
String getSimOptions(const String&);
struct ConnectionInfo {
ServerID server;
TimedMotionVector3f loc;
Expand Down
2 changes: 1 addition & 1 deletion liboh/src/HostedObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void HostedObject::addSimListeners(PerPresenceData& pd, const String& simName,Ti
}

HO_LOG(info,String("[OH] Initializing ") + simName);
sim = SimulationFactory::getSingleton().getConstructor ( simName ) ( mContext, getSharedPtr(), pd.id(), "");
sim = SimulationFactory::getSingleton().getConstructor ( simName ) ( mContext, getSharedPtr(), pd.id(), getObjectHost()->getSimOptions(simName));
if (!sim)
{
HO_LOG(error,String("Unable to load ") + simName + String(" plugin. The PATH environment variable is ignored, so make sure you have copied the DLLs from dependencies/ogre/bin/ into the current directory. Sorry about this!"));
Expand Down
13 changes: 11 additions & 2 deletions liboh/src/ObjectHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ ObjectHost::ObjectHost(ObjectHostContext* ctx, Network::IOService *ioServ, const
mScriptPlugins=new PluginManager;
OptionValue *protocolOptions;
OptionValue *scriptManagers;
OptionValue *simOptions;
InitializeClassOptions ico("objecthost",this,
protocolOptions=new OptionValue("protocols","",OptionValueType<std::map<std::string,std::string> >(),"passes options into protocol specific libraries like \"tcpsst:{--send-buffer-size=1440 --parallel-sockets=1},udp:{--send-buffer-size=1500}\""),
scriptManagers=new OptionValue("scriptManagers","simplecamera:{},js:{}",OptionValueType<std::map<std::string,std::string> >(),"Instantiates script managers with specified options like \"simplecamera:{},js:{--import-paths=/path/to/scripts}\""),
simOptions=new OptionValue("simOptions","ogregraphics:{}",OptionValueType<std::map<std::string,std::string> >(),"Passes initialization strings to simulations, by name"),

NULL);

OptionSet* oh_options = OptionSet::getOptions("objecthost",this);
oh_options->parse(options);

mSimOptions=simOptions->as<std::map<std::string,std::string> > ();
{
std::map<std::string,std::string> *options=&protocolOptions->as<std::map<std::string,std::string> > ();
for (std::map<std::string,std::string>::iterator i=options->begin(),ie=options->end();i!=ie;++i) {
Expand Down Expand Up @@ -308,5 +311,11 @@ ProxyManager *ObjectHost::getProxyManager(const SpaceID&space) const
NOT_IMPLEMENTED(oh);
return NULL;
}

String ObjectHost::getSimOptions(const String&simName){
std::string nam=simName;
std::map<std::string,std::string>::iterator where=mSimOptions.find(nam);
if (where==mSimOptions.end()) return String();
std::string retval=where->second;
return String(retval);
}
} // namespace Sirikata

0 comments on commit aa2e7e2

Please sign in to comment.