From: <spo...@us...> - 2008-06-15 12:14:11
|
Revision: 910 http://opengate.svn.sourceforge.net/opengate/?rev=910&view=rev Author: spom_spom Date: 2008-06-15 05:14:18 -0700 (Sun, 15 Jun 2008) Log Message: ----------- change xml-format for sector description, it can be saved by ogeditor and loaded by the client Modified Paths: -------------- branches/ogEditor/generate_code.py branches/ogEditor/ogEditor.py branches/ogEditor/ogtest.py branches/ogEditor/python_opengate.h trunk/plugins.cfg trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObject.h trunk/src/SectorObjectMoveable.cpp trunk/src/Station.cpp trunk/src/common.h trunk/src/commonWithOgre.h Added Paths: ----------- branches/ogEditor/src/OpenGateSpecs.py trunk/data/misc/test.sector Modified: branches/ogEditor/generate_code.py =================================================================== --- branches/ogEditor/generate_code.py 2008-06-11 21:08:31 UTC (rev 909) +++ branches/ogEditor/generate_code.py 2008-06-15 12:14:18 UTC (rev 910) @@ -135,10 +135,13 @@ #mb.class_( '::std::set < ::std::string >' ).alias = 'stringSet'; excludeClass( mb, [ 'deletePtr' - ,'GameStateListener' + ,'AiManager' + ,'GameStateListener' ,'GameStateManager' ,'Message' ,'MessageBodyBase' + ,'MessageBodyShipAmmoHit' + ,'MessageBodyShipDeRegister' ,'OpenALSoundSource' ] ) Modified: branches/ogEditor/ogEditor.py =================================================================== --- branches/ogEditor/ogEditor.py 2008-06-11 21:08:31 UTC (rev 909) +++ branches/ogEditor/ogEditor.py 2008-06-15 12:14:18 UTC (rev 910) @@ -14,18 +14,12 @@ import wx.lib.customtreectrl as CT -from ObjectInspectorPanels import * -from ResourceTreePane import * +from ObjectInspectorPanels import * +from ResourceTreePane import * -from OgreWindowWx import * +from OgreWindowWx import * +from SectorXMLWriter import * -try: - import opengate as og - haveOpenGatePlugin = True -except: - haveOpenGatePlugin = False - pass - ID_MB_FILE_EXIT = wx.NewId() ID_MB_VIEW_SCENETREE = wx.NewId() ID_MB_VIEW_OBJECT = wx.NewId() @@ -45,69 +39,10 @@ activeResource = None; def __init__(self): Pass - -class Opengate: - resourceManager_ = None - - def __init__( self, OgreWindow ): - self.resourceManager_ = og.ResourceManager() - self.resourceManager_.logManager = og.LogManager() - self.resourceManager_.entityManager = og.EntityManager( ) - self.resourceManager_.ogreRoot = OgreWindow.ogreRoot - self.resourceManager_.renderWindow = OgreWindow.renderWindow +from OpenGateSpecs import * - OgreWindow.AddResources( "opengate-resources.cfg" ) - ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup( "Opengate" ) - - for res in OgreWindow.resourceLocations: - self.resourceManager_.addResourceLocation( res[0], res[1] ) - - def initOpenGateResources_( self ): - self.resourceManager_.loadGlobalIDs( "ids.xml" ) - entityManager = self.resourceManager_.entityManager - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "commodities" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "engines" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "capacitors" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "radars" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "shields" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "ecms" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "power_plants" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "guns" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "missiles" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "ships" ); - entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "stations" ); - - def getName( self ): - return "Opengate" - - def fillProperties( self, objectInspectorPanel ): - objectInspectorPanel.typeStaticText.SetLabel( "Opengate" ) - shaderSchemes = ( "Default", "vpOnly", "vpfp" ) - vp = self.resourceManager_.renderWindow.getViewport( 0 ) - self.interpolModeChosser = objectInspectorPanel.propertyGrid.appendRowItemChoice( "shader scheme", - value = "Default", - itemList = shaderSchemes, - cback = vp.setMaterialScheme ) - - def AddToResourcesTree( self, tree, node): - - if self.resourceManager_: - ogResManNode = tree.AppendItem( node, "OpenGate resource manager" ) - - if self.resourceManager_.entityManager: - ogEntityManagerNode = tree.AppendItem( ogResManNode, "Entity manager" ) - categories = self.resourceManager_.entityManager.categories(); - - for category in categories: - categoryNode = tree.AppendItem( ogEntityManagerNode, category ) - - - def AddToSceneGraph( self, tree, node ): - opengateNode = tree.AppendItem( node, "Opengate" ) - tree.SetPyData( opengateNode, self ) - class DropData(wx.CustomDataObject): def __init__(self): wx.CustomDataObject.__init__(self, wx.CustomDataFormat("MyDropData")) @@ -230,8 +165,8 @@ ws = WorkSpace self.allPanes = [] self.allPanes.append( OGEditorPane( ID_MB_VIEW_SCENETREE, NAME_SCENETREE, "\tF1", None, True ) ) - self.allPanes.append( OGEditorPane( ID_MB_VIEW_OBJECT, NAME_OBJECT , "\tF2", None, False ) ) - self.allPanes.append( OGEditorPane( ID_MB_VIEW_RESOURCE, NAME_RESOURCE , "\tF3", None, True ) ) + self.allPanes.append( OGEditorPane( ID_MB_VIEW_OBJECT, NAME_OBJECT , "\tF2", None, True ) ) + self.allPanes.append( OGEditorPane( ID_MB_VIEW_RESOURCE, NAME_RESOURCE , "\tF3", None, False ) ) self.allPanes.append( OGEditorPane( ID_MB_VIEW_MATERIAL, NAME_MATERIAL , "\tF4", None, False ) ) self.allPanes.append( OGEditorPane( ID_MB_VIEW_PYCRUST, NAME_PYCRUST , "\tF9", None, False ) ) @@ -379,9 +314,9 @@ self.resourceTree = ResourceTreePane( self, -1, wx.Point( 0, 0 ), wx.Size( 160, 250 ), wx.TR_DEFAULT_STYLE | wx.NO_BORDER ); self.Bind( wx.EVT_TREE_SEL_CHANGED, self.doSelectTreeObject, self.resourceTree ) - self.resourceTree.Bind( wx.EVT_TREE_BEGIN_DRAG, self.OnBeginDrag ) - self.resourceTree.Bind( wx.EVT_TREE_BEGIN_RDRAG, self.OnBeginRDrag ) - self.resourceTree.Bind( wx.EVT_TREE_END_DRAG, self.OnEndDrag ) + self.resourceTree.Bind( wx.EVT_TREE_BEGIN_DRAG, self.OnBeginDrag ) + self.resourceTree.Bind( wx.EVT_TREE_BEGIN_RDRAG, self.OnBeginRDrag ) + self.resourceTree.Bind( wx.EVT_TREE_END_DRAG, self.OnEndDrag ) return self.resourceTree def setDefaultProperties_( self ): Modified: branches/ogEditor/ogtest.py =================================================================== --- branches/ogEditor/ogtest.py 2008-06-11 21:08:31 UTC (rev 909) +++ branches/ogEditor/ogtest.py 2008-06-15 12:14:18 UTC (rev 910) @@ -33,18 +33,21 @@ global ogResourceManager - self.ogreRenderWindow = OgreWindow( self, ID = -1, ogResourceMan = ogResourceManager ) + self.ogreRenderWindow = OgreWindow( self, ID = -1 ) + self.ogreRenderWindow.AddResources( "opengate-resources.cfg" ) + ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup( "Opengate" ) - mops = og.Mops(); - print mops.name() - print mops.getVec() - ogLog = og.LogManager(); ogResourceManager.logManager = ogLog + + + for res in self.ogreRenderWindow.resourceLocations: + ogResourceManager.addResourceLocation( res[0], res[1] ) + ogResourceManager.loadGlobalIDs( "ids.xml" ); entityManager = og.EntityManager( ) ogResourceManager.entityManager = entityManager - entityManager.load( ogResourceManager.resourceLocations( "General" ), "commodities" ); + entityManager.load( ogResourceManager.resourceLocations( "Opengate" ), "commodities" ); self.SetMenuBar( self.mb ) self.Bind( wx.EVT_MENU, self.doExit, id = wx.ID_EXIT ) Modified: branches/ogEditor/python_opengate.h =================================================================== --- branches/ogEditor/python_opengate.h 2008-06-11 21:08:31 UTC (rev 909) +++ branches/ogEditor/python_opengate.h 2008-06-15 12:14:18 UTC (rev 910) @@ -47,21 +47,6 @@ // #include "networkClient.h" //#include "networkProtocol.h" -namespace OpenGate{ - class Mops{ - public: - Mops(){} - std::string name(){ return "Mops";} - Ogre::Vector3 getVec(){ return pos_;} - void * voidPtr(){ return NULL; } - void vec( const Ogre::Vector3 & pos ){ - std::cout << pos << std::endl; - } - private: - Ogre::Vector3 pos_; - }; -} - //First we create a magic namespace to hold all our aliases namespace pyplusplus { namespace aliases { #include "python_opengate_aliases.h" Added: branches/ogEditor/src/OpenGateSpecs.py =================================================================== --- branches/ogEditor/src/OpenGateSpecs.py (rev 0) +++ branches/ogEditor/src/OpenGateSpecs.py 2008-06-15 12:14:18 UTC (rev 910) @@ -0,0 +1,222 @@ +import sys +from OgreWindowWx import * + +try: + import opengate as og + haveOpenGatePlugin = True +except: + haveOpenGatePlugin = False + pass + +class Opengate: + resourceManager_ = None + sceneTree_ = None + + def __init__( self, OgreWindow ): + + self.resourceManager_ = og.ResourceManager() + self.resourceManager_.logManager = og.LogManager() + self.resourceManager_.entityManager = og.EntityManager( ) + self.resourceManager_.ogreRoot = OgreWindow.ogreRoot + self.resourceManager_.renderWindow = OgreWindow.renderWindow + + OgreWindow.AddResources( "opengate-resources.cfg" ) + ogre.ResourceGroupManager.getSingleton().initialiseResourceGroup( "Opengate" ) + + for res in OgreWindow.resourceLocations: + self.resourceManager_.addResourceLocation( res[0], res[1] ) + + def initOpenGateResources_( self ): + self.resourceManager_.loadGlobalIDs( "ids.xml" ) + entityManager = self.resourceManager_.entityManager + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "commodities" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "engines" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "capacitors" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "radars" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "shields" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "ecms" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "power_plants" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "guns" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "missiles" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "ships" ); + entityManager.load( self.resourceManager_.resourceLocations( "Opengate" ), "stations" ); + + def getName( self ): + return "Opengate" + + def fillProperties( self, objectInspectorPanel ): + objectInspectorPanel.typeStaticText.SetLabel( "Opengate" ) + shaderSchemes = ( "Default", "vpOnly", "vpfp" ) + vp = self.resourceManager_.renderWindow.getViewport( 0 ) + self.interpolModeChosser = objectInspectorPanel.propertyGrid.appendRowItemChoice( "shader scheme", + value = "Default", + itemList = shaderSchemes, + cback = vp.setMaterialScheme ) + objectInspectorPanel.propertyGrid.appendRowItemFileSelect("Load sector", cback = self.LoadSectorScene, + toolTip = "Load sector", wildcard = "*.sector") + objectInspectorPanel.propertyGrid.appendRowItemFileSelect("Save sector", cback = self.SaveSectorScene, + toolTip = "Save scene", wildcard = "*.sector") + + def AddToResourcesTree( self, tree, node): + self.sceneTree_ = tree; + if self.resourceManager_: + ogResManNode = tree.AppendItem( node, "OpenGate resource manager" ) + + if self.resourceManager_.entityManager: + ogEntityManagerNode = tree.AppendItem( ogResManNode, "Entity manager" ) + categories = self.resourceManager_.entityManager.categories(); + + for category in categories: + categoryNode = tree.AppendItem( ogEntityManagerNode, category ) + + + def AddToSceneGraph( self, tree, node ): + opengateNode = tree.AppendItem( node, "Opengate" ) + tree.SetPyData( opengateNode, self ) + + def SaveSectorScene( self, name ): + out = open( name, 'w') + #out = sys.stdout + sectorWriter = SectorXMLWriter( out, 'utf-8') + sectorWriter.writeEnvironment( self.sector.sceneManager() ) + #sectorWriter.writeStation("test-station") + #sectorWriter.writeNode("test") + + for obj in self.sector.sectorObjects(): + sectorWriter.writeObject( obj ) + + sectorWriter.close() + print "save sector", name + + def LoadSectorScene( self, name ): + print "load sector", name + +from xml.sax import saxexts, saxlib, saxutils +from xml.sax.saxutils import XMLGenerator +from xml.sax.xmlreader import AttributesImpl +from xml.sax.xmlreader import AttributesNSImpl +import string + +class SectorXMLWriter(): + def __init__( self, output, encoding): + + self.logger_ = XMLGenerator( output, encoding ) + self.logger_.startDocument() + attrs = AttributesImpl({ + u'name': 'testsector' + }) + self.logger_.startElement( u'sector',attrs) + self.logger_.characters("\n") + + def writeEnvironment( self, sceneManager ): + attrs = AttributesImpl({ u'skybox': "OpenGate/SimpleSkyBox3" }) + self.logger_.startElement( u'environment', attrs) + self.logger_.characters("\n") + self.writeColour( u'ambient', sceneManager.getAmbientLight() ) + self.logger_.endElement( u'environment' ) + self.logger_.characters("\n") + + def writeObject( self, obj ): + if type( obj ) == og.StationObject: + self.writeStation( obj ) + elif type( obj ) == og.BeaconObject: + self.writeBeacon( obj ) + else: + self.writeSectorObject( obj ) + + def writeStation( self, obj ): + attrs = AttributesImpl({ u'name': obj.name() }) + self.logger_.startElement( u'station', attrs) + self.logger_.characters("\n") + self.writeVec3( u'position', obj.mainNode().getWorldPosition() ) + #self.writeVec3( u'direction', obj.mainNode().getDirection() ) + #self.writeVec3( u'scale', obj.mainNode().getScale() ) + #self.writeEntity( u'mesh.mesh' ) + self.logger_.endElement( u'station' ) + self.logger_.characters("\n") + + def writeBeacon( self, obj ): + attrs = AttributesImpl({}) + self.logger_.startElement( u'beacon', attrs) + self.logger_.characters("\n") + self.writeVec3( u'position', obj.mainNode().getWorldPosition() ) + #self.writeVec3( u'direction', obj.mainNode().getDirection() ) + #self.writeVec3( u'scale', obj.mainNode().getScale() ) + self.logger_.endElement( u'beacon') + self.logger_.characters("\n") + + def writeSectorObject( self, obj ): + attrs = AttributesImpl({u'name': obj.name() }) + self.logger_.startElement( u'sectorobject', attrs) + self.logger_.characters("\n") + self.writeVec3( u'position', obj.mainNode().getWorldPosition() ) + #self.writeVec3( u'direction', obj.mainNode().getDirection() ) + self.writeVec3( u'scale', obj.scaleNode().getScale() ) + self.writeEntity( obj.entity() ) + self.logger_.endElement( u'sectorobject') + self.logger_.characters("\n") + + def writeNode( self, name ): + + attrs = AttributesImpl({ + u'name': name }) + + self.logger_.startElement( u'node', attrs) + self.logger_.characters("\n") + self.writeVec3( u'position', [0,0,0] ) + self.writeVec3( u'scale', [1.0, 1.1, 1.0] ) + self.writeQuat( u'rotation', [0.0, 0.0, 0.0, 1.0] ) + #self.writeEntity( u'mesh.mesh' ) + #self.logger_.characters("msg") + self.logger_.endElement( u'node' ) + self.logger_.characters("\n") + + def writeVec3( self, name, vec): + attrs = AttributesImpl({ + u'x': "%g"%vec[0], + u'y': "%g"%vec[1], + u'z': "%g"%vec[2] + }) + self._writeElement( name, attrs ) + + def writeQuat( self, name, quat): + attrs = AttributesImpl({ + u'x': "%g"%quat[0], + u'y': "%g"%quat[1], + u'z': "%g"%quat[2], + u'w': "%g"%quat[3] + }) + self._writeElement( name, attrs ) + + def writeColour( self, name, quat): + attrs = AttributesImpl({ + u'r': "%g"%quat[0], + u'g': "%g"%quat[1], + u'b': "%g"%quat[2], + u'a': "%g"%quat[3] + }) + self._writeElement( name, attrs ) + + def writeEntity( self, entity): + nSubEnt= entity.getNumSubEntities() + atts = { + u'meshFile': entity.getMesh().getName(), + u'numSubEntities': "%d"%nSubEnt + } + + for i in range(0,nSubEnt): + atts[u'material-%d'%i] = entity.getSubEntity( i ).getMaterialName() + + attrs = AttributesImpl( atts ) + + self._writeElement( "entity", attrs ) + + def _writeElement( self, name, attrs ): + self.logger_.startElement( name, attrs) + self.logger_.endElement( name) + self.logger_.characters("\n") + + def close( self ): + self.logger_.endElement( u'sector') + self.logger_.characters("\n") + self.logger_.endDocument() \ No newline at end of file Added: trunk/data/misc/test.sector =================================================================== --- trunk/data/misc/test.sector (rev 0) +++ trunk/data/misc/test.sector 2008-06-15 12:14:18 UTC (rev 910) @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<sector name="testsector"> +<environment skybox="OpenGate/SimpleSkyBox3"> +<ambient a="1" r="0.1" b="0.1" g="0.1"></ambient> +</environment> +<station name="Tauseti Wake"> +<position y="0" x="0" z="-1480"></position> +</station> +<sectorobject name="ring"> +<position y="100" x="-650" z="800"></position> +<scale y="35" x="35" z="35"></scale> +<entity meshFile="ring.mesh" material-0="ring/main" numSubEntities="1"></entity> +</sectorobject> +<beacon> +<position y="0" x="-650" z="800"></position> +</beacon> +<sectorobject name="astro with bump"> +<position y="0" x="-250" z="440"></position> +<scale y="20" x="20" z="20"></scale> +<entity meshFile="asteroid01.mesh" material-0="Asteroid/BumpMapping" numSubEntities="1"></entity> +</sectorobject> +<sectorobject name="astro without bump"> +<position y="0" x="-250" z="500"></position> +<scale y="20" x="20" z="20"></scale> +<entity meshFile="asteroid01.mesh" material-0="Asteroid" numSubEntities="1"></entity> +</sectorobject> +</sector> Modified: trunk/plugins.cfg =================================================================== --- trunk/plugins.cfg 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/plugins.cfg 2008-06-15 12:14:18 UTC (rev 910) @@ -6,5 +6,5 @@ # Define D3D rendering implementation plugin Plugin=RenderSystem_GL.so Plugin=Plugin_ParticleFX.so -#Plugin=Plugin_CgProgramManager.so +Plugin=Plugin_CgProgramManager.so Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/Sector.cpp 2008-06-15 12:14:18 UTC (rev 910) @@ -42,6 +42,7 @@ #include <OgreOverlayManager.h> #include <OgreOverlayContainer.h> #include <OgreSceneNode.h> +#include <OgreSubEntity.h> #include <OgreEntity.h> #include <OgreRoot.h> #include <OgreRenderSystemCapabilities.h> @@ -125,12 +126,12 @@ //*** end starfield test 2; - Ogre::Light * mainLight = sceneMgr_->createLight("MainLight" ); - mainLight->setDiffuseColour( 0.1, 0.1, 0.1 ); - mainLight->setSpecularColour( 0.4, 0.4, 0.4 ); - mainLight->setPosition(-50000, 0, -40000 ); +// Ogre::Light * mainLight = sceneMgr_->createLight("MainLight" ); +// mainLight->setDiffuseColour( 0.1, 0.1, 0.1 ); +// mainLight->setSpecularColour( 0.4, 0.4, 0.4 ); +// mainLight->setPosition(-50000, 0, -40000 ); - sceneMgr_->setAmbientLight( Ogre::ColourValue( 0.1, 0.1, 0.1 ) ); + // sceneMgr_->setAmbientLight( Ogre::ColourValue( 0.1, 0.1, 0.1 ) ); if ( 1 ) { // planet_ = new Planet( "planet", sceneMgr_, Ogre::Vector3( 20000.0, 10000.0, 40000 ), 15000.0f, 32 ); @@ -139,7 +140,7 @@ } - populate( "testsector.xml" ); + populate( "test.sector" ); createKoordAxis( ); } @@ -181,41 +182,110 @@ } void Sector::populate( const std::string & fileName ){ - TiXmlDocument doc( ResourceManager::getSingleton().findFullFileName( fileName ) ); - bool loadOkay = doc.LoadFile(); + TiXmlDocument doc( ResourceManager::getSingleton().findFullFileName( fileName ) ); + bool loadOkay = doc.LoadFile(); - if ( !loadOkay ) { - log_->fatal( std::string( "Failed to load sector file: " + fileName ) ); - return; - } + if ( !loadOkay ) { + log_->fatal( std::string( "Failed to load sector file: " + fileName ) ); + return; + } - TiXmlHandle docHandle( &doc ); - TiXmlElement *pElem, *pSubElem; - TiXmlHandle hRoot( 0 ); + TiXmlHandle docHandle( &doc ); + TiXmlElement *pElem, *pSubElem; + TiXmlHandle hRoot( 0 ); - pElem = docHandle.FirstChildElement().Element(); - hRoot = TiXmlHandle( pElem ); + pElem = docHandle.FirstChildElement().Element(); + hRoot = TiXmlHandle( pElem ); - if ( !pElem ) { - log_->fatal( fileName + " cannot read first node." ); - return; - } + if ( !pElem ) { + log_->fatal( fileName + " cannot read first node." ); + return; + } - if ( strcmp( "sector", pElem->Value() ) != 0 ) { - log_->fatal( fileName + " is no sector description" ); + if ( strcmp( "sector", pElem->Value() ) != 0 ) { + log_->fatal( fileName + " is no sector description" ); + return; + } + readXMLAttribute< std::string >( pElem, "name_en name", this, &OpenGate::Sector::setName, false ); + + pElem = hRoot.ChildElement( "environment", 0 ).Element(); + if ( pElem ){ + readXMLAttribute< std::string >( pElem, "skybox", this, &OpenGate::Sector::setSkyBox, false ); + readXMLColourElement( pElem, "ambient", sceneMgr_, &Ogre::SceneManager::setAmbientLight, false ); + } + + pElem = hRoot.ChildElement( "station", 0 ).Element(); + if ( pElem ){ + std::string name; readXMLAttribute < std::string >( pElem, "name", name ); + Ogre::Vector3 pos( readXMLVec3Element( pElem, "position" ) ); + SectorObject *obj = createStation( name, pos ); + } + + pElem = hRoot.ChildElement( "beacon", 0 ).Element(); + if ( pElem ){ + Ogre::Vector3 pos( readXMLVec3Element( pElem, "position" ) ); + Ogre::Vector3 dir( readXMLVec3Element( pElem, "direction" ) ); + SectorObject * obj = createBeacon( pos ); + obj->mainNode()->setDirection( dir ); + } + + for ( pElem = hRoot.FirstChild( "sectorobject" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement("sectorobject") ) { + std::string name; readXMLAttribute < std::string >( pElem, "name", name ); + Ogre::Vector3 pos( readXMLVec3Element( pElem, "position" ) ); + Ogre::Vector3 scale( readXMLVec3Element( pElem, "scale" ) ); + + TiXmlElement * pElemChild = pElem->FirstChildElement( "entity" ); + + if ( pElemChild ){ + std::string mesh; readXMLAttribute < std::string >( pElemChild, "meshFile", mesh ); + SectorObject * obj = createStaticObject( mesh, name, pos ); + if ( scale != Ogre::Vector3::ZERO ){ + obj->scale( scale ); + } + int nSubEnt = 0; readXMLAttribute < int >( pElemChild, "numSubEntities", nSubEnt ); + + for ( int i = 0; i < nSubEnt; i ++ ){ + std::string matName; readXMLAttribute < std::string >( pElemChild, "material-"+toStr( i ), matName ); + obj->entity()->getSubEntity( i )->setMaterialName( matName ); + } + + } else{ + std::cerr << "no entity found for sectorobject: " << name << std::endl; + } + } + return; - } - readXMLNode< std::string >( hRoot, "name_en name", this, &OpenGate::Sector::setName, false ); - pElem = hRoot.ChildElement( "skybox", 0 ).Element(); - if ( pElem ){ - sceneMgr_->setSkyBox( true, pElem->FirstChild()->Value(), 10000 ); - } else{ - sceneMgr_->setSkyBox( true, "OpenGate/SimpleSkyBox1" ); - } - -// pElem = hRoot.ChildElement( "vesselschool", 0 ).Element(); +// for ( pElem = hRoot.FirstChild( "station" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement("station") ) { +// std::string name; +// pSubElem = pElem->FirstChildElement( "name" ); +// if ( pSubElem ){ +// name = pSubElem->FirstChild()->Value(); +// } else { +// log_->warn( "missing name for station " ); +// continue; +// } +// Ogre::Vector3 pos( 0.0, 0.0, 0.0); +// pSubElem = pElem->FirstChildElement( "position" ); +// if ( pSubElem ){ +// pos = Ogre::Vector3( &toVector3( pSubElem->FirstChild()->Value(), ',' )[ 0 ] ); +// } else { +// log_->warn( "missing pos for station " + name ); +// continue; +// } +// SectorObject *obj = createStation( name, pos ); +// +// Ogre::Vector3 targetDirection( 0.0, 0.0, 0.0); +// pSubElem = pElem->FirstChildElement( "direction" ); +// if ( pSubElem ){ +// targetDirection = Ogre::Vector3( &toVector3( pSubElem->FirstChild()->Value(), ',' )[0]); +// Ogre::Quaternion rot = ( obj->mainNode()->getOrientation().zAxis()* -1.0).getRotationTo( targetDirection ); +// obj->mainNode()->rotate( rot ); +// } +// } + + // pElem = hRoot.ChildElement( "vesselschool", 0 ).Element(); // if ( pElem ){ // std::string schoolclass( pElem->FirstChild()->Value() ); // @@ -241,34 +311,8 @@ // } //** Load stations - for ( pElem = hRoot.FirstChild( "station" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement("station") ) { - std::string name; - pSubElem = pElem->FirstChildElement( "name" ); - if ( pSubElem ){ - name = pSubElem->FirstChild()->Value(); - } else { - log_->warn( "missing name for station " ); - continue; - } - Ogre::Vector3 pos( 0.0, 0.0, 0.0); - pSubElem = pElem->FirstChildElement( "position" ); - if ( pSubElem ){ - pos = Ogre::Vector3( &toVector3( pSubElem->FirstChild()->Value(), ',' )[ 0 ] ); - } else { - log_->warn( "missing pos for station " + name ); - continue; - } - SectorObject *obj = createStation( name, pos ); - - Ogre::Vector3 targetDirection( 0.0, 0.0, 0.0); - pSubElem = pElem->FirstChildElement( "direction" ); - if ( pSubElem ){ - targetDirection = Ogre::Vector3( &toVector3( pSubElem->FirstChild()->Value(), ',' )[0]); - Ogre::Quaternion rot = ( obj->mainNode()->getOrientation().zAxis()* -1.0).getRotationTo( targetDirection ); - obj->mainNode()->rotate( rot ); - } - } + //** load beacon pElem = hRoot.FirstChild( "beacon" ).Element(); if ( pElem ){ @@ -374,6 +418,10 @@ } } +void Sector::setSkyBox( const std::string & name ){ + sceneMgr_->setSkyBox( true, name, 10000 ); +} + void Sector::update( Ogre::Real elapsedTime ){ if ( ResourceManager::getSingleton().collisionManager ) ResourceManager::getSingleton().collisionManager->update( elapsedTime ); Modified: trunk/src/Sector.h =================================================================== --- trunk/src/Sector.h 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/Sector.h 2008-06-15 12:14:18 UTC (rev 910) @@ -53,8 +53,10 @@ void populate( const std::string & fileName ); + void setSkyBox( const std::string & name ); + void setListener( UnDockedState * listener ){ listener_ = listener; } - + UnDockedState * listener( ){ return listener_; } /*! Set the name of this sector */ @@ -80,6 +82,8 @@ SectorObjectMissile * createMissile( const Ogre::String & name, Uint32 userId, Uint8 childId, Missile & missile ); + std::set< SectorObject * > sectorObjects() const { return sectorObjects_; } + void createAvatarObject( Avatar & avatar ); SectorObjectAvatar * avatarObject() { return avatar_; } Modified: trunk/src/SectorObject.h =================================================================== --- trunk/src/SectorObject.h 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/SectorObject.h 2008-06-15 12:14:18 UTC (rev 910) @@ -55,8 +55,10 @@ /*! Return pointer to the active sector.*/ Sector * sector() { return sector_; } - Ogre::SceneNode * rotnode() { return mainNodeEntityRot_;} + Ogre::SceneNode * rotNode() { return mainNodeEntityRot_;} + Ogre::SceneNode * scaleNode() { return mainNodeEntityScale_;} + virtual bool update( Ogre::Real elapsedTime ){ return true; } void setShape( const Ogre::String & meshname ); Modified: trunk/src/SectorObjectMoveable.cpp =================================================================== --- trunk/src/SectorObjectMoveable.cpp 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/SectorObjectMoveable.cpp 2008-06-15 12:14:18 UTC (rev 910) @@ -397,7 +397,7 @@ int nEmits = thrusterParticles_->getNumEmitters( ); // Ogre::Real thrustRate = 0.0; // if ( maxThrust() > 0 ) thrustRate = (float)thrust_ / maxThrust_ * 100.0; - std::cout << "SectorObjectMoveable::updateThruster()" << name_ << " " << thrustRate_ << " " << nEmits << std::endl; + //std::cout << "SectorObjectMoveable::updateThruster()" << name_ << " " << thrustRate_ << " " << nEmits << std::endl; for ( int i = 0; i < nEmits; i ++ ){ Ogre::ParticleEmitter * pEmit; Modified: trunk/src/Station.cpp =================================================================== --- trunk/src/Station.cpp 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/Station.cpp 2008-06-15 12:14:18 UTC (rev 910) @@ -77,7 +77,7 @@ } Pad::Pad( const std::string & name, SectorObject * parent, Ogre::SubEntity * padSubEntity ) - : BaseObject( name, parent->sector(), 0, 0, parent->rotnode() ), parent_( parent ){ + : BaseObject( name, parent->sector(), 0, 0, parent->rotNode() ), parent_( parent ){ padManualObject_ = sceneMgr_->createManualObject( mainNode_->getName() + "/ManualObject" ); Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/common.h 2008-06-15 12:14:18 UTC (rev 910) @@ -282,10 +282,47 @@ return results.size(); } -struct deletePtr{ - template < typename T > void operator()( T * p ) { delete p; p = NULL; } -}; +struct deletePtr{ template < typename T > void operator()( T * p ) { delete p; p = NULL; } }; +template < class ValueType > +bool readXMLAttribute( TiXmlElement * pElem, const std::string & name, ValueType & val ){ + std::vector < std::string > names( getSubstrings( name ) ); + for ( uint i = 0; i < names.size(); i ++ ) { + if ( pElem->Attribute( names[ i ] ) ){ + val = to< ValueType >( *pElem->Attribute( names[ i ] ) ); + return true; + } + } + return false; +} + +/*! Read a single xml-element with a given key and fill associated object properties. +If the mandatory flag is set, a std::invalid_argument exception is thrown when the node can not be found.*/ +template < class ValueType, class Class, class Method > +bool readXMLAttribute( TiXmlElement * pElem, const std::string & name, Class * obj, Method method, bool mandatory ){ + +// std::vector < std::string > names( getSubstrings( name ) ); +// +// for ( uint i = 0; i < names.size(); i ++ ) { +// if ( pElem->Attribute( names[ i ] ) ){ +// (obj->*method)( to< ValueType >( *pElem->Attribute( names[ i ] ) ) ); +// return true; +// } +// } + + ValueType val; + bool ret = readXMLAttribute< ValueType >( pElem, name, val ); + if ( ret ){ + (obj->*method)( val ); + return true; + } + + if ( mandatory ){ + throw std::invalid_argument( "Missing mandatory xml node " + name + " for entity " + obj->name() ); + } + return false; +} + /*! Read a single xml-node with a given key and fill associated object properties. If the mandatory flag is set, a std::invalid_argument exception is thrown when the node can not be found.*/ template < class ValueType, class Class, class Method > Modified: trunk/src/commonWithOgre.h =================================================================== --- trunk/src/commonWithOgre.h 2008-06-11 21:08:31 UTC (rev 909) +++ trunk/src/commonWithOgre.h 2008-06-15 12:14:18 UTC (rev 910) @@ -32,12 +32,14 @@ #ifndef _OPENGATE_COMMONWITHOGRE__H #define _OPENGATE_COMMONWITHOGRE__H +#include "tinyxml/tinyxml.h" #include "common.h" #include "networkProtocol.h" #include <OgrePrerequisites.h> #include <OgreVector3.h> #include <OgreQuaternion.h> +#include <OgreColourValue.h> namespace OpenGate{ @@ -54,7 +56,46 @@ /*! For debugging purposes dump scene node tree to a string */ std::string dumpSceneNodes( Ogre::Node * n ); + + +/*! Specialization of readXMLAttribute.*/ +template < class Class, class Method > +bool readXMLColourElement( TiXmlElement * pElem, const std::string & name, Class * obj, Method method, bool mandatory ){ + std::vector < std::string > names( getSubstrings( name ) ); + + TiXmlElement * pElemChild = pElem->FirstChildElement( name ); + if ( pElemChild ){ + if ( pElemChild->Attribute( "r" ) && pElemChild->Attribute( "g" ) && + pElemChild->Attribute( "b" ) && pElemChild->Attribute( "a" ) ){ + Ogre::ColourValue col( to< float >( pElemChild->Attribute( "r" ) ), to< float >( pElemChild->Attribute( "g" ) ), + to< float >( pElemChild->Attribute( "b" ) ), to< float >( pElemChild->Attribute( "a" ) ) ); + (obj->*method)( col ); + return true; + } + } + if ( mandatory ){ + throw std::invalid_argument( "Missing mandatory xml node " + name + " for " ); + } + return false; +} +inline Ogre::Vector3 readXMLVec3Element( TiXmlElement * pElem, const std::string & name, bool mandatory = false ){ + + TiXmlElement * pElemChild = pElem->FirstChildElement( name ); + if ( pElemChild ){ + if ( pElemChild->Attribute( "x" ) && pElemChild->Attribute( "y" ) && pElemChild->Attribute( "z" ) ){ + Ogre::Vector3 vec( to< float >( pElemChild->Attribute( "x" ) ), to< float >( pElemChild->Attribute( "y" ) ), + to< float >( pElemChild->Attribute( "z" ) ) ); + return vec; + } + } + + if ( mandatory ){ + throw std::invalid_argument( "Missing mandatory xml node " + name ); + } + return Ogre::Vector3::ZERO; +} + } // namespace OpenGate #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |