From: <eg...@us...> - 2007-11-18 11:15:05
|
Revision: 842 http://opengate.svn.sourceforge.net/opengate/?rev=842&view=rev Author: egore Date: 2007-11-18 03:15:08 -0800 (Sun, 18 Nov 2007) Log Message: ----------- configure.ac: add some missing things gathered from running autoscan Modified Paths: -------------- trunk/ChangeLog trunk/configure.ac Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-17 19:07:16 UTC (rev 841) +++ trunk/ChangeLog 2007-11-18 11:15:08 UTC (rev 842) @@ -1,4 +1,7 @@ -2007-11-14 hristoph Brill <eg...@us...> +2007-11-18 Christoph Brill <ego...@eg...> + * configure.ac: add some missing things gathered from running autoscan + +2007-11-14 Christoph Brill <eg...@us...> * src/networkServerUser.h: fix build with boost 1.34 2007-09-26 Christoph Brill <eg...@us...> Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-11-17 19:07:16 UTC (rev 841) +++ trunk/configure.ac 2007-11-18 11:15:08 UTC (rev 842) @@ -15,7 +15,27 @@ AM_PROG_CC_STDC AC_HEADER_STDC AM_PROG_CC_C_O +AC_C_CONST +AC_C_INLINE +AC_C_VOLATILE +AC_FUNC_STAT +AC_FUNC_STRTOD +AC_HEADER_STDBOOL +AC_PROG_RANLIB +AC_STRUCT_TM +AC_TYPE_SIGNAL +AC_TYPE_SIZE_T +# Check for header files +AC_CHECK_HEADERS([float.h stddef.h sys/timeb.h]) + +# Checks for library functions. +AC_CHECK_FUNCS([floor ftime memmove memset pow rint socket sqrt strchr \ + strerror]) + +# Check for defines +AC_CHECK_TYPES([ptrdiff_t]) + # TODO: remove this part OGSECTOR_PATH=$PWD AC_PREFIX_DEFAULT($OGSECTOR_PATH) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eg...@us...> - 2007-11-18 13:57:13
|
Revision: 844 http://opengate.svn.sourceforge.net/opengate/?rev=844&view=rev Author: egore Date: 2007-11-18 05:57:18 -0800 (Sun, 18 Nov 2007) Log Message: ----------- remove externals Modified Paths: -------------- trunk/ChangeLog trunk/configure.ac Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-18 13:21:07 UTC (rev 843) +++ trunk/ChangeLog 2007-11-18 13:57:18 UTC (rev 844) @@ -1,5 +1,6 @@ 2007-11-18 Christoph Brill <ego...@eg...> - * configure.ac: add some missing things gathered from running autoscan + * configure.ac: add some missing things gathered from running + autoscan, drop externals stuff 2007-11-14 Christoph Brill <eg...@us...> * src/networkServerUser.h: fix build with boost 1.34 Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-11-18 13:21:07 UTC (rev 843) +++ trunk/configure.ac 2007-11-18 13:57:18 UTC (rev 844) @@ -36,20 +36,14 @@ # Check for defines AC_CHECK_TYPES([ptrdiff_t]) -# TODO: remove this part -OGSECTOR_PATH=$PWD -AC_PREFIX_DEFAULT($OGSECTOR_PATH) -OGSECTOR_EXTERNALS_PATH=$OGSECTOR_PATH/externals -AC_SUBST(OGSECTOR_EXTERNALS_PATH) -AC_SUBST(PKG_CONFIG_PATH, "$OGSECTOR_EXTERNALS_PATH/lib/pkgconfig:$PKG_CONFIG_PATH") -# TODO: end remove - -AM_PROG_LIBTOOL - PKG_CHECK_MODULES(OGRE, [OGRE >= 1.4.0]) AC_SUBST(OGRE_CFLAGS) AC_SUBST(OGRE_LIBS) +PKG_CHECK_MODULES(ogreopcode, [ogreopcode >= 0.1.0]) +AC_SUBST(ogreopcode_CFLAGS) +AC_SUBST(ogreopcode_LIBS) + PKG_CHECK_MODULES(CEGUI, [CEGUI >= 0.5.0]) AC_SUBST(CEGUI_CFLAGS) AC_SUBST(CEGUI_LIBS) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eg...@us...> - 2007-11-18 13:59:20
|
Revision: 846 http://opengate.svn.sourceforge.net/opengate/?rev=846&view=rev Author: egore Date: 2007-11-18 05:59:24 -0800 (Sun, 18 Nov 2007) Log Message: ----------- drop externals stuff Modified Paths: -------------- trunk/ChangeLog trunk/src/Makefile.am Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-18 13:58:08 UTC (rev 845) +++ trunk/ChangeLog 2007-11-18 13:59:24 UTC (rev 846) @@ -1,6 +1,7 @@ 2007-11-18 Christoph Brill <ego...@eg...> * configure.ac: add some missing things gathered from running autoscan, drop externals stuff + * src/Makefile.am: drop externals stuff 2007-11-14 Christoph Brill <eg...@us...> * src/networkServerUser.h: fix build with boost 1.34 Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2007-11-18 13:58:08 UTC (rev 845) +++ trunk/src/Makefile.am 2007-11-18 13:59:24 UTC (rev 846) @@ -79,13 +79,12 @@ $(freealut_LIBS) \ $(vorbisfile_LIBS) \ $(OIS_LIBS) \ - $(OgreOpcode_LIBS) -# -L$(OGSECTOR_EXTERNALS_PATH)/lib/ + $(ogreopcode_LIBS) opengateclient_CXXFLAGS = \ $(OGRE_CFLAGS) \ $(CEGUI_CFLAGS) \ - $(OgreOpcode_CFLAGS) + $(ogreopcode_CFLAGS) opengateserver_SOURCES = \ opengateserver.cpp \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eg...@us...> - 2007-11-18 14:00:25
|
Revision: 847 http://opengate.svn.sourceforge.net/opengate/?rev=847&view=rev Author: egore Date: 2007-11-18 06:00:29 -0800 (Sun, 18 Nov 2007) Log Message: ----------- 2007-11-18 Christoph Brill <ego...@eg...> * runServer.sh, runClient.sh: drop unnecessary run-wrappers Modified Paths: -------------- trunk/ChangeLog Removed Paths: ------------- trunk/runClient.sh trunk/runServer.sh Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-18 13:59:24 UTC (rev 846) +++ trunk/ChangeLog 2007-11-18 14:00:29 UTC (rev 847) @@ -2,6 +2,7 @@ * configure.ac: add some missing things gathered from running autoscan, drop externals stuff * src/Makefile.am: drop externals stuff + * runServer.sh, runClient.sh: drop unnecessary run-wrappers 2007-11-14 Christoph Brill <eg...@us...> * src/networkServerUser.h: fix build with boost 1.34 Deleted: trunk/runClient.sh =================================================================== --- trunk/runClient.sh 2007-11-18 13:59:24 UTC (rev 846) +++ trunk/runClient.sh 2007-11-18 14:00:29 UTC (rev 847) @@ -1,13 +0,0 @@ -#!/bin/bash - -USERNAME='player' - -HOSTNAME='localhost' - -[ $# -gt 0 ] && USERNAME=$1 - -[ $# -gt 1 ] && HOSTNAME=$2 - -export LD_LIBRARY_PATH=./externals/lib:$LD_LIBRARY_PATH - -./src/opengateclient --no-config $* Deleted: trunk/runServer.sh =================================================================== --- trunk/runServer.sh 2007-11-18 13:59:24 UTC (rev 846) +++ trunk/runServer.sh 2007-11-18 14:00:29 UTC (rev 847) @@ -1,4 +0,0 @@ -#!/bin/bash -export LD_LIBRARY_PATH=./externals/lib:$LD_LIBRARY_PATH - -./src/opengateserver This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ult...@us...> - 2007-11-18 16:21:16
|
Revision: 852 http://opengate.svn.sourceforge.net/opengate/?rev=852&view=rev Author: ultrasick Date: 2007-11-18 08:21:21 -0800 (Sun, 18 Nov 2007) Log Message: ----------- small changes on sectors Modified Paths: -------------- trunk/TODO.gluck trunk/data/misc/sectors.xml Modified: trunk/TODO.gluck =================================================================== --- trunk/TODO.gluck 2007-11-18 14:55:13 UTC (rev 851) +++ trunk/TODO.gluck 2007-11-18 16:21:21 UTC (rev 852) @@ -1,4 +1,3 @@ before first release: * metaserver f\xFCr die sektorverwaltung vorbereiten -* sektoren in opacma aufnehmen (asteroiden fehlen + random bilder fehlen) -* werbung f\xFCr dark raus \ No newline at end of file +* sektoren in opacma aufnehmen (asteroiden fehlen + random bilder fehlen) \ No newline at end of file Modified: trunk/data/misc/sectors.xml =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spo...@us...> - 2007-11-21 17:16:55
|
Revision: 854 http://opengate.svn.sourceforge.net/opengate/?rev=854&view=rev Author: spom_spom Date: 2007-11-21 09:16:39 -0800 (Wed, 21 Nov 2007) Log Message: ----------- hopefully fixed some network issues Modified Paths: -------------- trunk/configure.ac trunk/src/Entity.cpp trunk/src/Entity.h trunk/src/EntityManager.cpp trunk/src/EntityManager.h trunk/src/Makefile.am trunk/src/MarketDialog.cpp trunk/src/MarketDialog.h trunk/src/OpcodeWrapper.cpp trunk/src/Projectile.cpp trunk/src/Projectile.h trunk/src/Sector.cpp trunk/src/SectorObjects.cpp trunk/src/SectorObjects.h trunk/src/networkProtocol.cpp trunk/src/networkProtocol.h Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/configure.ac 2007-11-21 17:16:39 UTC (rev 854) @@ -36,6 +36,8 @@ # Check for defines AC_CHECK_TYPES([ptrdiff_t]) +AM_PROG_LIBTOOL + PKG_CHECK_MODULES(OGRE, [OGRE >= 1.4.0]) AC_SUBST(OGRE_CFLAGS) AC_SUBST(OGRE_LIBS) @@ -87,7 +89,6 @@ echo "You can get them from http://sourceforge.net/projects/asio/" exit 1 ],[]) -# TODO: end fix AC_OUTPUT([ Makefile Modified: trunk/src/Entity.cpp =================================================================== --- trunk/src/Entity.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/Entity.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -71,9 +71,7 @@ if ( imageFileName_ == "unknown" ) imageFileName_ = name_; if ( !initialiseImage( imageFileName_ + "_small.png", imageFileName_ + "Small" ) ){ - if ( !initialiseImage( imageFileName_ + "_76x76.png", imageFileName_ + "Small" ) ){ - haveSmall = false; - } + haveSmall = false; } if ( haveSmall ){ @@ -81,11 +79,8 @@ } if ( !initialiseImage( imageFileName_ + "_big.png", imageFileName_ ) ){ - //**fallback to 290x290 - if ( !initialiseImage( imageFileName_ + "_290x290.png", imageFileName_ ) ){ - //**fallback - initialiseImage( imageFileName_ + ".png", imageFileName_, true ); - } + //**fallback; + initialiseImage( imageFileName_ + ".png", imageFileName_, true ); } if ( !haveSmall ) { Modified: trunk/src/Entity.h =================================================================== --- trunk/src/Entity.h 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/Entity.h 2007-11-21 17:16:39 UTC (rev 854) @@ -139,7 +139,7 @@ std::set < Commodity * > requieredComponents_; /*! A unique ID to find this object \todo maybe push to a string and merge with Commodity.commodityID_ */ - int id_; + Uint16 id_; /*! The required tech level to interact with this object */ int techLevel_; /*! The mass of this entity. */ Modified: trunk/src/EntityManager.cpp =================================================================== --- trunk/src/EntityManager.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/EntityManager.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -29,7 +29,7 @@ namespace OpenGate { EntityManager::~EntityManager(){ - for ( std::map< int, Entity * >::iterator it = templatesByID_.begin(); it != templatesByID_.end(); it ++ ){ + for ( std::map< Uint16, Entity * >::iterator it = templatesByID_.begin(); it != templatesByID_.end(); it ++ ){ delete it->second; } templatesByID_.end(); @@ -348,7 +348,7 @@ pElem = hRoot.ChildElement( "fire_delay", 0 ).Element(); if ( pElem ) dynamic_cast< Gun * >( entity )->setFireDelay( toDouble( pElem->FirstChild()->Value() ) ); - pElem = hRoot.ChildElement( "energy_per_shot", 0 ).Element(); + pElem = hRoot.ChildElement( "power_per_shot", 0 ).Element(); if ( pElem ) dynamic_cast< Gun * >( entity )->setEnergy( toInt( pElem->FirstChild()->Value() ) ); pElem = hRoot.ChildElement( "damage", 0 ).Element(); Modified: trunk/src/EntityManager.h =================================================================== --- trunk/src/EntityManager.h 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/EntityManager.h 2007-11-21 17:16:39 UTC (rev 854) @@ -84,6 +84,16 @@ } } + Entity * entity( Uint16 ID ){ + if ( templatesByID_.count( ID ) ){ + return templatesByID_[ ID ]; + } else { + LogManager::getSingleton().warn( ("Request for entity id: ") + toStr(ID) + " unknown" ); + return NULL; + } + } + + protected: /*! \brief This loads enities from there definition files, called from load() @@ -103,7 +113,7 @@ std::map < std::string, Entity * > templatesByName_; - std::map < int, Entity * > templatesByID_; + std::map < Uint16, Entity * > templatesByID_; std::set < std::string > factions_; }; Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/Makefile.am 2007-11-21 17:16:39 UTC (rev 854) @@ -79,12 +79,12 @@ $(freealut_LIBS) \ $(vorbisfile_LIBS) \ $(OIS_LIBS) \ - $(ogreopcode_LIBS) + $(ogreopcode_LIBS) opengateclient_CXXFLAGS = \ $(OGRE_CFLAGS) \ $(CEGUI_CFLAGS) \ - $(ogreopcode_CFLAGS) + $(ogreopcode_CFLAGS) opengateserver_SOURCES = \ opengateserver.cpp \ Modified: trunk/src/MarketDialog.cpp =================================================================== --- trunk/src/MarketDialog.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/MarketDialog.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -112,6 +112,8 @@ CEGUI::PushButton::EventClicked, MarketDialog::handleMarketItemWindowUpButton ); BIND_CEGUI_EVENT( wmgr.getWindow( (CEGUI::utf8*)"MarketWindow/DownButton"), CEGUI::PushButton::EventClicked, MarketDialog::handleMarketItemWindowDownButton ); + BIND_CEGUI_EVENT( wmgr.getWindow( (CEGUI::utf8*)"MarketWindow"), + CEGUI::PushButton::EventMouseWheel, MarketDialog::handleMouseWheelChanged ); BIND_CEGUI_EVENT( wmgr.getWindow( (CEGUI::utf8*)"MarketItemDetailedView/NotNowButton"), CEGUI::PushButton::EventClicked, MarketDialog::handleMarketItemViewNotNowButton ); @@ -136,6 +138,7 @@ BIND_CEGUI_EVENT( wmgr.getWindow( (CEGUI::utf8*)"InventoryWindow/DownButton"), CEGUI::PushButton::EventClicked, MarketDialog::handleInventItemWindowDownButton ); + for ( unsigned int i = 0; i < marketItems_.size(); i ++ ){ BIND_CEGUI_EVENT( marketItems_[ i ], CEGUI::Window::EventMouseEnters, MarketDialog::handleMarketItemMouseEnters ); BIND_CEGUI_EVENT( marketItems_[ i ], CEGUI::Window::EventMouseLeaves, MarketDialog::handleMarketItemMouseLeaves ); @@ -703,5 +706,10 @@ return true; } +bool MarketDialog::handleMouseWheelChanged( const CEGUI::EventArgs & e ){ + std::cout << "handleMouseWheelChanged" << std::endl; + return true; +} + } // namespace OpenGate Modified: trunk/src/MarketDialog.h =================================================================== --- trunk/src/MarketDialog.h 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/MarketDialog.h 2007-11-21 17:16:39 UTC (rev 854) @@ -62,12 +62,12 @@ bool handeMainWindowShown( const CEGUI::EventArgs & e ); - bool handleMarketItemSortAlphaAscend( const CEGUI::EventArgs & e ){ sortBy_ = Alphanumeric; updateSortIcons(); return true; } - bool handleMarketItemSortAlphaDescend( const CEGUI::EventArgs & e ){ sortBy_ = Alphanumeric; updateSortIcons(); return true; } - bool handleMarketItemSortCost( const CEGUI::EventArgs & e ){ sortBy_ = Cost; updateSortIcons(); return true; } - bool handleMarketItemSortSizeAscend( const CEGUI::EventArgs & e ){ sortBy_ = Size; updateSortIcons(); return true; } - bool handleMarketItemSortSizeDescend( const CEGUI::EventArgs & e ){ sortBy_ = Size; updateSortIcons(); return true; } - bool handleMarketItemSortRank( const CEGUI::EventArgs & e ){ sortBy_ = Rank; updateSortIcons(); return true; } + bool handleMarketItemSortAlphaAscend( const CEGUI::EventArgs & e ){ sortBy_ = Alphanumeric; updateSortIcons(); return true; } + bool handleMarketItemSortAlphaDescend( const CEGUI::EventArgs & e ){ sortBy_ = Alphanumeric; updateSortIcons(); return true; } + bool handleMarketItemSortCost( const CEGUI::EventArgs & e ){ sortBy_ = Cost; updateSortIcons(); return true; } + bool handleMarketItemSortSizeAscend( const CEGUI::EventArgs & e ){ sortBy_ = Size; updateSortIcons(); return true; } + bool handleMarketItemSortSizeDescend( const CEGUI::EventArgs & e ){ sortBy_ = Size; updateSortIcons(); return true; } + bool handleMarketItemSortRank( const CEGUI::EventArgs & e ){ sortBy_ = Rank; updateSortIcons(); return true; } bool handleMarketItemSortAmountAscend( const CEGUI::EventArgs & e ){ sortBy_ = Amount; updateSortIcons(); return true; } bool handleMarketItemSortAmountDescend( const CEGUI::EventArgs & e ){ sortBy_ = Amount; updateSortIcons(); return true; } @@ -88,6 +88,8 @@ bool handleMarketItemViewAcceptButton( const CEGUI::EventArgs & e ); bool handleMarketItemChangeAmount( const CEGUI::EventArgs & e ); + bool handleMouseWheelChanged( const CEGUI::EventArgs & e ); + std::string selectedCategory_; std::vector < CEGUI::Window * > marketItems_; std::vector < CEGUI::Window * > inventItems_; Modified: trunk/src/OpcodeWrapper.cpp =================================================================== --- trunk/src/OpcodeWrapper.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/OpcodeWrapper.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -50,7 +50,6 @@ OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "DockPad", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); // OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_CONTACT ); // OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_QUICK ); - collideInSectorContext_ = OgreOpcode::CollisionManager::getSingletonPtr()->getDefaultContext(); } Modified: trunk/src/Projectile.cpp =================================================================== --- trunk/src/Projectile.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/Projectile.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -30,35 +30,57 @@ namespace OpenGate{ + Projectile::Projectile( BaseObject * parent, long shotCount, Gun & gun, const Ogre::Vector3 & pos, const Ogre::Vector3 & vel ) + : BaseObject( parent->name() + "_" + toStr( shotCount ), parent->sector() ), parent_( parent ), + shotCount_( shotCount ), gun_( &gun ), damage_( gun.damage() ), maxLifeTime_( gun.lifeTime() ), vel_( vel ){ + + selectable_ = false; + beam_ = NULL; + bullet_ = NULL; + shape_ = NULL; + trail_ = NULL; + + maxRange_ = gun.speed() * maxLifeTime_; + + fire( pos ); +} + Projectile::Projectile( BaseObject * parent, long shotCounter, const GunObject & gun, const Ogre::Vector3 & mountPoint ) - : BaseObject( parent->name() + "_" + toStr( shotCounter ), parent->sector() ), parent_( parent ), - shotCount_( shotCounter), damage_( gun.gun()->damage() ), maxLifeTime_( gun.gun()->lifeTime() ){ + : BaseObject( parent->name() + "_" + toStr( shotCounter ), parent->sector() ), parent_( parent ), + shotCount_( shotCounter), gun_( gun.gun() ), damage_( gun.gun()->damage() ), maxLifeTime_( gun.gun()->lifeTime() ){ selectable_ = false; - Ogre::String bulletName( name_ + "_" + toStr( shotCounter ) ); - beam_ = NULL; bullet_ = NULL; shape_ = NULL; trail_ = NULL; + maxRange_ = gun.gun()->speed() * maxLifeTime_; + Ogre::Quaternion direction( parent_->mainNode()->getOrientation() ); + vel_ = gun.gun()->speed() * -direction.zAxis().normalisedCopy() + parent->velocity(); + Ogre::Vector3 relGunPos( ( gun.sceneNode().getParentSceneNode()->getOrientation() * gun.sceneNode().getPosition() ) * - gun.sceneNode().getParentSceneNode()->getParentSceneNode()->getScale() ); - + gun.sceneNode().getParentSceneNode()->getParentSceneNode()->getScale() ); - maxRange_ = gun.gun()->speed() * maxLifeTime_; + Ogre::Vector3 pos( gun.sceneNode().getWorldPosition() - direction.zAxis() * relGunPos[ 2 ] ); + fire( pos, relGunPos ); +} + +void Projectile::fire( const Ogre::Vector3 & pos, const Ogre::Vector3 & relGunPos ){ + Ogre::String bulletName( name_ + "_" + toStr( shotCount_ ) ); + + Ogre::Quaternion direction( parent_->mainNode()->getOrientation() ); mainNode_->setOrientation( direction ); - mainNode_->setPosition( gun.sceneNode().getWorldPosition() - direction.zAxis() * relGunPos[ 2 ] ); + mainNode_->setPosition( pos ); mainNode_->_update( true, true ); lifeTime_ = 0.0; oldTime_ = 0.0; ammoHit_ = false; - vel_ = gun.gun()->speed() * -direction.zAxis().normalisedCopy() + parent->velocity(); - switch ( gun.gun()->type() ){ + switch ( gun_->type() ){ case BULLET:{ int maxBB = 20; bullet_ = sceneMgr_->createBillboardSet( bulletName + "_BBS", maxBB ); @@ -112,10 +134,10 @@ case MININGLASER: { } break; case UNKNOWN: { - LogManager::getSingleton().warn( "guntype unknown: " + toStr( gun.gun()->type() ) + " Forced bullet." ); - }break; + LogManager::getSingleton().warn( "guntype unknown: " + toStr( gun_->type() ) + " Forced bullet." ); + } break; - } + } //switch gun_->type } Projectile::~Projectile() { Modified: trunk/src/Projectile.h =================================================================== --- trunk/src/Projectile.h 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/Projectile.h 2007-11-21 17:16:39 UTC (rev 854) @@ -28,10 +28,14 @@ class Projectile : public BaseObject { public: + Projectile( BaseObject * parent, long shotCount, Gun & gun, const Ogre::Vector3 & pos, const Ogre::Vector3 & vel ); + Projectile( BaseObject * parent, long shotCount, const GunObject & gun, const Ogre::Vector3 & mountPoint ); virtual ~Projectile(); + void fire( const Ogre::Vector3 & pos, const Ogre::Vector3 & relGunPos = Ogre::Vector3::ZERO); + inline virtual long getTypeID() const { return PROJECTILE_RTTI; } virtual void collide( BaseObject * object ); @@ -50,11 +54,15 @@ Uint16 shotCount() const { return shotCount_; } + Gun * gun() const { return gun_; } + protected: BaseObject * parent_; Uint16 shotCount_; Uint32 damage_; + Gun * gun_; + // Ogre::BillboardChain * chain_; Ogre::BillboardSet * bullet_; Ogre::ManualObject * beam_; Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/Sector.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -27,6 +27,7 @@ #include "Station.h" #include <OgreManualObject.h> +#include <OgreMaterialManager.h> #include <OgreOverlayManager.h> #include <OgreOverlayContainer.h> #include <OgreSceneNode.h> @@ -92,7 +93,7 @@ // myManualObject->position(Ogre::Vector3(Ogre::Math::RangeRandom(-1,1), // Ogre::Math::RangeRandom(-1,1), // Ogre::Math::RangeRandom(-1,1)).normalisedCopy() * -// Ogre::Math::RangeRandom(10000,40000) ); +// Ogre::Math::RangeRandom(100000,400000) ); // } // myManualObject->end(); // myManualObjectNode->attachObject(myManualObject); @@ -216,7 +217,7 @@ pElem = hRoot.ChildElement( "skybox", 0 ).Element(); if ( pElem ){ - sceneMgr_->setSkyBox( true, pElem->FirstChild()->Value() ); + sceneMgr_->setSkyBox( true, pElem->FirstChild()->Value(), 10000 ); } else{ // sceneMgr_->setSkyBox( true, "OpenGate/SimpleSkyBox1" ); } @@ -555,7 +556,7 @@ } } - void Sector::destructMoveableObject( SectorObjectMoveable * obj ){ +void Sector::destructMoveableObject( SectorObjectMoveable * obj ){ selectNextTarget( obj ); sectorObjects_.erase( obj ); @@ -949,10 +950,8 @@ std::cout << "Send: Projectile from " << projectile.name() << " collide with: " << victim->name() << " " << victim->userID() << " " << victim->childID() << std::endl; - if ( network_->online() ){ - MessageBodyShipAmmoHit msg( projectile.parent().childID(), victim->userID(), victim->childID(), projectile.damage() ); - network_->send( msg ); - } + MessageBodyShipAmmoHit msg( projectile.parent().childID(), victim->userID(), victim->childID(), projectile.damage() ); + network_->send( msg ); victim->hitByAmmo( projectile.damage() ); } } @@ -981,12 +980,10 @@ } void Sector::sendProjectile( const Projectile & projectile ){ - if ( network_->online() ){ - MessageBodyShipProjectileFired msg( projectile.parent().childID(), projectile.shotCount(), - projectile.position().ptr(), projectile.velocity().ptr(), - projectile.damage(), projectile.lifeTime() ); - network_->send( msg ); - } + MessageBodyShipProjectileFired msg( projectile.parent().childID(), projectile.shotCount(), + projectile.position().ptr(), projectile.velocity().ptr(), + projectile.gun()->id(), projectile.damage(), projectile.lifeTime() ); + network_->send( msg ); } void Sector::receiveProjectile( const MessageBodyShipProjectileFired & msg ){ @@ -994,8 +991,15 @@ std::map< long, SectorObjectMoveable * >::iterator it; if ( ( it = movableObjects_.find( createGlobalID( msg.senderID(), msg.childID() ) ) ) != movableObjects_.end() ){ -// Projectile * pro = new Projectile( it->second, msg.shotCount(), msg.velocity().length(), msg.damage(), msg.liveTime() ); -// it->second->addProjectile( pro ); + Gun * gun = dynamic_cast < Gun * >(EquipmentManager::getSingleton().entity( msg.gunID() ) ); + if ( gun->entityType() == GUN ){ + Projectile * pro = new Projectile( it->second, msg.shotCount(), *gun, + toOgreVec( msg.position() ), + toOgreVec( msg.velocity() ) ); + it->second->addProjectile( pro ); + } else { + log_->warn( "Unknown projectile type: " + toStr( msg.gunID() ) ); + } } else { log_->warn( "Unknown shooter" ); } Modified: trunk/src/SectorObjects.cpp =================================================================== --- trunk/src/SectorObjects.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/SectorObjects.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -236,6 +236,7 @@ } explosion_ = NULL; + armor_ = vessel_->armor(); setThrust( 0 ); updateThruster(); } @@ -470,15 +471,14 @@ void SectorObjectMoveable::inititializeVesselStats_(){ - armor_ = maxArmor(); yaw_ = 0; roll_ = 0; pitch_ = 0; mass_ = 1; + armor_ = 1; thrust_ = 0; - maxThrust_ = 0; - armor_ = 1; + maxThrust_ = 0; shield_ = 0; maxShield_ = 0; @@ -854,7 +854,7 @@ bool SectorObjectAvatar::update( Ogre::Real elapsedTime ){ updatePowerGrid( elapsedTime ); - thrustRate_ += (thrustChange_ *0.5f*elapsedTime); + thrustRate_ += (thrustChange_ * 0.5f * elapsedTime); thrustRate_ = max( thrustRate_, 0.0f ); thrustRate_ = min( 1.0f, thrustRate_ ); if ( thrustChange_ != 0.0 ) updateThruster(); Modified: trunk/src/SectorObjects.h =================================================================== --- trunk/src/SectorObjects.h 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/SectorObjects.h 2007-11-21 17:16:39 UTC (rev 854) @@ -70,12 +70,12 @@ inline Ogre::SceneNode & sceneNode() const { return *mountPoint_; } protected: - Gun * gun_; - SectorObject * parent_; - Ogre::SceneNode * mountPoint_; - Uint32 * capacity_; - Ogre::Real delayTime_; - Ogre::Vector3 mountPosition_; + Gun * gun_; + SectorObject * parent_; + Ogre::SceneNode * mountPoint_; + Uint32 * capacity_; + Ogre::Real delayTime_; + Ogre::Vector3 mountPosition_; OpenALSoundSource * gunSound_; }; @@ -276,7 +276,6 @@ /*! Returns the current relative armor. */ inline Ogre::Real armorRate() const { if ( maxArmor() > 0 ) return (float)armor_ / maxArmor(); else return 0.0; } - /*! Set the current shield. */ inline void setShield( Uint32 shield ) { shield_ = shield; } Modified: trunk/src/networkProtocol.cpp =================================================================== --- trunk/src/networkProtocol.cpp 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/networkProtocol.cpp 2007-11-21 17:16:39 UTC (rev 854) @@ -119,8 +119,8 @@ MessageBodyShipProjectileFired::MessageBodyShipProjectileFired( Uint8 childID, Uint16 shotCount, const Float * pos, - const Float * vel, Uint32 damage, Float liveTime ) - : MessageBodyShipBase( childID ), shotCount_( shotCount ), damage_( damage ), liveTime_( liveTime ) { + const Float * vel, Uint16 gunID, Uint32 damage, Float liveTime ) + : MessageBodyShipBase( childID ), shotCount_( shotCount ), gunID_( gunID ), damage_( damage ), liveTime_( liveTime ) { type_ = (Uint8)PROTO_SHIP_PROJECTILEFIRED; pos_.v[ 0 ] = pos[ 0 ]; pos_.v[ 1 ] = pos[ 1 ]; pos_.v[ 2 ] = pos[ 2 ]; vel_.v[ 0 ] = vel[ 0 ]; vel_.v[ 1 ] = vel[ 1 ]; vel_.v[ 2 ] = vel[ 2 ]; @@ -133,6 +133,7 @@ readFromData( shotCount_, data, count ); readFromData( pos_, data, count ); readFromData( vel_, data, count ); + readFromData( gunID_, data, count ); readFromData( damage_, data, count ); readFromData( liveTime_, data, count ); } @@ -142,6 +143,7 @@ writeToOut( out_, shotCount_ ); writeToOut( out_, pos_ ); writeToOut( out_, vel_ ); + writeToOut( out_, gunID_ ); writeToOut( out_, damage_ ); writeToOut( out_, liveTime_ ); } Modified: trunk/src/networkProtocol.h =================================================================== --- trunk/src/networkProtocol.h 2007-11-18 19:03:10 UTC (rev 853) +++ trunk/src/networkProtocol.h 2007-11-21 17:16:39 UTC (rev 854) @@ -507,7 +507,7 @@ class MessageBodyShipProjectileFired : public MessageBodyShipBase { public: MessageBodyShipProjectileFired( Uint8 childID, Uint16 shotCount, const Float * pos, const Float * vel, - Uint32 damage, Float liveTime ); + Uint16 gunID, Uint32 damage, Float liveTime ); MessageBodyShipProjectileFired( const char * data ); @@ -515,17 +515,19 @@ void createOutStream(); - Uint16 shotCount() const { return shotCount_ ; } + Uint16 shotCount() const { return shotCount_ ; } FVector3 position() const; FVector3 velocity() const; - Uint32 damage() const { return damage_; } - Float liveTime() const { return liveTime_; } + Uint16 gunID() const { return gunID_; } + Uint32 damage() const { return damage_; } + Float liveTime() const { return liveTime_; } protected: - Uint16 shotCount_; + Uint16 shotCount_; FVector3 pos_; FVector3 vel_; - Uint32 damage_; + Uint16 gunID_; + Uint32 damage_; Float liveTime_; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spo...@us...> - 2007-11-21 22:56:30
|
Revision: 856 http://opengate.svn.sourceforge.net/opengate/?rev=856&view=rev Author: spom_spom Date: 2007-11-21 14:56:35 -0800 (Wed, 21 Nov 2007) Log Message: ----------- try to fix strange network problem Modified Paths: -------------- trunk/src/Sector.cpp trunk/src/metaserver.cpp trunk/src/networkProtocol.h trunk/src/opengateserver.cpp Removed Paths: ------------- trunk/win32/ogsectorclient/OgreOpcode.dll trunk/win32/ogsectorclient/Opcode.dll Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2007-11-21 19:52:10 UTC (rev 855) +++ trunk/src/Sector.cpp 2007-11-21 22:56:35 UTC (rev 856) @@ -912,7 +912,8 @@ it->second->setFlightProperties( (*i->second) ); } else { std::cerr << "Requested non existant object for shipmovement: " - << network_->userName( i->second->senderID() ) << " at: " + << network_->userName( i->second->senderID() ) + << " child: " << (int)i->second->childID() << " at: " << i->second->position() << " this should not happen." << std::endl; } } Modified: trunk/src/metaserver.cpp =================================================================== --- trunk/src/metaserver.cpp 2007-11-21 19:52:10 UTC (rev 855) +++ trunk/src/metaserver.cpp 2007-11-21 22:56:35 UTC (rev 856) @@ -413,12 +413,7 @@ asio::write( socket_, request ); // Read the response status line. -#ifdef WIN32 - // we dont have boost:regex within win32, i will fix this later (carsten) - //asio::read_until(socket_, response, "\n"); -#else asio::read_until( socket_, response, boost::regex("\r\n") ); -#endif // Check that response is OK. std::istream response_stream( &response ); @@ -429,21 +424,15 @@ std::string status_message; std::getline(response_stream, status_message); if ( !response_stream || http_version.substr(0, 5) != "HTTP/" ) { - std::cout << "Invalid response\n"; + log_->fatal( "Metaserver: invalid response" ); return -51; } if ( status_code != 200 ) { - std::cout << "Response returned with status code " << status_code << "\n"; + log_->fatal( "Metaserver: response returned with status code " + toStr( status_code ) ); return -52; } - // Read the response headers, which are terminated by a blank line. -#ifdef WIN32 - // we dont have boost:regex within win32, i will fix this later (carsten) - //asio::read_until(socket_, response, "\n"); -#else asio::read_until( socket_, response, boost::regex( "\r\n\r\n" ) ); -#endif // Process the response headers. (to get the crap of the response before reading the body!) std::string header; Modified: trunk/src/networkProtocol.h =================================================================== --- trunk/src/networkProtocol.h 2007-11-21 19:52:10 UTC (rev 855) +++ trunk/src/networkProtocol.h 2007-11-21 22:56:35 UTC (rev 856) @@ -114,27 +114,27 @@ /*! Destructor */ virtual ~MessageBodyBase(){ } - virtual char * data() { + inline virtual char * data() { out_.str( "" ); createOutStream(); outData_ = out_.str(); return (char*)&outData_[ 0 ]; } - virtual void createOutStream() { + inline virtual void createOutStream() { writeToOut( out_, type_ ); writeToOut( out_, senderID_ ); } - int length() const { return outData_.length(); } + inline int length() const { return outData_.length(); } - Uint8 type() const { return (int)type_; } + inline Uint8 type() const { return type_; } - Uint32 senderID( ) const { return senderID_; } + inline Uint32 senderID( ) const { return senderID_; } - void setSenderID( Uint32 senderID ) { senderID_ = senderID; } + inline void setSenderID( Uint32 senderID ) { senderID_ = senderID; } - virtual int dataSize() const { return sizeof( Uint8 ) + sizeof( Uint32 ); } + inline virtual int dataSize() const { return sizeof( Uint8 ) + sizeof( Uint32 ); } friend std::ostream & operator << ( std::ostream & str, const MessageBodyBase & msg ){ str << "Type: " << (int)( msg.type() ) << " senderID: " << msg.senderID() ; @@ -171,9 +171,9 @@ writeToOut( out_, userID_ ); } - virtual int dataSize() const { return MessageBodyBase::dataSize() + sizeof( Uint32 ); } + inline virtual int dataSize() const { return MessageBodyBase::dataSize() + sizeof( Uint32 ); } - Uint32 userID( ) const { return userID_; } + inline Uint32 userID( ) const { return userID_; } protected: Uint32 userID_; @@ -223,7 +223,7 @@ out_.write( ( char* )( username_.c_str() ), sizeof( char ) * nameLength_ ); } - std::string userName( ) const { return username_; } + inline std::string userName( ) const { return username_; } protected: Uint8 nameLength_; @@ -252,7 +252,7 @@ writeToOut( out_, reason_ ); } - Uint8 reason( ) const { return reason_; } + inline Uint8 reason( ) const { return reason_; } protected: Uint8 reason_; @@ -287,9 +287,9 @@ out_.write( ( char* )( message_.c_str() ), sizeof( char ) * messageLength_ ); } - void setMessage( const std::string & message ){ message_ = message; } + inline void setMessage( const std::string & message ){ message_ = message; } - std::string message( ) const { return message_; } + inline std::string message( ) const { return message_; } protected: mutable Uint16 messageLength_; @@ -314,14 +314,14 @@ virtual ~MessageBodyShipBase( ){ } - void createOutStream() { + inline void createOutStream() { MessageBodyBase::createOutStream(); writeToOut( out_, childID_ ); } - Uint8 childID( ) const { return (int)childID_; } + inline Uint8 childID( ) const { return childID_; } - virtual int dataSize() const { return MessageBodyBase::dataSize() + sizeof( Uint8 ); } + inline virtual int dataSize() const { return MessageBodyBase::dataSize() + sizeof( Uint8 ); } protected: Uint8 childID_; @@ -341,14 +341,10 @@ inline std::string name() const { return name_; } - FVector3 position() const; - - inline Uint16 vesselID() const { return vesselID_; } - - inline Uint32 mass() const { return mass_; } - + FVector3 position() const; + inline Uint16 vesselID() const { return vesselID_; } + inline Uint32 mass() const { return mass_; } inline Uint32 maxShield() const { return maxShield_; } - inline Uint32 maxThrust() const { return maxThrust_; } protected: @@ -375,9 +371,7 @@ virtual ~MessageBodyShipDeRegister( ){ } - void createOutStream() { - MessageBodyShipBase::createOutStream(); - } + inline void createOutStream() { MessageBodyShipBase::createOutStream(); } friend std::ostream & operator << ( std::ostream & str, const MessageBodyShipDeRegister & msg ){ str << "Type: " << (int)( msg.type() ) << " senderID: " << msg.senderID() << " childID: " << msg.childID(); @@ -398,9 +392,7 @@ virtual ~MessageBodyShipDied( ){ } - void createOutStream() { - MessageBodyShipBase::createOutStream(); - } + inline void createOutStream() { MessageBodyShipBase::createOutStream(); } friend std::ostream & operator << ( std::ostream & str, const MessageBodyShipDied & msg ){ str << "Type: " << (int)( msg.type() ) << " senderID: " << msg.senderID() << " childID: " << msg.childID(); @@ -421,20 +413,13 @@ void createOutStream(); - FVector3 velocity() const; - - FVector3 position() const; - - FVector4 orientation() const; - - inline Uint32 thrust() const { return thrust_; } - - inline float yaw() const { return yaw_; } - - inline float pitch() const { return pitch_; } - - inline float roll() const { return roll_; } - + FVector3 velocity() const; + FVector3 position() const; + FVector4 orientation() const; + inline Uint32 thrust() const { return thrust_; } + inline float yaw() const { return yaw_; } + inline float pitch() const { return pitch_; } + inline float roll() const { return roll_; } inline Uint16 sequenceNr( ) const { return seqNr_; } friend std::ostream & operator << ( std::ostream & str, const MessageBodyShipMovement & msg ); @@ -484,16 +469,12 @@ tmp = ( Uint8 )break_; writeToOut( out_, tmp ); } - Uint32 shield( ) const { return shield_; } + inline Uint32 shield( ) const { return shield_; } + inline Uint32 armor( ) const { return armor_; } + inline bool firePressed( ) const { return fire_; } + inline bool afterburnerPressed( ) const { return afterburner_; } + inline bool breakPressed( ) const { return break_; } - Uint32 armor( ) const { return armor_; } - - bool firePressed( ) const { return fire_; } - - bool afterburnerPressed( ) const { return afterburner_; } - - bool breakPressed( ) const { return break_; } - protected: Uint32 shield_; Uint32 armor_; @@ -515,12 +496,12 @@ void createOutStream(); - Uint16 shotCount() const { return shotCount_ ; } - FVector3 position() const; - FVector3 velocity() const; - Uint16 gunID() const { return gunID_; } - Uint32 damage() const { return damage_; } - Float liveTime() const { return liveTime_; } + inline Uint16 shotCount() const { return shotCount_ ; } + FVector3 position() const; + FVector3 velocity() const; + inline Uint16 gunID() const { return gunID_; } + inline Uint32 damage() const { return damage_; } + inline Float liveTime() const { return liveTime_; } protected: Uint16 shotCount_; @@ -555,12 +536,10 @@ writeToOut( out_, damage_ ); } - Uint32 targetID() const { return targetID_; } + inline Uint32 targetID() const { return targetID_; } + inline Uint8 targetChildID() const { return targetChildID_; } + inline Uint32 damage() const { return damage_; } - Uint8 targetChildID() const { return targetChildID_; } - - Uint32 damage() const { return damage_; } - protected: Uint32 targetID_; @@ -601,14 +580,11 @@ return true; } - Uint16 length() const { return HeaderLength + bodyLength_; } + inline Uint16 length() const { return HeaderLength + bodyLength_; } + inline const char * body() const { return data_ + HeaderLength; } + inline char * body() { return data_ + HeaderLength; } + inline Uint16 bodyLength() const { return bodyLength_; } - const char * body() const { return data_ + HeaderLength; } - - char * body() { return data_ + HeaderLength; } - - Uint16 bodyLength() const { return bodyLength_; } - protected: char data_[ HeaderLength + MaxBodyLength ]; Uint16 bodyLength_; Modified: trunk/src/opengateserver.cpp =================================================================== --- trunk/src/opengateserver.cpp 2007-11-21 19:52:10 UTC (rev 855) +++ trunk/src/opengateserver.cpp 2007-11-21 22:56:35 UTC (rev 856) @@ -83,7 +83,7 @@ //** ein bissle mehr verbose output, kommt sp\xE4ter wieder weg.; //** das k\xF6nnte mal vielleicht als option rausreichen, das man wie beim clienten die Wahl hat; //** -M = (withMetaServer = true); - bool withMetaServer = false; + bool withMetaServer = true; std::string servername( "testserver Sim 1" ); try { asio::io_service io_service; Deleted: trunk/win32/ogsectorclient/OgreOpcode.dll =================================================================== (Binary files differ) Deleted: trunk/win32/ogsectorclient/Opcode.dll =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spo...@us...> - 2007-12-02 17:25:28
|
Revision: 873 http://opengate.svn.sourceforge.net/opengate/?rev=873&view=rev Author: spom_spom Date: 2007-12-02 09:25:31 -0800 (Sun, 02 Dec 2007) Log Message: ----------- upgrade to asio-0.3.8, fixed miscellaneous minor and major bugs Modified Paths: -------------- trunk/configure.ac trunk/data/materials/advancedMaterials.material trunk/data/materials/advancedMaterials.program trunk/plugins.cfg trunk/src/DockedState.cpp trunk/src/GameStateManager.cpp trunk/src/OpcodeWrapper.cpp trunk/src/OpcodeWrapper.h trunk/src/OpenALSoundManager.cpp trunk/src/OpenALSoundManager.h trunk/src/Projectile.cpp trunk/src/Projectile.h trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObjects.cpp trunk/src/SectorObjects.h trunk/src/Station.h trunk/src/common.cpp trunk/src/common.h trunk/src/metaserver.cpp trunk/src/metaserver.h trunk/src/networkClient.cpp trunk/src/networkClient.h trunk/src/networkProtocol.cpp trunk/src/networkProtocol.h trunk/src/networkServer.cpp trunk/src/networkServer.h trunk/src/networkServerUser.cpp trunk/src/networkServerUser.h trunk/src/opengateserver.cpp Added Paths: ----------- trunk/data/materials/simpleshield.cg trunk/data/materials/simpleshield.material Removed Paths: ------------- trunk/ogre.cfg trunk/win32/ogsectorclient/ogre.cfg Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/configure.ac 2007-12-02 17:25:31 UTC (rev 873) @@ -85,7 +85,7 @@ # TODO: fix this part AC_CHECK_HEADER([asio.hpp],, [ - echo "Can't find asio headers. Please install the asio development packages." + echo "Can't find asio headers-0.3.8. Please install the asio development packages." echo "You can get them from http://sourceforge.net/projects/asio/" exit 1 ],[]) Modified: trunk/data/materials/advancedMaterials.material =================================================================== --- trunk/data/materials/advancedMaterials.material 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/data/materials/advancedMaterials.material 2007-12-02 17:25:31 UTC (rev 873) @@ -21,7 +21,6 @@ // be an issue vertex_program_ref BasicVertexPrograms/AmbientOneTextureUnified { - param_named_auto worldViewProj worldviewproj_matrix param_named_auto ambient ambient_light_colour } @@ -43,7 +42,6 @@ vertex_program_ref BumpMapVP { param_named_auto lightPosition light_position_object_space 0 - param_named_auto worldViewProj worldviewproj_matrix } // Fragment program @@ -79,7 +77,6 @@ // be an issue vertex_program_ref BasicVertexPrograms/AmbientOneTextureUnified { - param_named_auto worldViewProj worldviewproj_matrix param_named ambient float4 1 1 1 1 } scene_blend dest_colour zero @@ -110,7 +107,6 @@ // be an issue vertex_program_ref BasicVertexPrograms/AmbientOneTextureUnified { - param_named_auto worldViewProj worldviewproj_matrix param_named_auto ambient ambient_light_colour } @@ -132,7 +128,6 @@ vertex_program_ref BumpMapVP { param_named_auto lightPosition light_position_object_space 0 - param_named_auto worldViewProj worldviewproj_matrix } // Base bump map @@ -162,7 +157,6 @@ // be an issue vertex_program_ref BasicVertexPrograms/AmbientOneTextureUnified { - param_named_auto worldViewProj worldviewproj_matrix param_named ambient float4 1 1 1 1 } scene_blend dest_colour zero Modified: trunk/data/materials/advancedMaterials.program =================================================================== --- trunk/data/materials/advancedMaterials.program 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/data/materials/advancedMaterials.program 2007-12-02 17:25:31 UTC (rev 873) @@ -2,46 +2,37 @@ { source Example_BumpMapping.cg entry_point main_vp - profiles vs_1_1 arbvp1 + profiles arbvp1 vp20 vs_1_1 + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } } -// Bump map fragment program, support for this is optional -fragment_program BumpMapFP cg -{ - source Example_BumpMapping.cg - entry_point main_fp - profiles vs_1_1 arbfp1 fp20 -} - // Bump map with specular vertex program, support for this is required vertex_program BumpMapVPSpecular cg { source Example_BumpMapping.cg entry_point specular_vp - profiles vs_1_1 arbvp1 + profiles arbvp1 vp20 vs_1_1 + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + } } -// Bump map fragment program, support for this is optional -fragment_program BumpMapFPSpecular cg -{ - source Example_BumpMapping.cg - entry_point specular_fp - profiles vs_1_1 arbfp1 fp20 -} - // A really basic ambient pass program, support for one texture coodinate set vertex_program BasicVertexPrograms/AmbientOneTextureCG cg { source Example_Basic.cg entry_point ambientOneTexture_vp - profiles vs_1_1 arbvp1 + profiles arbvp1 vp20 vs_1_1 default_params { param_named_auto worldViewProj worldviewproj_matrix param_named_auto ambient ambient_light_colour } - } // A really basic ambient pass program, support for one texture coodinate set @@ -49,7 +40,7 @@ { source Example_Basic.hlsl entry_point ambientOneTexture_vp - target vs_1_1 arbvp1 + target arbvp1 vp20 vs_1_1 default_params { @@ -73,4 +64,20 @@ delegate BasicVertexPrograms/AmbientOneTextureGLSL delegate BasicVertexPrograms/AmbientOneTextureHLSL delegate BasicVertexPrograms/AmbientOneTextureCG +} + +// Bump map fragment program, support for this is optional +fragment_program BumpMapFP cg +{ + source Example_BumpMapping.cg + entry_point main_fp + profiles arbfp1 fp20 ps_1_1 +} + +// Bump map fragment program, support for this is optional +fragment_program BumpMapFPSpecular cg +{ + source Example_BumpMapping.cg + entry_point specular_fp + profiles arbfp1 fp20 ps_1_1 } \ No newline at end of file Added: trunk/data/materials/simpleshield.cg =================================================================== --- trunk/data/materials/simpleshield.cg (rev 0) +++ trunk/data/materials/simpleshield.cg 2007-12-02 17:25:31 UTC (rev 873) @@ -0,0 +1,9 @@ +float4 main_fp( uniform float4 customParamColour, + uniform float time + ) : COLOR +{ + float4 outColor; + outColor = customParamColour; +// outColor.w = customParamColour.w * ( 1 - time ); + return outColor; +} Added: trunk/data/materials/simpleshield.material =================================================================== --- trunk/data/materials/simpleshield.material (rev 0) +++ trunk/data/materials/simpleshield.material 2007-12-02 17:25:31 UTC (rev 873) @@ -0,0 +1,24 @@ +fragment_program shader_fp/simpleshield_cg cg +{ + source simpleshield.cg + entry_point main_fp + profiles arbfp1 ps_1_1 +} + +material simpleshield +{ + technique + { + pass + { + scene_blend alpha_blend + depth_check off + lighting off + fragment_program_ref shader_fp/simpleshield_cg + { + param_named_auto customParamColour custom 0 + param_named_auto time time_0_x 1 + } + } + } +} Deleted: trunk/ogre.cfg =================================================================== --- trunk/ogre.cfg 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/ogre.cfg 2007-12-02 17:25:31 UTC (rev 873) @@ -1,7 +0,0 @@ -Render System=OpenGL Rendering Subsystem - -[OpenGL Rendering Subsystem] -FSAA=6 -Full Screen=No -RTT Preferred Mode=FBO -Video Mode=1024 x 768 Modified: trunk/plugins.cfg =================================================================== --- trunk/plugins.cfg 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/plugins.cfg 2007-12-02 17:25:31 UTC (rev 873) @@ -6,7 +6,5 @@ # Define D3D rendering implementation plugin Plugin=RenderSystem_GL.so Plugin=Plugin_ParticleFX.so -Plugin=Plugin_BSPSceneManager.so -Plugin=Plugin_OctreeSceneManager.so Plugin=Plugin_CgProgramManager.so Modified: trunk/src/DockedState.cpp =================================================================== --- trunk/src/DockedState.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/DockedState.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -129,12 +129,16 @@ exitToUndockedState_ = false; quitAllStates_ = false; + std::cout << "soundManager->listener "<< std::endl; if ( resources_->soundManager->listener() ){ resources_->soundManager->listener()->reset(); } - if ( backgroundSound_ ) backgroundSound_->play(); + std::cout << "backgroundSound_ "<< backgroundSound_ << std::endl; + + backgroundSound_->play(); + std::cout << "backgroundSound_ "<< std::endl; } void DockedState::exit(){ - if ( backgroundSound_ ) backgroundSound_->stop(); + backgroundSound_->stop(); CEGUI::WindowManager::getSingleton().getWindow( (CEGUI::utf8*)"Config/BackButton" )->removeEvent( CEGUI::PushButton::EventClicked ); Modified: trunk/src/GameStateManager.cpp =================================================================== --- trunk/src/GameStateManager.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/GameStateManager.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -20,6 +20,7 @@ #include "GameStateManager.h" +#include <OgreGpuProgramManager.h> #include <OgreRoot.h> #include <OgreRenderWindow.h> #include <OgreConfigFile.h> @@ -335,7 +336,21 @@ resources_.ogreRoot->removeFrameListener( state ); } +bool GameStateManager::initialiseBootstrap( bool dialog ){ + resources_.ogreRoot = new Ogre::Root; + resources_.gameStateRoot = this; + + if ( !initialiseOgreEngine_( dialog ) ) { + log_->fatal( "Cannot initialize ogre engine." ); + return false; + } + initialiseBootstrapResources(); + initLoadingVector(); + return true; +} + bool GameStateManager::initialiseBootstrapResources( ) { + log_->info( "load bootstrap resources." ); Ogre::ConfigFile cf; cf.load( "resources.cfg" ); // Go through all sections & settings in the file @@ -362,16 +377,6 @@ return true; } -bool GameStateManager::initialiseBootstrap( bool dialog ){ - resources_.ogreRoot = new Ogre::Root; - resources_.gameStateRoot = this; - - if ( !initialiseOgreEngine_( dialog ) ) return false; - initialiseBootstrapResources(); - initLoadingVector(); - return true; -} - void GameStateManager::initLoadingVector(){ loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), @@ -426,6 +431,13 @@ } bool GameStateManager::checkRenderSystemCapabilities( ){ + + log_->info("checkRenderSystemCapabilities: Your card support the following shader syntax: "); + std::set< Ogre::String> syntaxCodes = Ogre::GpuProgramManager::getSingleton().getSupportedSyntax(); + for ( std::set< Ogre::String>::iterator it = syntaxCodes.begin(); it != syntaxCodes.end(); it ++ ){ + log_->info( *it ); + } + const Ogre::RenderSystemCapabilities * caps = ResourceManager::getSingleton().ogreRoot->getRenderSystem()->getCapabilities(); if ( !caps->hasCapability( Ogre::RSC_VERTEX_PROGRAM ) ) { @@ -514,6 +526,10 @@ } bool GameStateManager::initialiseOgreEngine_( bool dialog ){ + if ( !fileExist( "ogre.cfg" ) ) { + dialog = true; + } + if ( !dialog ){ resources_.ogreRoot->restoreConfig(); resources_.renderWindow = resources_.ogreRoot->initialise( true, "OpenGate" ); @@ -522,8 +538,6 @@ if ( resources_.ogreRoot->showConfigDialog() ) { resources_.renderWindow = resources_.ogreRoot->initialise( true, "OpenGate" ); return true; - } else { - return false; } } return false; Modified: trunk/src/OpcodeWrapper.cpp =================================================================== --- trunk/src/OpcodeWrapper.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/OpcodeWrapper.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -58,7 +58,6 @@ } bool OpcodeCollisionDetection::update( Ogre::Real elapsedTime ){ - collideInSectorContext_->collide( 0.0 ); collideInSectorContext_->collide( elapsedTime ); OgreOpcode::CollisionReporter report( collideInSectorContext_->getCollisionReport() ); @@ -105,52 +104,49 @@ } OgreOpcode::CollisionObject * OpcodeCollisionDetection::createObject( SectorObject * obj ){ + return createObject( obj->entity(), obj, "SectorObject" ); +} - OgreOpcode::EntityCollisionShape * collShape = OgreOpcode::CollisionManager::getSingletonPtr() - ->createEntityCollisionShape( obj->name() + "/CollShape" ); - collShape->load( obj->entity() ); +void OpcodeCollisionDetection::destroyObject( OgreOpcode::CollisionObject * obj ){ - OgreOpcode::CollisionObject * collObj = collideInSectorContext_->createObject( obj->name() + "/CollObj" ); - collObj->setCollClass( OgreOpcode::CollisionManager::getSingletonPtr()->queryCollClass( "SectorObject" ) ); - collObj->setShape( collShape ); + OgreOpcode::ICollisionShape *shape = obj->getShape(); + OgreOpcode::CollisionManager::getSingletonPtr()->detachShape(shape); + OgreOpcode::CollisionManager::getSingletonPtr()->destroyShape(shape); - collideInSectorContext_->addObject( collObj ); - collObj->setClientData( obj ); - return collObj; -} -void OpcodeCollisionDetection::destroyObject( OgreOpcode::CollisionObject * obj ){ collideInSectorContext_->destroyObject( obj ); - OgreOpcode::CollisionManager::getSingletonPtr()->destroyShape( obj->getShape() ); + // OgreOpcode::CollisionManager::getSingletonPtr()->destroyShape( obj->getShape() ); } bool OpcodeCollisionDetection::checkCollideRay( BaseObject * obj, const Ogre::Ray & ray, double rayLength){ - OgreOpcode::CollisionPair ** rayPickReport; - uint nColl = collideInSectorContext_->rayCheck( ray, rayLength, OgreOpcode::COLLTYPE_EXACT, - OgreOpcode::COLLTYPE_ALWAYS_EXACT, rayPickReport ); - -// std::cout << "checkCollideRay: " << " " << rayLength << " " << nColl <<std::endl; - - for ( uint i = 0; i < nColl; i ++ ){ - OgreOpcode::CollisionObject* col1 = rayPickReport[ i ]->this_object; - OgreOpcode::CollisionObject* col2 = rayPickReport[ i ]->other_object; + if ( !obj->isSetDestroyRequest() ){ + OgreOpcode::CollisionPair ** rayPickReport; + uint nColl = collideInSectorContext_->rayCheck( ray, rayLength, OgreOpcode::COLLTYPE_EXACT, + OgreOpcode::COLLTYPE_ALWAYS_EXACT, rayPickReport ); -// std::cout << "checkCollideRay: " << i << " " -// << static_cast< BaseObject * >( col1->getClientData() )->name() << "<->" -// << static_cast< BaseObject * >( col2->getClientData() )->name() << std::endl; - - if ( obj->getTypeID() == PROJECTILE_RTTI ){ - if ( dynamic_cast< Projectile * >( obj )->parent() != static_cast< BaseObject * >( col1->getClientData() ) ){ - obj->mainNode()->setPosition( rayPickReport[ i ]->contact ); + // std::cout << "checkCollideRay: " << " " << rayLength << " " << nColl <<std::endl; + + for ( uint i = 0; i < nColl; i ++ ){ + OgreOpcode::CollisionObject* col1 = rayPickReport[ i ]->this_object; + OgreOpcode::CollisionObject* col2 = rayPickReport[ i ]->other_object; + + // std::cout << "checkCollideRay: " << i << " " + // << static_cast< BaseObject * >( col1->getClientData() )->name() << "<->" + // << static_cast< BaseObject * >( col2->getClientData() )->name() << std::endl; + + if ( obj->getTypeID() == PROJECTILE_RTTI ){ + if ( dynamic_cast< Projectile * >( obj )->parent() != static_cast< BaseObject * >( col1->getClientData() ) ){ + obj->mainNode()->setPosition( rayPickReport[ i ]->contact ); + obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); + static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); + return true; + } + } else if ( obj != col1->getClientData() ){ obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); - return true; } - } else if ( obj != col1->getClientData() ){ - obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); - static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); - } - } + } + } return false; } Modified: trunk/src/OpcodeWrapper.h =================================================================== --- trunk/src/OpcodeWrapper.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/OpcodeWrapper.h 2007-12-02 17:25:31 UTC (rev 873) @@ -43,16 +43,13 @@ bool update( Ogre::Real elapsedTime ); + OgreOpcode::CollisionObject * createObject( Ogre::Entity * entity, BaseObject * obj, const std::string & collClass ); OgreOpcode::CollisionObject * createObject( SectorObject * obj ); - OgreOpcode::CollisionObject * createObject( Ogre::Entity * entity, BaseObject * obj, const std::string & collClass = "SectorObject" ); - void destroyObject( OgreOpcode::CollisionObject * obj ); - bool checkCollideRay( BaseObject * obj, const Ogre::Ray & bulletRay, double rayLength ); + bool checkCollideRay( BaseObject * obj, const Ogre::Ray & ray, double rayLength ); - OgreOpcode::CollisionContext * collideInSectorContext(){ return collideInSectorContext_; } - void changeCollClass( OgreOpcode::CollisionObject * collObj, const std::string & collClass ); static OpcodeCollisionDetection & getSingleton( ); Modified: trunk/src/OpenALSoundManager.cpp =================================================================== --- trunk/src/OpenALSoundManager.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/OpenALSoundManager.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -187,9 +187,7 @@ return true; } -bool OpenALSoundSource::setDirection( float x, float y, float z ){ - return setDirection( Ogre::Vector3( x, y, z ) ); } - +bool OpenALSoundSource::setDirection( float x, float y, float z ){ return setDirection( Ogre::Vector3( x, y, z ) ); } bool OpenALSoundSource::setDirection( const Ogre::Vector3 & dir ){ direction_ = dir; alSourcefv( source_, AL_DIRECTION, direction_.ptr() ); @@ -227,7 +225,6 @@ return false; } - OpenALOggStreamSource::OpenALOggStreamSource( OpenALSoundManager * soundMgr, const std::string & name) : OpenALSoundSource( soundMgr, name ){ } @@ -392,7 +389,7 @@ return true; } -OpenALListener::OpenALListener( OpenALSoundManager * soundMgr ) : soundMgr_( soundMgr ){ + OpenALListener::OpenALListener( OpenALSoundManager * soundMgr, bool dummy ) : soundMgr_( soundMgr ), dummy_( dummy ){ reset(); } @@ -407,18 +404,22 @@ bool OpenALListener::setPosition( float x, float y, float z ){ return setPosition( Ogre::Vector3( x, y, z ) ); } bool OpenALListener::setPosition( const Ogre::Vector3 & pos){ - position_ = pos; - alListenerfv( AL_POSITION, position_.ptr() ); - if ( soundMgr_->checkOpenALError( "OpenALListener::alListenerfv:AL_POSITION" ) ) return false; + if ( !dummy_ ){ + position_ = pos; + alListenerfv( AL_POSITION, position_.ptr() ); + if ( soundMgr_->checkOpenALError( "OpenALListener::alListenerfv:AL_POSITION" ) ) return false; + } return true; } bool OpenALListener::setVelocity( float x, float y, float z ){ return setVelocity( Ogre::Vector3( x, y, z ) ); } bool OpenALListener::setVelocity( const Ogre::Vector3 & vel){ - velocity_ = vel; - alListenerfv( AL_VELOCITY, position_.ptr() ); - if ( soundMgr_->checkOpenALError( "OpenALListener::alListenerfv:AL_VELOCITY" ) ) return false; + if ( !dummy_ ){ + velocity_ = vel; + alListenerfv( AL_VELOCITY, position_.ptr() ); + if ( soundMgr_->checkOpenALError( "OpenALListener::alListenerfv:AL_VELOCITY" ) ) return false; + } return true; } @@ -426,12 +427,14 @@ return setOrientation( Ogre::Vector3( xf, yf, zf ), Ogre::Vector3( xu, yu, zu ) ); } bool OpenALListener::setOrientation( const Ogre::Vector3 & front, const Ogre::Vector3 & up){ - directionFront_ = front; directionUp_ = up; - orientation_[ 0 ] = front[ 0 ]; orientation_[ 1 ] = front[ 1 ]; orientation_[ 2 ] = front[ 2 ]; - orientation_[ 3 ] = up[ 0 ]; orientation_[ 4 ] = up[ 1 ]; orientation_[ 5 ] = up[ 2 ]; - - alListenerfv( AL_ORIENTATION, orientation_ ); - if ( soundMgr_->checkOpenALError( "OpenALListener::alListenerfv:AL_ORIENTATION" ) ) return false; + if ( !dummy_ ){ + directionFront_ = front; directionUp_ = up; + orientation_[ 0 ] = front[ 0 ]; orientation_[ 1 ] = front[ 1 ]; orientation_[ 2 ] = front[ 2 ]; + orientation_[ 3 ] = up[ 0 ]; orientation_[ 4 ] = up[ 1 ]; orientation_[ 5 ] = up[ 2 ]; + + alListenerfv( AL_ORIENTATION, orientation_ ); + if ( soundMgr_->checkOpenALError( "OpenALListener::alListenerfv:AL_ORIENTATION" ) ) return false; + } return true; } @@ -460,11 +463,13 @@ if ( listener_ ) delete listener_; - ALCcontext *context = alcGetCurrentContext(); - ALCdevice *device = alcGetContextsDevice( context ); - alcMakeContextCurrent( NULL ); - alcDestroyContext( context ); - alcCloseDevice( device ); + if ( haveSoundDevice_ ){ + ALCcontext *context = alcGetCurrentContext(); + ALCdevice *device = alcGetContextsDevice( context ); + alcMakeContextCurrent( NULL ); + alcDestroyContext( context ); + alcCloseDevice( device ); + } } bool OpenALSoundManager::frameStarted( const Ogre::FrameEvent & evt ){ @@ -535,26 +540,25 @@ if ( !device ){ log_->warn( "No sound device detected." ); haveSoundDevice_ = false; - return false; } - log_->info( "Choosing: " + Ogre::String( alcGetString( device, ALC_DEVICE_SPECIFIER) ) ); - ALCcontext * context = alcCreateContext( device, NULL ); - if ( !context ){ - log_->warn( "Can not create sound context." ); - return false; - } + if ( haveSoundDevice_ ){ + log_->info( "Choosing: " + Ogre::String( alcGetString( device, ALC_DEVICE_SPECIFIER) ) ); + ALCcontext * context = alcCreateContext( device, NULL ); - alcMakeContextCurrent( context ); - if ( checkOpenALError( "OpenALSoundManager::init::alcMakeContextCurrent" ) ) return false; + if ( !context ){ + log_->warn( "Can not create sound context." ); + return false; + } - maxSources_ = getMaxSources_(); - listener_ = new OpenALListener( this ); - if ( !context ){ - log_->warn( "Can not create sound context." ); - return false; + alcMakeContextCurrent( context ); + if ( checkOpenALError( "OpenALSoundManager::init::alcMakeContextCurrent" ) ) return false; + + maxSources_ = getMaxSources_(); } + listener_ = new OpenALListener( this, !haveSoundDevice_ ); + return true; } @@ -600,23 +604,25 @@ bool loop, bool stream ){ OpenALSoundSource * sound = NULL; + if ( mapSoundSources_.count( name ) ){ + log_->warn( "Sound with name: " + name + " allready registered." ); + mapSoundSources_[ name ]; + } + if ( haveSoundDevice_ ){ - if ( mapSoundSources_.count( name ) ){ - log_->warn( "Sound with name: " + name + " allready registered." ); - return NULL; - } - if ( stream ){ log_->info( "create sound stream: " + name ); sound = new OpenALOggStreamSource( this, name ); } else { sound = new OpenALSoundSource( this, name ); } + } else { + sound = new OpenALSoundSourceDummy( this, name ); + } - sound->open( fileName ); - sound->showInfos( ); - mapSoundSources_[ name ] = sound; - } + sound->open( fileName ); + sound->showInfos( ); + mapSoundSources_[ name ] = sound; return sound; } Modified: trunk/src/OpenALSoundManager.h =================================================================== --- trunk/src/OpenALSoundManager.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/OpenALSoundManager.h 2007-12-02 17:25:31 UTC (rev 873) @@ -60,35 +60,33 @@ virtual void showInfos(); - virtual bool update(){ - return true; - } + virtual bool update(){ return true; } //** check if the source is playing bool isPlaying(); bool setPosition( float x, float y, float z ); - bool setPosition( const Ogre::Vector3 & pos ); + virtual bool setPosition( const Ogre::Vector3 & pos ); bool setVelocity( float x, float y, float z ); - bool setVelocity( const Ogre::Vector3 & vel); + virtual bool setVelocity( const Ogre::Vector3 & vel); bool setDirection( float x, float y, float z ); - bool setDirection( const Ogre::Vector3 & dir); + virtual bool setDirection( const Ogre::Vector3 & dir); uint * refSound( ){ return &source_; } std::string name () const { return name_; } - bool setRelative( bool rel ); + virtual bool setRelative( bool rel ); - bool setRolloff( float rolloff ); + virtual bool setRolloff( float rolloff ); - bool setGain( float gain ); + virtual bool setGain( float gain ); - bool setPitch( float pitch ); + virtual bool setPitch( float pitch ); - bool setLoop( bool loop ); + virtual bool setLoop( bool loop ); protected: @@ -104,7 +102,33 @@ int format_; int size_; float freq_; +}; +class OpenALSoundSourceDummy : public OpenALSoundSource { +public: + OpenALSoundSourceDummy( OpenALSoundManager * soundMgr, const std::string & name) + : OpenALSoundSource( soundMgr, name ){ } + virtual ~OpenALSoundSourceDummy(){ }; + + virtual bool play(){ return true; } + virtual bool stop(){ return true; } + + virtual bool release(){ return true; } + virtual bool open( const std::string & fileName ){ return true; } + virtual void showInfos(){ LogManager::getSingleton().info( "Audio info: dummy " + name_ + " installed " ); } + + virtual bool update(){ return true; } + virtual bool setPosition( const Ogre::Vector3 & pos ){ return true; } + virtual bool setVelocity( const Ogre::Vector3 & vel ){ return true; } + virtual bool setDirection( const Ogre::Vector3 & dir ){ return true; } + virtual bool setLoop( bool loop ) { return true; } + virtual bool setGain( float gain ) { return true; } + virtual bool setPitch( float pitch ) { return true; } + virtual bool setRelative( bool rel ) { return true; } + virtual bool setRolloff( float rolloff ){ return true; } + +protected: + }; //! Based on: http://www.devmaster.net/articles/openal-tutorials/lesson8.php @@ -151,7 +175,7 @@ /*! OpenALListener, there is just one. YOU! respectivly your avatar. */ class OpenALListener{ public: - OpenALListener( OpenALSoundManager * soundMgr ); + OpenALListener( OpenALSoundManager * soundMgr, bool dummy = false); ~OpenALListener(); bool setPosition( float x, float y, float z ); @@ -172,6 +196,7 @@ Ogre::Vector3 directionFront_; Ogre::Vector3 directionUp_; float orientation_[ 6 ]; + bool dummy_; }; Modified: trunk/src/Projectile.cpp =================================================================== --- trunk/src/Projectile.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/Projectile.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -123,7 +123,7 @@ } else { trail_ = sceneMgr_->createRibbonTrail( bulletName + "_RibbonTrail"); trail_->setMaterialName( "BeamGreen" ); - trail_->setTrailLength( maxRange_ / 2.0 ); + trail_->setTrailLength( maxRange_ ); trail_->setWidthChange( 0, 2.0 ); trail_->setMaxChainElements( 1000 ); trail_->setInitialWidth( 0, 1.0 ); Modified: trunk/src/Projectile.h =================================================================== --- trunk/src/Projectile.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/Projectile.h 2007-12-02 17:25:31 UTC (rev 873) @@ -56,6 +56,8 @@ Gun * gun() const { return gun_; } + virtual void destroyRequest(){} + protected: BaseObject * parent_; Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/Sector.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -152,7 +152,7 @@ for ( std::map< long, SectorObjectMoveable * >::iterator it = movableObjects_.begin(); it != movableObjects_.end();){ // log_->info( "Destructing: " + it->second->name() ); - destructMoveableObject( (it++)->second ); + destructMoveableObject_( (it++)->second ); // log_->info( "done: " ); } @@ -444,25 +444,29 @@ for ( std::map< long, SectorObjectMoveable * >::iterator it = movableObjects_.begin(); it != movableObjects_.end(); ){ - if ( !it->second->update( elapsedTime ) ) { //** object died; - if ( it->second == avatar_ ) { - if ( avatarDeathSequenceTime_ == 0.0 ){ - avatarDeathSequenceTime_ = 1.0; - } else { - avatarDeathSequenceTime_ -= elapsedTime; - if ( avatarDeathSequenceTime_ < 0 ){ - avatarDeathSequenceTime_ = 0.0; - listener_->avatarDeathSequence( false ); + if ( !it->second ){ + log_->info( "update request for invalid object id: " + toStr( it->first ) ); + } else { + if ( !it->second->update( elapsedTime ) ) { //** object died; + if ( it->second == avatar_ ) { + if ( avatarDeathSequenceTime_ == 0.0 ){ + avatarDeathSequenceTime_ = 1.0; + } else { + avatarDeathSequenceTime_ -= elapsedTime; + if ( avatarDeathSequenceTime_ < 0 ){ + avatarDeathSequenceTime_ = 0.0; + listener_->avatarDeathSequence( false ); + } } + it++; + } else { //** died object is not avatar; + log_->info( "Destructing: " + it->second->name() ); + destructSectorObject_( (it++)->second ); + log_->info( "done: " ); } - it++; - } else { //** died object is not avatar; - log_->info( "Destructing: " + it->second->name() ); - destructSectorObject( (it++)->second ); - log_->info( "done: " ); - } - } else ++it; - } + } else ++it; + } + } } void Sector::avatarDied( ){ @@ -518,78 +522,87 @@ return obj; } -void Sector::destructSectorObject( SectorObject * obj ){ - selectNextTarget( obj ); - sectorObjects_.erase( obj ); +void Sector::destructSectorObject_( SectorObject * obj ){ + if ( obj ){ + selectNextTarget( obj ); + sectorObjects_.erase( obj ); - if ( obj->isOnRadar() && radar_ ){ - Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); - Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); - radarMap->removeChild( obj->dotA()->getName() ); - radarMap->removeChild( obj->dotB()->getName() ); - } - - for ( std::map< long, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); it != localAiObjects_.end(); it ++ ){ - if ( it->second->target() == obj ){ - log_->warn( std::string( "ai object target: " ) + it->second->name() + " loose target." ); - it->second->setTarget( NULL ); + if ( obj->isOnRadar() && radar_ ){ + Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); + Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); + radarMap->removeChild( obj->dotA()->getName() ); + radarMap->removeChild( obj->dotB()->getName() ); } + + for ( std::map< long, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); it != localAiObjects_.end(); it ++ ){ + if ( it->second->target() == obj ){ + log_->warn( std::string( "ai object target: " ) + it->second->name() + " loose target." ); + it->second->setTarget( NULL ); + } + } + + switch ( obj->getTypeID() ){ + case SECTOROBJECTMOVABLE_RTTI: + movableObjects_.erase( obj->globalID() ); + delete obj; + obj = NULL; + break; + case SECTOROBJECTMOVABLE_AI_RTTI: { + if ( dynamic_cast< SectorObjectMoveableAi *>( obj )->target() == avatar_ ) { + sendVesselDeRegister( dynamic_cast< SectorObjectMoveable * >( obj ) ); + } + movableObjects_.erase( obj->globalID() ); + localAiObjects_.erase( dynamic_cast< SectorObjectMoveableAi *>(obj)->globalID() ); + delete obj; + obj = NULL; + } break; + default: + log_->fatal( "destructSectorObject: object type unknown. this should not happen: " + toStr( obj->getTypeID() ) ); + } + } else { + log_->fatal( "destructSectorObject: object is no valid: " ); } - switch ( obj->getTypeID() ){ - case SECTOROBJECTMOVABLE_RTTI: - movableObjects_.erase( obj->globalID() ); - delete obj; - obj = NULL; - break; - case SECTOROBJECTMOVABLE_AI_RTTI: { - if ( dynamic_cast< SectorObjectMoveableAi *>( obj )->target() == avatar_ ) { - sendVesselDeRegister( dynamic_cast< SectorObjectMoveable * >( obj ) ); - } - movableObjects_.erase( obj->globalID() ); - localAiObjects_.erase( dynamic_cast< SectorObjectMoveableAi *>(obj)->globalID() ); - delete obj; - obj = NULL; - } break; - default: - log_->fatal( "destructSectorObject: object type unknown. this should not happen: " + toStr( obj->getTypeID() ) ); - } } -void Sector::destructMoveableObject( SectorObjectMoveable * obj ){ - selectNextTarget( obj ); - sectorObjects_.erase( obj ); +void Sector::destructMoveableObject_( SectorObjectMoveable * obj ){ + if ( obj ){ + selectNextTarget( obj ); + sectorObjects_.erase( obj ); - if ( obj->isOnRadar() && radar_ ){ - Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); - Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); - radarMap->removeChild( obj->dotA()->getName() ); - radarMap->removeChild( obj->dotB()->getName() ); - } - - for ( std::map< long, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); it != localAiObjects_.end(); it ++ ){ - if ( it->second->target() == obj ){ - log_->warn( std::string( "ai object target: " ) + it->second->name() + " loose target." ); - it->second->setTarget( NULL ); + if ( obj->isOnRadar() && radar_ ){ + Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); + Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); + radarMap->removeChild( obj->dotA()->getName() ); + radarMap->removeChild( obj->dotB()->getName() ); } + + for ( std::map< long, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); it != localAiObjects_.end(); it ++ ){ + if ( it->second->target() == obj ){ + log_->warn( std::string( "ai object target: " ) + it->second->name() + " loose target." ); + it->second->setTarget( NULL ); + } + } + + switch ( obj->getTypeID() ){ + case SECTOROBJECTMOVABLE_RTTI: + movableObjects_.erase( obj->globalID() ); + delete obj; + obj = NULL; + break; + case SECTOROBJECTMOVABLE_AI_RTTI: { + if ( dynamic_cast< SectorObjectMoveableAi *>( obj )->target() == avatar_ ) sendVesselDeRegister( obj ); + movableObjects_.erase( obj->globalID() ); + localAiObjects_.erase( dynamic_cast< SectorObjectMoveableAi *>(obj)->globalID() ); + delete obj; + obj = NULL; + } break; + default: + log_->fatal( "destructMoveableObject: object type unknown. this should not happen: " + toStr( obj->getTypeID() ) ); + } + } else { + log_->fatal( "destructMoveableObject: object is no valid: " ); } - - switch ( obj->getTypeID() ){ - case SECTOROBJECTMOVABLE_RTTI: - movableObjects_.erase( obj->globalID() ); - delete obj; - obj = NULL; - break; - case SECTOROBJECTMOVABLE_AI_RTTI: { - if ( dynamic_cast< SectorObjectMoveableAi *>( obj )->target() == avatar_ ) sendVesselDeRegister( obj ); - movableObjects_.erase( obj->globalID() ); - localAiObjects_.erase( dynamic_cast< SectorObjectMoveableAi *>(obj)->globalID() ); - delete obj; - obj = NULL; - } break; - default: - log_->fatal( "destructMoveableObject: object type unknown. this should not happen: " + toStr( obj->getTypeID() ) ); - } } SectorObjectMoveableAi * Sector::createAiMoveableObject( const Ogre::String & name, int userID, int childID, @@ -862,9 +875,8 @@ + movableObjects_[ createGlobalID( msg.senderID(), msg.childID() ) ]->name() ); SectorObjectMoveable *obj = movableObjects_[ createGlobalID( msg.senderID(), msg.childID() ) ]; + obj->destroyRequest(); - destructMoveableObject( obj ); - } else { log_->warn( std::string( "Deregistering request for unknown object: " ) + toStr( msg.senderID() ) + ": " + toStr( (int)msg.childID() ) ); @@ -948,11 +960,9 @@ void Sector::sendVesselAmmoHit( const Projectile & projectile, BaseObject * victim ){ if ( projectile.parent().userID() == network_->userID() ){ -// std::cout << "Send: Projectile from " << projectile.name() << " collide with: " << victim->name() -// << " " << victim->userID() << " " << victim->childID() << std::endl; - MessageBodyShipAmmoHit msg( projectile.parent().childID(), victim->userID(), victim->childID(), projectile.damage() ); network_->send( msg ); + // std::cout << " Send: " << msg << endl; victim->hitByAmmo( projectile.damage() ); } } @@ -963,19 +973,22 @@ std::map< long, SectorObjectMoveable * >::iterator it; if ( ( it = movableObjects_.find( createGlobalID( msg.targetID(), msg.targetChildID() ) ) ) != movableObjects_.end() ){ - log_->cout( "ReceiveVesselAmmoHit for " + network_->userName( msg.targetID() ) + " " + toStr( msg.damage() ) ); + // log_->cout( "ReceiveVesselAmmoHit for " + network_->userName( msg.targetID() ) + " " + toStr( msg.damage() ) ); + it->second->hitByAmmo( msg.damage() ); } else { log_->fatal( std::string( "Requested non existant object for VesselAmmoHit " ) + - " shooter: " + network_->userName( msg.senderID() ) + + " shooter: " + network_->userName( msg.senderID() ) + + " shooter id: " + toStr( msg.senderID() ) + + " gloabel id: " + toStr( createGlobalID( msg.targetID(), msg.targetChildID() ) ) + " victim: " + network_->userName( msg.targetID() ) + - " child: " + toStr( msg.targetChildID() ) + + " child: " + toStr( (int)msg.targetChildID() ) + " damage: " + toStr( msg.damage() ) + " this should not happen." ) ; -// std::cerr << "Available objects: " << std::endl; -// for ( std::map< long, SectorObjectMoveable * >::iterator i = movableObjects_.begin(); i != movableObjects_.end(); i++){ -// std::cerr << "\t" << i->first << " " << i->second->name() << " " << std::endl; -// } + std::cerr << "Available objects: " << std::endl; + for ( std::map< long, SectorObjectMoveable * >::iterator i = movableObjects_.begin(); i != movableObjects_.end(); i++){ + std::cerr << "\t" << i->first << " " << i->second->name() << " " << std::endl; + } } } } Modified: trunk/src/Sector.h =================================================================== --- trunk/src/Sector.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/Sector.h 2007-12-02 17:25:31 UTC (rev 873) @@ -61,10 +61,6 @@ SectorObjectMoveableAi * createAiMoveableObject( const Ogre::String & name, int userId, int childId, Vessel & vessel ); - void destructSectorObject( SectorObject * obj ); - - void destructMoveableObject( SectorObjectMoveable * obj ); - void createAvatarObject( Avatar & avatar ); SectorObjectAvatar * avatarObject() { return avatar_; } @@ -112,6 +108,11 @@ void receiveProjectile( const MessageBodyShipProjectileFired & msg ); protected: + //** do not destruct objects manualy, let them send false during update loop + void destructSectorObject_( SectorObject * obj ); + void destructMoveableObject_( SectorObjectMoveable * obj ); + + Ogre::SceneManager * sceneMgr_; NetworkClient * network_; LogManager * log_; Modified: trunk/src/SectorObjects.cpp =================================================================== --- trunk/src/SectorObjects.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/SectorObjects.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -27,6 +27,7 @@ #include <OgreOverlayManager.h> #include <OgreOverlayElement.h> #include <OgreEntity.h> +#include <OgreSubEntity.h> #include <OgreParticleSystem.h> #include <OgreParticleEmitter.h> #include <OgreBillboardSet.h> @@ -80,6 +81,7 @@ LogManager::getSingleton().fatal( e.getFullDescription() ); } + destroyRequest_ = false; lifeTime_ = 0.0; selectable_ = false; collObj_ = NULL; @@ -94,6 +96,7 @@ SectorObject::SectorObject( const Ogre::String & name, Sector * sector, int userID, int childID ) : BaseObject( name, sector, userID, childID ) { + destroyRequest_ = false; isOnRadar_ = false; mainNodeEntityScale_ = mainNode_->createChildSceneNode( name_ + "_baseScale" ); mainNodeEntityRot_ = mainNodeEntityScale_->createChildSceneNode( name_ + "_baseRot" ); @@ -132,6 +135,14 @@ mainNode_->removeAndDestroyChild( mainNodeEntityScale_->getName() ); } +void SectorObject::destroyRequest(){ + //** the object will finaly destroyed by the sectors update loop if this->update returns false + if ( collObj_ ) OpcodeCollisionDetection::getSingleton().destroyObject( collObj_ ); + collObj_ = NULL; + destroyRequest_ = true; + hide( ); +} + void SectorObject::setShape( const Ogre::String & meshname ){ entity_ = sceneMgr_->createEntity( name_ + "_shape", meshname ); mainNodeEntityRot_->attachObject( entity_ ); @@ -206,7 +217,6 @@ } } - setBaseRot( vessel_->baseYaw(), vessel_->basePitch(), vessel_->baseRoll() ); setBaseSize( vessel_->baseSize() ); @@ -235,6 +245,12 @@ mainNode_->attachObject( thrusterParticles_ ); } + shieldEntity_ = entity_->clone( entity_->getName() + "_shieldEntity" ); + shieldEntity_->setMaterialName("simpleshield"); + shieldEntity_->getSubEntity( 0 )->setCustomParameter( 0, Ogre::Vector4( 1.0, 0.0, 0.0, 0.4 ) ); + shieldEntityNode_ = mainNodeEntityRot_->createChildSceneNode( mainNodeEntityRot_->getName() + "_shieldEntityNode" ); + shieldEntityNode_->scale( 1.1, 1.1, 1.1); + explosion_ = NULL; armor_ = vessel_->armor(); setThrust( 0 ); @@ -242,11 +258,17 @@ } SectorObjectMoveable::~SectorObjectMoveable() { + shieldEntityNode_->detachObject( shieldEntity_ ); + mainNodeEntityRot_->removeAndDestroyChild( shieldEntityNode_->getName() ); + sceneMgr_->destroyEntity( shieldEntity_ ); + + Ogre::Entity * shieldEntity_; + Ogre::SceneNode * shieldEntityNode_; + if ( explosion_ ){ mainNode_->detachObject( explosion_ ); sceneMgr_->destroyParticleSystem( explosion_ ); } - if ( thrusterParticles_ ){ mainNode_->detachObject( thrusterParticles_ ); sceneMgr_->destroyParticleSystem( thrusterParticles_ ); @@ -270,12 +292,16 @@ delete gun; } activeGuns_.clear(); - } bool SectorObjectMoveable::update( Ogre::Real elapsedTime ){ if ( elapsedTime < 0.001 ) return true; + //** we only can destroy this object when all projectiles are and of life + if ( destroyRequest_ && projectiles_.size() == 0 ){ + return false; + } + lifeTime_ += elapsedTime; lastFrameCount_ ++; @@ -316,8 +342,10 @@ mainNode_->translate( ( vel_ + interpolateVel_ ) * elapsedTime ); //** because of the discrete jumps between to frames we have to check for collisions via ray; - Ogre::Ray rayNoNextPos( mainNode_->getPosition(), vel_.normalisedCopy() ); - OpcodeCollisionDetection::getSingleton().checkCollideRay( this, rayNoNextPos, (vel_ * elapsedTime).length() ); + if ( !destroyRequest_ ){ + Ogre::Ray rayNoNextPos( mainNode_->getPosition(), vel_.normalisedCopy() ); + OpcodeCollisionDetection::getSingleton().checkCollideRay( this, rayNoNextPos, (vel_ * elapsedTime).length() ); + } for ( std::set < Projectile * >::iterator it = projectiles_.begin(); it != projectiles_.end();){ if ( !(*it)->update( elapsedTime ) ) { @@ -326,6 +354,16 @@ } else ++it; } + if ( shieldGlowActive_ ){ + shieldGlowTime_ -= elapsedTime; + shieldEntity_->getSubEntity( 0 )->setCustomParameter( 0, Ogre::Vector4( 1.0, 0.0, 0.0, shieldGlowTime_ / 2.0 ) ); + + if ( shieldGlowTime_ < 0 ) { + shieldEntityNode_->detachObject( shieldEntity_ ); + shieldGlowActive_ = false; + } + } + // //** snap quaternion // Ogre::Quaternion rnd( mainNode_->getOrientation() ); // mainNode_->setOrientation( round( rnd.w, 5 ), round( rnd.x, 5 ), round( rnd.y, 5 ), round( rnd.z, 5 ) ); @@ -443,7 +481,15 @@ // std::cout << "SectorObjectMoveable: " << name() << " collide with " << object->getTypeID() << " " << object->name() << std::endl; if ( name_ != object->name() ){ if ( object->getTypeID( ) == PROJECTILE_RTTI ){ - // hitByProjectile( dynamic_cast< Projectile* >( object ) ); + + shieldGlowTime_ = 1.0; + + if ( !shieldGlowActive_ && shield_ > 0 ){ + shieldGlowActive_ = true; + shieldEntityNode_->attachObject( shieldEntity_ ); + } + + return; } if ( object->getTypeID( ) == STATION_RTTI ){ @@ -578,15 +624,16 @@ maxShield_ = 0; if ( vessel_->shield() ) maxShield_ = vessel_->shield()->maxDeflection(); - shield_ = maxShield_; - lastShieldSend_ = 0; + shield_ = maxShield_; + lastShieldSend_ = 0; + shieldGlowActive_ = false; + shieldGlowTime_ = 0.0; } bool SectorObjectMoveableLocal::update( Ogre::Real elapsedTime ){ - SectorObjectMoveable::update( elapsedTime ); //** object died - if ( armor_ <= 0 || deathSequence_ ) { + if ( armor_ <= 0 || deathSequence_ || !SectorObjectMoveable::update( elapsedTime ) ) { return deathSequence( elapsedTime ); } @@ -619,13 +666,17 @@ void SectorObjectMoveableLocal::hitByAmmo( Uint32 damage ){ - shield_ -= damage; + int shield = shield_ - damage; + int armor = armor_; - if ( shield_ < 0 ){ - armor_ += shield_; + if ( shield < 0 ){ + armor += shield; shield_ = 0; - armor_ = max( Uint32(0), armor_); + armor_ = max( 0, armor ); + } else { + shield_ = shield; } + statusChanged_ = true; } Modified: trunk/src/SectorObjects.h =================================================================== --- trunk/src/SectorObjects.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/SectorObjects.h 2007-12-02 17:25:31 UTC (rev 873) @@ -88,6 +88,10 @@ virtual long getTypeID() const = 0; + virtual void destroyRequest() = 0; + + bool isSetDestroyRequest() const { return destroyRequest_; } + inline virtual int userID() const { return userID_; } inline virtual int childID() const { return childID_; } @@ -128,6 +132,7 @@ Ogre::SceneManager * sceneMgr_; OgreOpcode::CollisionObject * collObj_; Ogre::Real lifeTime_; + bool destroyRequest_; }; class SectorObject : public BaseObject { @@ -138,8 +143,10 @@ inline virtual long getTypeID() const { return SECTOROBJECT_RTTI; } + virtual void destroyRequest(); + virtual void collide( BaseObject * object ){ - std::cout << "SectorObject " << name_ << " collide with " << object->getTypeID() << " " << object->name()<< std::endl; + // std::cout << "SectorObject " << name_ << " collide with " << object->getTypeID() << " " << object->name()<< std::endl; } virtual bool update( Ogre::Real elapsedTime ){ return true; } @@ -168,11 +175,14 @@ virtual void selectedBy( SectorObject * obj ){ selector_ = obj; } + virtual void setVisible( bool visible ){ mainNode_->setVisible( false ); } + void show( ){ setVisible( true ); } + void hide( ){ setVisible( false ); } + protected: Ogre::SceneNode * mainNodeEntityScale_; // Main character node for base size Ogre::SceneNode * mainNodeEntityRot_; // Main character node for base rotation - Ogre::SceneNode * mainEntityNode_; // Main character node which hold the entity Ogre::Entity * entity_; Ogre::OverlayElement * dotA_; @@ -183,6 +193,7 @@ Ogre::Vector3 baseScale_; SectorObject * selector_; + }; /*! Base class for movable objects, instances are only used for foreign player objects. */ @@ -326,6 +337,11 @@ Ogre::ParticleSystem * explosion_; Ogre::BillboardSet * thrusterBbs_; + Ogre::Entity * shieldEntity_; + Ogre::SceneNode * shieldEntityNode_; + Ogre::Real shieldGlowTime_; + bool shieldGlowActive_; + Uint32 mass_; Uint32 thrust_; Uint32 maxThrust_; Modified: trunk/src/Station.h =================================================================== --- trunk/src/Station.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/Station.h 2007-12-02 17:25:31 UTC (rev 873) @@ -65,6 +65,8 @@ Ogre::Real radius() const { return radius_; } + void destroyRequest() { } + protected: Ogre::ManualObject * dockPadManualObject_; Ogre::Entity * dockPadEntity_; Modified: trunk/src/common.cpp =================================================================== --- trunk/src/common.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/common.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -20,8 +20,6 @@ #include "common.h" -long createGlobalID( int userId, int childId ) { return childId * MAXUSERID + userId; } - void myMSleep( int s ) { #ifdef WIN32 Sleep( s ); Modified: trunk/src/common.h =================================================================== --- trunk/src/common.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/common.h 2007-12-02 17:25:31 UTC (rev 873) @@ -46,9 +46,9 @@ #include <algorithm> #include <sys/timeb.h> -typedef unsigned char Uint8; -typedef unsigned short Uint16; -typedef int Uint32; +typedef uint8_t Uint8; +typedef uint16_t Uint16; +typedef uint32_t Uint32; #ifdef WIN32 #define PATHSEPARATOR "\\" @@ -66,7 +66,7 @@ // typedef void (T::*Type)( const std::vector< std::string > &); // }; -long createGlobalID( int userId, int childId ); +inline Uint32 createGlobalID( Uint32 userId, Uint8 childId ) { return childId * MAXUSERID + userId; } //! In-place convert string to lower case \return ref to transformed string inline void strToLower( std::string & str ) { std::transform(str.begin(), str.end(), str.begin(), tolower ); } @@ -169,12 +169,27 @@ } /*! + * \brief Quick and dirty check if a file exist. + * + */ +inline bool fileExist( const std::string & filename ){ + bool result = false; + std::ifstream file; file.open( filename.c_str() ); + if ( file ) { + result = true; + file.close(); + } + return result; +} + +/*! * \brief This method is used as a cross plattform sleep method. * * You pass an amount of seconds to this function that you want the program or * a single thread to sleep. * \param s The amount of seconds to sleep */ + void myMSleep( int s ); class Stopwatch { Modified: trunk/src/metaserver.cpp =================================================================== --- trunk/src/metaserver.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/metaserver.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -29,7 +29,7 @@ namespace OpenGate{ - MetaConnection::MetaConnection( asio::io_service & io_service, LogManagerBase & log ) : +MetaConnection::MetaConnection( asio::io_service & io_service, LogManagerBase & log ) : io_service_( io_service ), socket_( io_service ), resolver_( io_service ), log_( &log ) { isConnected_ = true; @@ -99,9 +99,9 @@ } else { log_->fatal( std::string( "meta server login: we got no response " ) ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "meta server login: asio::error: " ) + e.what() ); - return -5; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "meta server login: asio::error: " ) + e.what() ); +// return -5; } catch ( std::exception & e) { log_->fatal( std::string( "meta server login: std::exception: " ) + e.what() ); return -5; @@ -114,7 +114,7 @@ return META_NOT_CONNECTED; } -int MetaConnection::check_version( int user_id ) { +int MetaConnection::check_version( Uint32 user_id ) { if ( isConnected_ ) { try { @@ -149,9 +149,9 @@ } else { log_->fatal( std::string( "meta server check_version: we got no response " ) ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "meta server check_version: asio::error: " ) + e.what() ); - return -5; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "meta server check_version: asio::error: " ) + e.what() ); +// return -5; } catch ( std::exception & e) { log_->fatal( std::string( "meta server check_version: std::exception: " ) + e.what() ); return -5; @@ -164,7 +164,7 @@ return META_NOT_CONNECTED; } -int MetaConnection::logout( int user_id ) { +int MetaConnection::logout( Uint32 user_id ) { if ( isConnected_ ) { try { @@ -200,9 +200,9 @@ } else { log_->fatal( std::string( "meta server logout: we got no response " ) ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "meta server logout: asio::error: " ) + e.what() ); - return -5; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "meta server logout: asio::error: " ) + e.what() ); +// return -5; } catch ( std::exception & e) { log_->fatal( std::string( "meta server logout: std::exception: " ) + e.what() ); return -5; @@ -260,9 +260,9 @@ } else { log_->fatal( std::string( "meta server add game server: we got no response " ) ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "meta server add game server: asio::error: " ) + e.what() ); - return -5; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "meta server add game server: asio::error: " ) + e.what() ); +// return -5; } catch ( std::exception & e) { log_->fatal( std::string( "meta server add game server: std::exception: " ) + e.what() ); return -5; @@ -315,9 +315,9 @@ } else { log_->fatal( std::string( "meta server list game server: we got no response " ) ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "meta server list game server: asio::error: " ) + e.what() ); - return mylist; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "meta server list game server: asio::error: " ) + e.what() ); +// return mylist; } catch ( std::exception & e) { log_->fatal( std::string( "meta server list game server: std::exception: " ) + e.what() ); return mylist; @@ -363,9 +363,9 @@ log_->fatal( std::string( "meta server remove game server: we got no response " ) ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "meta server remove game server: asio::error: " ) + e.what() ); - return -5; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "meta server remove game server: asio::error: " ) + e.what() ); +// return -5; } catch ( std::exception & e) { log_->fatal( std::string( "meta server remove game server: std::exception: " ) + e.what() ); return -5; @@ -381,7 +381,7 @@ // Form the request. We specify the "Connection: close" header so that the // server will close the socket after transmitting the response. This will // allow us to treat all data up until the EOF as the content. - asio::error error = asio::error::host_not_found; + asio::error_code error = asio::error::host_not_found; try{ tcp::resolver::query query( hostname_, "http" ); tcp::resolver::iterator endpoint_iterator = resolver_.resolve( query ); @@ -389,11 +389,11 @@ while ( error && endpoint_iterator != end ) { socket_.close(); - socket_.connect( *endpoint_iterator++, asio::assign_error( error ) ); + socket_.connect( *endpoint_iterator++, error ); } - } catch ( asio::error & e) { - log_->fatal( std::string( "resolving meta server: asio::error: " ) + e.what() ); - isConnected_ = false; +// } catch ( asio::error & e) { +// log_->fatal( std::string( "resolving meta server: asio::error: " ) + e.what() ); +// isConnected_ = false; } catch ( std::exception & e) { log_->fatal( std::string( "resolving meta server: std::exception: " ) + e.what() ); isConnected_ = false; @@ -422,6 +422,7 @@ unsigned int status_code; response_stream >> status_code; std::string status_message; + std::getline(response_stream, status_message); if ( !response_stream || http_version.substr(0, 5) != "HTTP/" ) { log_->fatal( "Metaserver: invalid response" ); @@ -444,11 +445,13 @@ error = asio::error::eof; // Read until EOF, writing data to output as we go. // std::cout << "response: " <<std::endl; - while ( asio::read( socket_, response, asio::transfer_at_least( 1 ), asio::assign_error( error ) ) ){ + while ( asio::read( socket_, response, asio::transfer_at_least( 1 ), error ) ){ // std::cout << &response << std::endl; } if ( error != asio::error::eof ) throw error; + + socket_.close(); return 1; } Modified: trunk/src/metaserver.h =================================================================== --- trunk/src/metaserver.h 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/metaserver.h 2007-12-02 17:25:31 UTC (rev 873) @@ -22,6 +22,7 @@ #define _OPENGATE_METASERVER__H #include <asio.hpp> +#include "common.h" using asio::ip::tcp; @@ -37,8 +38,8 @@ ~MetaConnection(); int login( const std::string & userName, const std::string & passwd = "" ); - int check_version( int user_id ); - int logout( int user_id ); + int check_version( Uint32 user_id ); + int logout( Uint32 user_id ); //** register the current ip to the metaserver, you can specify a symbolic name int add_game_server( const std::string & servername = ""); Modified: trunk/src/networkClient.cpp =================================================================== --- trunk/src/networkClient.cpp 2007-11-27 23:37:55 UTC (rev 872) +++ trunk/src/networkClient.cpp 2007-12-02 17:25:31 UTC (rev 873) @@ -37,7 +37,7 @@ log_->info( std::string( "Connecting to " ) + hostname_ + ":" + toStr( (int)OG_PORT ) ); - asio::error error = asio::error::host_not_found; + asio::error_code error = asio::error::host_not_found; try{ tcp::resolver::query query( hostname_, toStr( (int)OG_PORT) ); tcp::resolver::iterator endpoint_iterator = resolver_.resolve( query ); @@ -45,22 +45,22 @@ while ( error && endpoint_iterator != end ) { socket_.close(); - socket_.connect( *endpoint_iterator++, asio::assign_error( error ) ); + socket_.connect( *endpoint_iterator++, error ); } - } catch ( asio::error & e) { - log_->fatal( e.what() ); + if ( error ) throw asio::system_error( error ); } catch ( std::exception & e) { - log_->fatal( std::string( "Exception: " ) + e.what() ); + log_->fatal( std::string( "std::exception: " ) + e.what() ); } catch (...) { log_->fatal( "Unkown exception occured while resolving the server" ); } if ( !error ){ log_->info( "Connected: waiting for userID. " ); online_ = true; - asio::async_read( socket_, asio::buffer( readMsg_.data(), Message::HeaderLength+MessageBodyUserID( Uint32(0) ).dataSize() ), + asio::async_read( socket_, + asio::buffer( readMsg_.data(), Message::HeaderLength + MessageBodyUserID( Uint32(0) ).dataSize() ), boost::bind( & NetworkClient::handleReceiveUserID, this, asio::placeholders::error ) ); } else { - log_->fatal( error.what() ); + log_->fatal( "NetworkClient: asio error" + toStr( error ) ); } } @@ -92,7 +92,7 @@ } } -std::string NetworkClient::userName( int userID ) { +std::string NetworkClient::userName( Uint32 userID ) { if ( userID == 0 ) return userName_; if ( users_.count( userID ) ){ @@ -103,9 +103,9 @@ } } -void NetworkClient::handleReceiveUserID( const asio::error & error ) { +void NetworkClient::handleReceiveUserID( const asio::error_code & error ) { if ( online_ ){ - // std::cout << "handleReceiveUserID " << std::endl; + std::cout << "handleReceiveUserID " << std::endl; if ( !error && readMsg_.decodeHeader() ) { @@ -118,38 +118,38 @@ default: log_->fatal( std::string( "unknown MESSAGE_PROTO " ) + toStr( base.type() ) ); log_->fatal( "wait for userid " ); - asio::async_read( socket_, asio::buffer( readMsg_.data(), - Message::HeaderLength+MessageBodyUserID( Uint32(0) ).dataSize() ), - boost::bind( & NetworkClient::handleReceiveUserID, this, - asio::placeholders::error ) ); + asio::async_read( socket_, + asio::buffer( readMsg_.data(), Message::HeaderLength+MessageBodyUserID( Uint32(0) ).dataSize() ), + boost::bind( & NetworkClient::handleReceiveUserID, this, asio::placeholders::error ) ); } - asio::async_read(socket_, asio::buffer( readMsg_.data(), Message::HeaderLength ), - boost::bind( & NetworkClient::handleReadMessageHeader, this, - as... [truncated message content] |
From: <eg...@us...> - 2007-12-08 12:40:10
|
Revision: 878 http://opengate.svn.sourceforge.net/opengate/?rev=878&view=rev Author: egore Date: 2007-12-08 04:40:12 -0800 (Sat, 08 Dec 2007) Log Message: ----------- * data/Makefile.am, configure.ac: add some parts of the data to the build system Modified Paths: -------------- trunk/ChangeLog trunk/Makefile.am trunk/configure.ac trunk/src/Makefile.am Added Paths: ----------- trunk/data/Makefile.am Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-12-03 20:34:06 UTC (rev 877) +++ trunk/ChangeLog 2007-12-08 12:40:12 UTC (rev 878) @@ -1,3 +1,7 @@ +2007-12-08 Christoph Brill <ego...@eg...> + * data/Makefile.am, configure.ac: add some parts of the data to the + build system + 2007-11-18 Christoph Brill <ego...@eg...> * configure.ac: add some missing things gathered from running autoscan, drop externals stuff Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2007-12-03 20:34:06 UTC (rev 877) +++ trunk/Makefile.am 2007-12-08 12:40:12 UTC (rev 878) @@ -1,5 +1,8 @@ -SUBDIRS = src +AUTOMAKE_OPTIONS = dist-bzip2 +SUBDIRS = src \ + data + distclean: maintainer-clean rm -rf *~ rm -rf autom4te.cache Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2007-12-03 20:34:06 UTC (rev 877) +++ trunk/configure.ac 2007-12-08 12:40:12 UTC (rev 878) @@ -21,7 +21,7 @@ AC_FUNC_STAT AC_FUNC_STRTOD AC_HEADER_STDBOOL -AC_PROG_RANLIB +#AC_PROG_RANLIB AC_STRUCT_TM AC_TYPE_SIGNAL AC_TYPE_SIZE_T @@ -92,6 +92,7 @@ AC_OUTPUT([ Makefile +data/Makefile src/Makefile ]) Added: trunk/data/Makefile.am =================================================================== --- trunk/data/Makefile.am (rev 0) +++ trunk/data/Makefile.am 2007-12-08 12:40:12 UTC (rev 878) @@ -0,0 +1,382 @@ + +asteroids_DATA = \ + asteroids/asteroid.material\ + asteroids/asteroid.png \ + asteroids/asteroid01.mesh \ + asteroids/asteroidBump.png \ + asteroids/ice_oval.material \ + asteroids/ice_oval.png \ + asteroids/ice_oval_6.mesh \ + asteroids/ice_oval_7.mesh \ + asteroids/ice_oval_8.mesh \ + asteroids/ice_oval_9.mesh \ + asteroids/ice_oval_10.mesh \ + asteroids/normal_oval.material \ + asteroids/normal_oval.png \ + asteroids/normal_oval_1.mesh \ + asteroids/normal_oval_2.mesh \ + asteroids/normal_oval_3.mesh \ + asteroids/normal_oval_4.mesh \ + asteroids/normal_oval_5.mesh + +EXTRA_DIST = \ + $(asteroids_DATA)\ + $(capacitors_DATA) \ + $(commodities_DATA) \ + $(ecms_DATA) \ + $(engines_DATA) \ + $(power_plants_DATA) \ + $(rankings_DATA) \ + $(radars_DATA) \ + $(guns_DATA) \ + $(shields_DATA) \ + $(stations_DATA) + +asteroidsdir = \ + $(pkgdatadir)/asteroids + +capacitors_DATA = \ + capacitors/alembic.xml\ + capacitors/alembic_big.png \ + capacitors/alembic_small.png \ + capacitors/deepol.xml \ + capacitors/deepol_big.png \ + capacitors/deepol_small.png \ + capacitors/germ.xml \ + capacitors/germ_big.png \ + capacitors/germ_small.png \ + capacitors/jar.xml \ + capacitors/jar_big.png \ + capacitors/jar_small.png \ + capacitors/lifeline.xml \ + capacitors/lifeline_big.png \ + capacitors/lifeline_small.png \ + capacitors/Makefile.am \ + capacitors/mantra.xml \ + capacitors/mantra_big.png \ + capacitors/mantra_small.png \ + capacitors/outlet.xml \ + capacitors/outlet_big.png \ + capacitors/outlet_small.png \ + capacitors/quadro.xml \ + capacitors/quadro_big.png \ + capacitors/quadro_small.png \ + capacitors/sponge.xml \ + capacitors/sponge_big.png \ + capacitors/sponge_small.png \ + capacitors/summoner.xml \ + capacitors/summoner_big.png \ + capacitors/summoner_small.png \ + capacitors/tank.xml \ + capacitors/tank_big.png \ + capacitors/tank_small.png \ + capacitors/t-c-15.xml \ + capacitors/t-c-15_big.png \ + capacitors/t-c-15_small.png + +commodities_DATA = \ + commodities/aluminium.xml\ + commodities/aluminium_big.png \ + commodities/aluminium_small.png \ + commodities/ammunition.xml \ + commodities/ammunition_big.png \ + commodities/ammunition_small.png \ + commodities/antimony.xml \ + commodities/antimony_big.png \ + commodities/antimony_small.png \ + commodities/armor.xml \ + commodities/armor_big.png \ + commodities/armor_small.png \ + commodities/barium.png \ + commodities/barium.xml \ + commodities/boron.xml \ + commodities/boron_big.png \ + commodities/boron_small.png \ + commodities/cesium.xml \ + commodities/cesium_big.png \ + commodities/cesium_small.png \ + commodities/chemicals.xml \ + commodities/chemicals_big.png \ + commodities/chemicals_small.png \ + commodities/chromium.xml \ + commodities/chromium_big.png \ + commodities/chromium_small.png \ + commodities/copper.xml \ + commodities/copper_big.png \ + commodities/copper_small.png \ + commodities/cpus.xml \ + commodities/cpus_big.png \ + commodities/cpus_small.png \ + commodities/electronics.xml \ + commodities/electronics_big.png \ + commodities/electronics_small.png \ + commodities/fiber_optics.xml \ + commodities/fiber_optics_big.png \ + commodities/fiber_optics_small.png \ + commodities/fuel_cells.xml \ + commodities/fuel_cells_big.png \ + commodities/fuel_cells_small.png \ + commodities/gold.xml \ + commodities/gold_big.png \ + commodities/gold_small.png \ + commodities/helium.xml \ + commodities/helium_big.png \ + commodities/helium_small.png \ + commodities/ice.xml \ + commodities/ice_big.png \ + commodities/ice_small.png \ + commodities/iron.xml \ + commodities/iron_big.png \ + commodities/iron_small.png \ + commodities/laser_components.xml \ + commodities/laser_components_big.png \ + commodities/laser_components_small.png \ + commodities/lumber.xml \ + commodities/lumber_big.png \ + commodities/lumber_small.png \ + commodities/magnetic_components.png \ + commodities/magnetic_components.xml \ + commodities/manufactured_foods.xml \ + commodities/manufactured_foods_big.png \ + commodities/manufactured_foods_small.png \ + commodities/medical_supplies.xml \ + commodities/medical_supplies_big.png \ + commodities/medical_supplies_small.png \ + commodities/nitrogen.xml \ + commodities/nitrogen_big.png \ + commodities/nitrogen_small.png \ + commodities/octavia_light.xml \ + commodities/octavia_light_big.png \ + commodities/octavia_light_small.png \ + commodities/organic_foods.xml \ + commodities/organic_foods_big.png \ + commodities/organic_foods_small.png \ + commodities/plutonium.xml \ + commodities/plutonium_big.png \ + commodities/plutonium_small.png \ + commodities/power_converters.xml \ + commodities/power_converters_big.png \ + commodities/power_converters_small.png \ + commodities/prostheses.xml \ + commodities/prostheses_big.png \ + commodities/prostheses_small.png \ + commodities/ram.xml \ + commodities/ram_big.png \ + commodities/ram_small.png \ + commodities/rubber.xml \ + commodities/rubber_big.png \ + commodities/rubber_small.png \ + commodities/squadrok_biomass.xml \ + commodities/squadrok_biomass_big.png \ + commodities/squadrok_biomass_small.png \ + commodities/tauseti_flashback.xml \ + commodities/tauseti_flashback_big.png \ + commodities/tauseti_flashback_small.png \ + commodities/unsigned_box.xml \ + commodities/unsigned_box_big.png \ + commodities/unsigned_box_small.png \ + commodities/uranium.xml \ + commodities/uranium_big.png \ + commodities/uranium_small.png \ + commodities/water.xml \ + commodities/water_big.png \ + commodities/water_small.png \ + commodities/xenon.xml \ + commodities/xenon_big.png \ + commodities/xenon_small.png \ + commodities/zinc.xml \ + commodities/zinc_big.png \ + commodities/zinc_small.png + +commoditiesdir = \ + $(pkgdatadir)/commodities + +capacitorsdir = \ + $(pkgdatadir)/capacitors + +ecms_DATA = \ + ecms/ghost.xml + +engines_DATA = \ + engines/money.xml\ + engines/money_big.png \ + engines/money_small.png \ + engines/t-e-15.xml \ + engines/t-e-15_big.png \ + engines/t-e-15_small.png + +power_plants_DATA = \ + power_plants/contender.xml\ + power_plants/contender_big.png \ + power_plants/contender_small.png \ + power_plants/contender_xl.xml \ + power_plants/contender_xl_big.png \ + power_plants/contender_xl_small.png \ + power_plants/contender_xpr.xml \ + power_plants/contender_xpr_big.png \ + power_plants/contender_xpr_small.png \ + power_plants/gatherer.xml \ + power_plants/gatherer_big.png \ + power_plants/gatherer_small.png \ + power_plants/spud.xml \ + power_plants/spud_big.png \ + power_plants/spud_small.png \ + power_plants/t-p-16.xml \ + power_plants/t-p-16_big.png \ + power_plants/t-p-16_small.png + +rankings_DATA = \ + rankings/00.png\ + rankings/01.png \ + rankings/02.png \ + rankings/03.png \ + rankings/04.png \ + rankings/05.png \ + rankings/06.png \ + rankings/07.png \ + rankings/08.png \ + rankings/09.png \ + rankings/10.png \ + rankings/11.png \ + rankings/12.png \ + rankings/13.png \ + rankings/14.png \ + rankings/15.png \ + rankings/16.png \ + rankings/17.png \ + rankings/18.png \ + rankings/19.png \ + rankings/20.png \ + rankings/21.png \ + rankings/22.png \ + rankings/23.png \ + rankings/24.png \ + rankings/25.png \ + rankings/26.png \ + rankings/27.png \ + rankings/28.png \ + rankings/29.png \ + rankings/30.png \ + rankings/31.png \ + rankings/32.png \ + rankings/33.png \ + rankings/34.png \ + rankings/35.png \ + rankings/36.png \ + rankings/37.png \ + rankings/38.png \ + rankings/39.png \ + rankings/40.png \ + rankings/41.png \ + rankings/42.png \ + rankings/43.png \ + rankings/44.png \ + rankings/45.png \ + rankings/46.png \ + rankings/47.png \ + rankings/48.png \ + rankings/49.png \ + rankings/50.png + +radars_DATA = \ + radars/chime.xml\ + radars/chime_big.png \ + radars/chime_small.png \ + radars/cyclops.xml \ + radars/cyclops_big.png \ + radars/cyclops_small.png \ + radars/hall_monitor.xml \ + radars/hall_monitor_big.png \ + radars/hall_monitor_small.png \ + radars/knocker.xml \ + radars/knocker_big.png \ + radars/knocker_small.png \ + radars/night_watchman.xml \ + radars/night_watchman_big.png \ + radars/night_watchman_small.png \ + radars/outlook.xml \ + radars/outlook_big.png \ + radars/outlook_small.png \ + radars/t-r-9.xml \ + radars/t-r-9_big.png \ + radars/t-r-9_small.png + +guns_DATA = \ + guns/bender.xml\ + guns/bender_big.png \ + guns/bender_small.png \ + guns/duster.xml \ + guns/duster_big.png \ + guns/duster_small.png \ + guns/excavator.xml \ + guns/excavator_big.png \ + guns/excavator_small.png \ + guns/liar.xml \ + guns/liar_big.png \ + guns/liar_small.png \ + guns/t-g-28.xml \ + guns/t-g-28_big.png \ + guns/t-g-28_small.png + +shields_DATA = \ + shields/alpaa.xml\ + shields/alpaa_big.png \ + shields/alpaa_small.png \ + shields/flatiron.xml \ + shields/flatiron_big.png \ + shields/flatiron_small.png \ + shields/himelea.xml \ + shields/himelea_big.png \ + shields/himelea_small.png \ + shields/kydango.xml \ + shields/kydango_big.png \ + shields/kydango_small.png \ + shields/pod.xml \ + shields/pod_big.png \ + shields/pod_small.png \ + shields/shelter.xml \ + shields/shelter_big.png \ + shields/shelter_small.png \ + shields/t-s-13.xml \ + shields/t-s-13_big.png \ + shields/t-s-13_small.png + +stations_DATA = \ + stations/octavius_core.xml\ + stations/tauseti_core.xml \ + stations/TausetiStationBackground.png \ + stations/TausetiStationBackground.xcf \ + stations/TausetiStationBackgroundBM.png \ + stations/TausetiStationBackgroundPlain.png \ + stations/TausetiStationWindow.png \ + stations/TausetiStationWindow.xcf \ + stations/TausetiStationWindowBM.png \ + stations/tauseti_wake.mesh \ + stations/tauseti_wake.xml + +enginesdir = \ + $(pkgdatadir)/engines + +radarsdir = \ + $(pkgdatadir)/radars + +rankingsdir = \ + $(pkgdatadir)/rankings + +shieldsdir = \ + $(pkgdatadir)/shields + +power_plantsdir = \ + $(pkgdatadir)/power_plants + +gunsdir = \ + $(pkgdatadir)/guns + +stationsdir = \ + $(pkgdatadir)/stations + +ecmsdir = \ + $(pkgdatadir)/ecms + +## File created by the gnome-build tools + Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2007-12-03 20:34:06 UTC (rev 877) +++ trunk/src/Makefile.am 2007-12-08 12:40:12 UTC (rev 878) @@ -1,7 +1,6 @@ bin_PROGRAMS = \ opengateclient \ opengateserver -# testopenalmanager opengateclient_SOURCES = \ opengateclient.cpp \ @@ -72,17 +71,17 @@ metaserver.h \ metaserver.cpp -opengateclient_LDFLAGS = \ - $(OGRE_LIBS) \ - $(CEGUI_LIBS) \ - $(CEGUIOGRE_LIBS) \ - $(freealut_LIBS) \ - $(vorbisfile_LIBS) \ - $(OIS_LIBS) \ +opengateclient_LDFLAGS = \ + $(OGRE_LIBS) \ + $(CEGUI_LIBS) \ + $(CEGUIOGRE_LIBS) \ + $(freealut_LIBS) \ + $(vorbisfile_LIBS) \ + $(OIS_LIBS) \ $(ogreopcode_LIBS) opengateclient_CXXFLAGS = \ - $(OGRE_CFLAGS) \ + $(OGRE_CFLAGS) \ $(CEGUI_CFLAGS) \ $(ogreopcode_CFLAGS) @@ -101,12 +100,11 @@ metaserver.h \ metaserver.cpp -opengateserver_LDFLAGS = -# $(OGRE_LIBS) \ -# $(OIS_LIBS) +opengateserver_LDFLAGS = \ + $(ogreopcode_LIBS) -opengateserver_CXXFLAGS = -# $(OGRE_CFLAGS) +opengateserver_CXXFLAGS = \ + $(ogreopcode_CFLAGS) #testopenalmanager_SOURCES = \ # testopenalmanager.cpp \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spo...@us...> - 2007-12-28 12:05:38
|
Revision: 881 http://opengate.svn.sourceforge.net/opengate/?rev=881&view=rev Author: spom_spom Date: 2007-12-28 04:05:37 -0800 (Fri, 28 Dec 2007) Log Message: ----------- add forgotten files Modified Paths: -------------- trunk/data/materials/advancedMaterials.program trunk/data/materials/simpleshield.material trunk/data/skybox/skybox.material trunk/resources.cfg Added Paths: ----------- trunk/data/materials/planet.cg trunk/data/materials/planet.material trunk/data/textures/clouds_2500x1250.jpg trunk/data/textures/nm_bk.png trunk/data/textures/nm_dn.png trunk/data/textures/nm_fr.png trunk/data/textures/nm_lf.png trunk/data/textures/nm_rt.png trunk/data/textures/nm_up.png trunk/data/textures/terrainnormal_1024.jpg trunk/data/textures/terrainspec_1024.jpg trunk/data/textures/terrainsurface_1024.jpg Removed Paths: ------------- trunk/data/MediaFromOgre/AdvancedMaterials/nm_bk.png trunk/data/MediaFromOgre/AdvancedMaterials/nm_dn.png trunk/data/MediaFromOgre/AdvancedMaterials/nm_fr.png trunk/data/MediaFromOgre/AdvancedMaterials/nm_lf.png trunk/data/MediaFromOgre/AdvancedMaterials/nm_rt.png trunk/data/MediaFromOgre/AdvancedMaterials/nm_up.png trunk/data/materials/simpleSkybox.material trunk/data/skybox/skybox.zip Deleted: trunk/data/MediaFromOgre/AdvancedMaterials/nm_bk.png =================================================================== (Binary files differ) Deleted: trunk/data/MediaFromOgre/AdvancedMaterials/nm_dn.png =================================================================== (Binary files differ) Deleted: trunk/data/MediaFromOgre/AdvancedMaterials/nm_fr.png =================================================================== (Binary files differ) Deleted: trunk/data/MediaFromOgre/AdvancedMaterials/nm_lf.png =================================================================== (Binary files differ) Deleted: trunk/data/MediaFromOgre/AdvancedMaterials/nm_rt.png =================================================================== (Binary files differ) Deleted: trunk/data/MediaFromOgre/AdvancedMaterials/nm_up.png =================================================================== (Binary files differ) Modified: trunk/data/materials/advancedMaterials.program =================================================================== --- trunk/data/materials/advancedMaterials.program 2007-12-27 19:07:56 UTC (rev 880) +++ trunk/data/materials/advancedMaterials.program 2007-12-28 12:05:37 UTC (rev 881) @@ -35,34 +35,8 @@ } } -// A really basic ambient pass program, support for one texture coodinate set -vertex_program BasicVertexPrograms/AmbientOneTextureHLSL hlsl -{ - source Example_Basic.hlsl - entry_point ambientOneTexture_vp - target arbvp1 vp20 vs_1_1 - - default_params - { - param_named_auto worldViewProj worldviewproj_matrix - param_named_auto ambient ambient_light_colour - } -} -// A really basic ambient pass program, support for one texture coodinate set -vertex_program BasicVertexPrograms/AmbientOneTextureGLSL glsl -{ - source AmbientOneTexture.glsl - - default_params - { - param_named_auto ambient ambient_light_colour - } -} - vertex_program BasicVertexPrograms/AmbientOneTextureUnified unified { - delegate BasicVertexPrograms/AmbientOneTextureGLSL - delegate BasicVertexPrograms/AmbientOneTextureHLSL delegate BasicVertexPrograms/AmbientOneTextureCG } Added: trunk/data/materials/planet.cg =================================================================== --- trunk/data/materials/planet.cg (rev 0) +++ trunk/data/materials/planet.cg 2007-12-28 12:05:37 UTC (rev 881) @@ -0,0 +1,155 @@ +float3 expand( float3 v ) { return (v - 0.5) * 2; } + +struct vertexOutput { + float4 clipPos : POSITION; + float2 uv : TEXCOORD0; + float4 pos : TEXCOORD1; + float3 normal : TEXCOORD2; + float3 binormal : TEXCOORD3; + float3 tangent : TEXCOORD4; + float4 lightPos : TEXCOORD5; + float3 camPos : TEXCOORD6; + float3 tsLightDir : TEXCOORD7; +}; + +void atmos_vp( float4 objectPos : POSITION, + float3 normal : NORMAL, + out vertexOutput OUT, + uniform float4 lightPos, + uniform float3 camPos, + uniform float4x4 modelViewProjection ) +{ + float4 pos = objectPos; + pos.xyz += normal * 700.0; + OUT.clipPos = mul( modelViewProjection, pos ); + OUT.pos = pos; + OUT.normal = normal; + OUT.lightPos = lightPos; + OUT.camPos = camPos; +} + +float4 atmos_fp( in vertexOutput IN, + uniform sampler2D decalTexture : TEXUNIT0, + uniform float4 lightDiffuse ) : COLOR { + + float3 camDir = normalize( IN.camPos - IN.pos.xyz ); + float3 nN = normalize( IN.normal ); + float3 lightDir = normalize( IN.lightPos.xyz - ( IN.pos * IN.lightPos.w ) ); + + float rin = 15000; + float rout = 15000 + 700; + float atmLengthMax = 2.0 * rout * sqrt( 1- ( rin / rout ) ); + float atmDens = 0.8 / atmLengthMax; + float atmLength = 2.0 * ( rout * dot( camDir, nN ) ); + + float4 oColor; + + float dist = dot( camDir, camDir ); + float pSQR = - dot( camDir, IN.camPos ) / dist; + float qSQR = ( dot( IN.camPos, IN.camPos ) - rin * rin ) / dist; + dist = pSQR * pSQR - qSQR; + + oColor = atmDens * atmLength; + + if ( dist > 0f ){ + oColor -= atmDens * ( sqrt( 2 * dist ) )*1.5; + } else { + oColor *= atmLength / atmLengthMax / 1.5; + } + + return saturate( oColor ) * ( dot( lightDir, nN ) ); +} + +void cloud_vp( float4 objectPos : POSITION, + float2 uv : TEXCOORD0, + float3 normal : NORMAL, + out vertexOutput OUT, + uniform float4 lightPos, + uniform float3 camPos, + uniform float4x4 modelViewProjection ) +{ + OUT.clipPos = mul( modelViewProjection, objectPos ); + OUT.uv = uv; + OUT.normal = normal; + OUT.lightPos = lightPos; +} + +float4 cloud_fp( in vertexOutput IN, + uniform sampler2D decalTexture : TEXUNIT0, + uniform float4 lightDiffuse ) : COLOR { + + float3 nN = normalize( IN.normal ); + float3 lightDir = normalize( IN.lightPos.xyz - ( IN.pos * IN.lightPos.w ) ); + + float4 d = tex2D( decalTexture, IN.uv ); + return d * ( dot( lightDir, nN ) ); +} + +void main_vp( float4 objectPos : POSITION, + float2 uv : TEXCOORD0, + float3 normal : NORMAL, + float3 tangent : TANGENT, + out vertexOutput OUT, + uniform float4 lightPos, + uniform float3 camPos, + uniform float4x4 modelViewProjection) +{ + OUT.clipPos = mul( modelViewProjection, objectPos ); // position (view space) + OUT.uv = uv; + + OUT.pos = objectPos; + OUT.normal = normal; + OUT.tangent = tangent; + OUT.lightPos = lightPos; + OUT.camPos = camPos; + + float3 lightDir = lightPos.xyz - ( objectPos * lightPos.w ); + OUT.binormal = cross( tangent, normal ); + float3x3 rotation = float3x3( tangent, OUT.binormal, normal ); + OUT.tsLightDir = mul( rotation, lightDir ); +} + +float4 main_fp( vertexOutput IN, + uniform float exponent, + uniform float4 lightDiffuse, + uniform float4 lightSpecular, + uniform float4 lightAmbient, + uniform sampler2D decalTexture : TEXUNIT0, + uniform sampler2D normTexture : TEXUNIT1, + uniform sampler2D specTexture : TEXUNIT2, + uniform samplerCUBE normalCubeMap : TEXUNIT3 ) : COLOR { + + float3 lightDir = normalize( IN.lightPos.xyz - ( IN.pos * IN.lightPos.w ) ); + float3 camDir = normalize( IN.camPos - IN.pos.xyz ); + float3 halfAngle = normalize( lightDir ); + + float3 nN = normalize( IN.normal ); + float NdotL = dot( lightDir, nN ); + float NdotH = dot( halfAngle, nN ); + + //cg docs say using their lit function is the fastest + float4 Lit = lit( NdotL, NdotH, exponent ); + + float3 lightVec = expand( texCUBE( normalCubeMap, IN.tsLightDir ).xyz ); + + float3 bumpVec = expand( tex2D( normTexture, IN.uv ).xyz); + float4 d = tex2D( decalTexture, IN.uv ); + float4 s = tex2D( specTexture, IN.uv ); + +// float KrMin = 0.05; +// float Kr = 1.0; +// float FresExp = 5.0; + +// float3 nT = normalize(IN.tangent); +// float3 nB = normalize(IN.binormal); +// // float3 Nb = nN + (bumpVec.x * Tn + bumpVec.y * Bn ); +// float3 Nb = nN;// + ( 0.001 * nT + 0.1 * nB ); +// float vdn = dot( camDir, Nb ); + +// float fres = KrMin + (Kr-KrMin) * pow(1-abs(vdn),FresExp); +// return fres + lightSpecular * Lit.z; +// return float4(0.0, 0.0, 0.0, 0.0); + return lightDiffuse * Lit.y + lightSpecular * Lit.z * s + d * dot(bumpVec, lightVec); + // return lightDiffuse * Lit.y + lightSpecular * Lit.z * s + lightAmbient * d + d * saturate( dot(bumpVec, lightVec) ); +} + Added: trunk/data/materials/planet.material =================================================================== --- trunk/data/materials/planet.material (rev 0) +++ trunk/data/materials/planet.material 2007-12-28 12:05:37 UTC (rev 881) @@ -0,0 +1,215 @@ +vertex_program VertexPrograms/PlanetNormSpec cg +{ + source planet.cg + entry_point main_vp + profiles arbvp1 vp20 vs_1_1 + + default_params + { + param_named_auto modelViewProjection worldviewproj_matrix + param_named_auto lightPos light_position_object_space 0 + param_named_auto camPos camera_position_object_space + } +} + +fragment_program FragmentPrograms/PlanetNormSpec cg +{ + source planet.cg + entry_point main_fp + profiles arbfp1 fp20 ps_1_1 + default_params + { + } +} + +vertex_program VertexPrograms/PlanetCloud cg +{ + source planet.cg + entry_point cloud_vp + profiles arbvp1 vp20 vs_1_1 + + default_params + { + param_named_auto modelViewProjection worldviewproj_matrix + param_named_auto lightPos light_position_object_space 0 + param_named_auto camPos camera_position_object_space + } +} + +fragment_program FragmentPrograms/PlanetCloud cg +{ + source planet.cg + entry_point cloud_fp + profiles arbfp1 fp20 ps_1_1 + default_params + { + } +} + +vertex_program VertexPrograms/PlanetAtmosphere cg +{ + source planet.cg + entry_point atmos_vp + profiles arbvp1 vp20 vs_1_1 + + default_params + { + param_named_auto modelViewProjection worldviewproj_matrix + param_named_auto lightPos light_position_object_space 0 + param_named_auto camPos camera_position_object_space + } +} + +fragment_program FragmentPrograms/PlanetAtmosphere cg +{ + source planet.cg + entry_point atmos_fp + profiles arbfp1 fp20 ps_1_1 + default_params + { + } +} + +material PlanetNormSpec +{ + technique vpfp + { + scheme vpfp + pass + { + vertex_program_ref VertexPrograms/PlanetNormSpec + { + } + fragment_program_ref FragmentPrograms/PlanetNormSpec + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 + param_named lightAmbient float4 0.05 0.05 0.05 0.1 + param_named exponent float 10 + } + + texture_unit + { + texture_alias Image + tex_coord_set 0 + } + texture_unit + { + texture_alias ImageNormMap + tex_coord_set 1 + } + texture_unit + { + texture_alias ImageSpecMap + tex_coord_set 2 + } + texture_unit + { + cubic_texture nm.png combinedUVW + tex_coord_set 3 + tex_address_mode clamp + colour_op_ex dotproduct src_texture src_current + colour_op_multipass_fallback dest_colour zero + } + } + pass + { + depth_check on + depth_write off + scene_blend add + vertex_program_ref VertexPrograms/PlanetAtmosphere + { + } + fragment_program_ref FragmentPrograms/PlanetAtmosphere + { + param_named_auto lightDiffuse light_diffuse_colour 0 + } + } + } + technique fallback + { + scheme Default + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.900000 0.900000 0.900000 1.000000 + specular 0.900000 0.900000 0.900000 1.000000 + emissive 0.500000 0.500000 0.500000 1.000000 + texture_unit + { + texture_alias ImageFallback + tex_coord_set 0 + } + } + } +} + +material Planet/Cloud +{ + technique vpfp + { + scheme vpfp + pass + { + depth_check on + depth_write off + scene_blend add + vertex_program_ref VertexPrograms/PlanetCloud + { + } + fragment_program_ref FragmentPrograms/PlanetCloud + { + } + texture_unit + { + texture clouds_2500x1250.jpg + } + } + } + technique fallback + { + scheme Default + pass + { + specular 0.500000 0.500000 0.500000 0.5000000 + emissive 1.000000 1.000000 1.000000 1.000000 + depth_check on + depth_write off + scene_blend add + texture_unit + { + texture clouds_2500x1250.jpg + tex_coord_set 0 + } + } + } + +} + +material Planet : PlanetNormSpec +{ +// set_texture_alias Image terrainsurface_8192.bmp +// set_texture_alias ImageNormMap terrainnormal_8192.bmp +// set_texture_alias ImageSpecMap terrainspec_8192.bmp + + set_texture_alias Image terrainsurface_1024.jpg + set_texture_alias ImageNormMap terrainnormal_1024.jpg + set_texture_alias ImageSpecMap terrainspec_1024.jpg + set_texture_alias ImageFallback terrainsurface_1024.jpg + +// set_texture_alias Image terrainsurface.bmp +// set_texture_alias ImageNormMap terrainnormal.bmp +// set_texture_alias ImageSpecMap terrainspec.bmp + + +//http://www.oera.net/How2/TextureMaps.htm +// set_texture_alias Image EarthMap_2500x1250.jpg +// set_texture_alias ImageNormMap world.topo.200407Norm.png +// set_texture_alias ImageSpecMap EarthMask_2500x1250.jpg +// set_texture_alias ImageFallback EarthMapAtmos_2500x1250.jpg + +// set_texture_alias Image world.topo.200407.png +// set_texture_alias ImageNormMap texture world.topo.200407Norm.png +// set_texture_alias ImageSpecMap texture world.topo.200407Spec.png +} + Deleted: trunk/data/materials/simpleSkybox.material =================================================================== --- trunk/data/materials/simpleSkybox.material 2007-12-27 19:07:56 UTC (rev 880) +++ trunk/data/materials/simpleSkybox.material 2007-12-28 12:05:37 UTC (rev 881) @@ -1,56 +0,0 @@ -material OpenGate/SimpleSkyBox1 -{ - technique - { - pass - { - lighting off - depth_write off -// scene_blend add - - texture_unit - { - cubic_texture skybox1.png separateUV -// cubic_texture skybox1_4096.png separateUV -// cubic_texture skybox1_2048.png separateUV -// cubic_texture skybox1_1024.png separateUV -// cubic_texture skybox1_512.png separateUV - tex_address_mode clamp - } - } - } -} -material OpenGate/SimpleSkyBox2 -{ - technique - { - pass - { - lighting off - depth_write off - - texture_unit - { - cubic_texture skybox2.png separateUV - tex_address_mode clamp - } - } - } -} -material OpenGate/SimpleSkyBox3 -{ - technique - { - pass - { - lighting off - depth_write off - - texture_unit - { - cubic_texture skybox3.png separateUV - tex_address_mode clamp - } - } - } -} Modified: trunk/data/materials/simpleshield.material =================================================================== --- trunk/data/materials/simpleshield.material 2007-12-27 19:07:56 UTC (rev 880) +++ trunk/data/materials/simpleshield.material 2007-12-28 12:05:37 UTC (rev 881) @@ -12,7 +12,7 @@ pass { scene_blend alpha_blend - depth_check off + depth_check on lighting off fragment_program_ref shader_fp/simpleshield_cg { Modified: trunk/data/skybox/skybox.material =================================================================== --- trunk/data/skybox/skybox.material 2007-12-27 19:07:56 UTC (rev 880) +++ trunk/data/skybox/skybox.material 2007-12-28 12:05:37 UTC (rev 881) @@ -1,4 +1,4 @@ -material Examples/SpaceSkyBox +material OpenGate/SimpleSkyBox1 { technique { @@ -6,12 +6,53 @@ { lighting off depth_write off +// scene_blend add texture_unit { - cubic_texture stevecube.jpg separateUV + cubic_texture skybox1.png separateUV +// cubic_texture skybox1_4096.png separateUV +// cubic_texture skybox1_2048.png separateUV +// cubic_texture skybox1_1024.png separateUV +// cubic_texture skybox1_512.png separateUV tex_address_mode clamp } } } } + +material OpenGate/SimpleSkyBox2 +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture skybox2.png separateUV + tex_address_mode clamp + } + } + } +} + +material OpenGate/SimpleSkyBox3 +{ + technique + { + pass + { + lighting off + depth_write off + + texture_unit + { + cubic_texture skybox3.png separateUV + tex_address_mode clamp + } + } + } +} Deleted: trunk/data/skybox/skybox.zip =================================================================== (Binary files differ) Added: trunk/data/textures/clouds_2500x1250.jpg =================================================================== (Binary files differ) Property changes on: trunk/data/textures/clouds_2500x1250.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/nm_bk.png =================================================================== (Binary files differ) Property changes on: trunk/data/textures/nm_bk.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/nm_dn.png =================================================================== (Binary files differ) Property changes on: trunk/data/textures/nm_dn.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/nm_fr.png =================================================================== (Binary files differ) Property changes on: trunk/data/textures/nm_fr.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/nm_lf.png =================================================================== (Binary files differ) Property changes on: trunk/data/textures/nm_lf.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/nm_rt.png =================================================================== (Binary files differ) Property changes on: trunk/data/textures/nm_rt.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/nm_up.png =================================================================== (Binary files differ) Property changes on: trunk/data/textures/nm_up.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/terrainnormal_1024.jpg =================================================================== (Binary files differ) Property changes on: trunk/data/textures/terrainnormal_1024.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/terrainspec_1024.jpg =================================================================== (Binary files differ) Property changes on: trunk/data/textures/terrainspec_1024.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/textures/terrainsurface_1024.jpg =================================================================== (Binary files differ) Property changes on: trunk/data/textures/terrainsurface_1024.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/resources.cfg =================================================================== --- trunk/resources.cfg 2007-12-27 19:07:56 UTC (rev 880) +++ trunk/resources.cfg 2007-12-28 12:05:37 UTC (rev 881) @@ -15,6 +15,7 @@ FileSystem=./data/ships/quantar/storm FileSystem=./data/ships/tauseti/lady_kickstart FileSystem=./data/ships/squadrok/squid +FileSystem=./data/skybox FileSystem=./data/stations FileSystem=./data/materials FileSystem=./data/textures This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spo...@us...> - 2007-12-28 13:35:32
|
Revision: 882 http://opengate.svn.sourceforge.net/opengate/?rev=882&view=rev Author: spom_spom Date: 2007-12-28 05:35:37 -0800 (Fri, 28 Dec 2007) Log Message: ----------- cleaning planet destruction Modified Paths: -------------- trunk/data/materials/planet.material trunk/src/Planet.cpp trunk/src/Planet.h trunk/src/Sector.cpp trunk/src/UnDockedState.cpp Modified: trunk/data/materials/planet.material =================================================================== --- trunk/data/materials/planet.material 2007-12-28 12:05:37 UTC (rev 881) +++ trunk/data/materials/planet.material 2007-12-28 13:35:37 UTC (rev 882) @@ -7,7 +7,8 @@ default_params { param_named_auto modelViewProjection worldviewproj_matrix - param_named_auto lightPos light_position_object_space 0 + param_named lightPos float3 -50000.0 0.0 -40000.0 +// param_named_auto lightPos light_position_object_space 0 param_named_auto camPos camera_position_object_space } } @@ -31,7 +32,8 @@ default_params { param_named_auto modelViewProjection worldviewproj_matrix - param_named_auto lightPos light_position_object_space 0 + param_named lightPos float4 -50000.0 0.0 -40000.0 0.0 +// param_named_auto lightPos light_position_object_space 0 param_named_auto camPos camera_position_object_space } } @@ -55,7 +57,8 @@ default_params { param_named_auto modelViewProjection worldviewproj_matrix - param_named_auto lightPos light_position_object_space 0 + param_named lightPos float4 -50000.0 0.0 -40000.0 0.0 +// param_named_auto lightPos light_position_object_space 0 param_named_auto camPos camera_position_object_space } } @@ -178,8 +181,7 @@ scene_blend add texture_unit { - texture clouds_2500x1250.jpg - tex_coord_set 0 + texture clouds_1275.jpg } } } Modified: trunk/src/Planet.cpp =================================================================== --- trunk/src/Planet.cpp 2007-12-28 12:05:37 UTC (rev 881) +++ trunk/src/Planet.cpp 2007-12-28 13:35:37 UTC (rev 882) @@ -26,36 +26,80 @@ #include <OgreMeshManager.h> #include <OgreSubMesh.h> #include <OgreVector3.h> +#include <OgreLight.h> namespace OpenGate{ Planet::Planet( const std::string & name, Ogre::SceneManager * SceneMgr, const Ogre::Vector3 & relPos, Ogre::Real radius, int segments ) : name_( name ), sceneMgr_( SceneMgr ){ - createSphere_( name + "_Mesh", radius, segments, segments ); - - Ogre::Entity * planetEntity = sceneMgr_->createEntity( name + "_Entity", name + "_Mesh" ); - planetNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode(); - planetEntity->setMaterialName( "Planet" ); - planetNode_->attachObject( planetEntity ); - planetNode_->setPosition( relPos ); + + planetNode_ = NULL; + planetCloudNode_ = NULL; + planetCloudEntity_ = NULL; + planetEntity_ = NULL; + light_ = NULL; + + createSphere_( name + "/Mesh", radius, segments, segments ); + planetNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode(); + + planetEntity_ = sceneMgr_->createEntity( name + "/Entity", name + "/Mesh" ); + planetEntity_->setMaterialName( "Planet" ); + + planetNode_->attachObject( planetEntity_ ); + planetNode_->setPosition( relPos ); //planetNode_->pitch( Ogre::Degree(30) ); + + planetCloudNode_ = planetNode_->createChildSceneNode(); - Ogre::Entity * planetCloudEntity = planetEntity->clone( planetEntity->getName() + "_Cloud" ); - planetCloudEntity->setMaterialName( "Planet/Cloud" ); - planetCloudNode_ = planetNode_->createChildSceneNode(); - planetCloudNode_->attachObject( planetCloudEntity ); - planetCloudNode_->scale(1.015, 1.015, 1.015); + planetCloudEntity_ = planetEntity_->clone( planetEntity_->getName() + "/Cloud" ); + planetCloudEntity_->setMaterialName( "Planet/Cloud" ); + + planetCloudNode_->attachObject( planetCloudEntity_ ); + planetCloudNode_->scale(1.015, 1.015, 1.015); + + light_ = sceneMgr_->createLight( name + "/Light" ); + light_->setDiffuseColour( 0.1, 0.1, 0.1 ); + light_->setSpecularColour( 0.4, 0.4, 0.4 ); + planetNode_->attachObject( light_ ); + + this->lighting( false ); +} + +Planet::~Planet( ){ + if ( planetNode_ ) { + if ( light_ ){ + planetNode_->detachObject( light_ ); + sceneMgr_->destroyLight( light_->getName() ); + } + if ( planetCloudNode_ ){ + if ( planetCloudEntity_ ){ + planetCloudNode_->detachObject( planetCloudEntity_ ); + sceneMgr_->destroyEntity( planetCloudEntity_ ); + } + planetNode_->removeAndDestroyChild( planetCloudNode_->getName() ); + } + if ( planetEntity_ ){ + Ogre::MeshManager::getSingleton().remove( name_ + "/Mesh" ); + planetNode_->detachObject( planetEntity_ ); + sceneMgr_->destroyEntity( planetEntity_ ); + } + sceneMgr_->getRootSceneNode()->removeAndDestroyChild( planetNode_->getName() ); } +} void Planet::update( float elapsedTime ){ planetNode_->yaw( Ogre::Degree( 0.2 * elapsedTime ) ); planetCloudNode_->yaw( Ogre::Degree( 0.1 * elapsedTime ) ); } +void Planet::lighting( bool on ){ + light_->setVisible( on ); +} + void Planet::createSphere_( const std::string & strName, const float r, const int nRings, const int nSegments ){ Ogre::MeshPtr pSphere = Ogre::MeshManager::getSingleton().createManual(strName, - Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::SubMesh *pSphereVertex = pSphere->createSubMesh(); pSphere->sharedVertexData = new Ogre::VertexData(); Modified: trunk/src/Planet.h =================================================================== --- trunk/src/Planet.h 2007-12-28 12:05:37 UTC (rev 881) +++ trunk/src/Planet.h 2007-12-28 13:35:37 UTC (rev 882) @@ -29,6 +29,8 @@ public: Planet( const std::string & name, Ogre::SceneManager * SceneMgr, const Ogre::Vector3 & relPos, Ogre::Real radius, int segments ); + ~Planet( ); + void lighting( bool on ); void update( float elapsedTime ); protected: @@ -41,6 +43,9 @@ Ogre::SceneNode * planetNode_; Ogre::SceneNode * planetCloudNode_; + Ogre::Entity * planetCloudEntity_; + Ogre::Entity * planetEntity_; + Ogre::Light * light_; }; } // namespace OpenGate Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2007-12-28 12:05:37 UTC (rev 881) +++ trunk/src/Sector.cpp 2007-12-28 13:35:37 UTC (rev 882) @@ -126,6 +126,7 @@ if ( 1 ) { // planet_ = new Planet( "planet", sceneMgr_, Ogre::Vector3( 20000.0, 10000.0, 40000 ), 15000.0f, 32 ); planet_ = new Planet( "planet", sceneMgr_, Ogre::Vector3( 0000.0, 0000.0, 50000 ), 15000.0f, 64 ); + planet_->lighting( true ); } if ( !1 ) { @@ -184,6 +185,10 @@ // log_->info( "done: " ); } + sceneMgr_->destroyLight("MainLight" ); + + if ( planet_ ) { delete planet_; } + if ( planetNode_ ){ sceneMgr_->destroyManualObject( "Planet" ); sceneMgr_->getRootSceneNode()->removeAndDestroyChild( planetNode_->getName() ); Modified: trunk/src/UnDockedState.cpp =================================================================== --- trunk/src/UnDockedState.cpp 2007-12-28 12:05:37 UTC (rev 881) +++ trunk/src/UnDockedState.cpp 2007-12-28 13:35:37 UTC (rev 882) @@ -383,7 +383,7 @@ return false; } - myMSleep( (int)min( 0.0f, 1 - ( evt.timeSinceLastFrame ) ) ); + //myMSleep( (int)min( 0.0f, 1 - ( evt.timeSinceLastFrame ) ) ); return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <spo...@us...> - 2008-04-24 19:46:31
|
Revision: 885 http://opengate.svn.sourceforge.net/opengate/?rev=885&view=rev Author: spom_spom Date: 2008-04-24 12:45:36 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Add basic multi threading ai-manager, fixed several ugly bugs Modified Paths: -------------- trunk/ToDo trunk/data/materials/advancedMaterials.material trunk/data/materials/planet.material trunk/data/materials/simpleshield.material trunk/data/materials/station.material trunk/data/misc/testsector.xml trunk/src/Avatar.cpp trunk/src/Avatar.h trunk/src/GameStateManager.cpp trunk/src/GameStateManager.h trunk/src/InputManager.cpp trunk/src/KeyMap.cpp trunk/src/Makefile.am trunk/src/OpcodeWrapper.cpp trunk/src/OpcodeWrapper.h trunk/src/OpenALSoundManager.cpp trunk/src/Projectile.h trunk/src/ResourceManager.cpp trunk/src/ResourceManager.h trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObjects.cpp trunk/src/SectorObjects.h trunk/src/Station.cpp trunk/src/Station.h trunk/src/UnDockedState.cpp trunk/src/UnDockedState.h trunk/src/common.cpp trunk/src/common.h trunk/src/networkClient.cpp trunk/src/networkClient.h trunk/src/opengateclient.cpp Added Paths: ----------- trunk/data/textures/clouds_1275.jpg trunk/src/AiManager.cpp trunk/src/AiManager.h trunk/src/AiObject.cpp trunk/src/AiObject.h Modified: trunk/ToDo =================================================================== --- trunk/ToDo 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/ToDo 2008-04-24 19:45:36 UTC (rev 885) @@ -197,5 +197,7 @@ 9. Sonne 10. Plasma 11. Asche - - -Guns: Dazzler \ No newline at end of file + 12. Candle + 13. Torch,Flambeau + + -Guns: Dazzler Modified: trunk/data/materials/advancedMaterials.material =================================================================== --- trunk/data/materials/advancedMaterials.material 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/data/materials/advancedMaterials.material 2008-04-24 19:45:36 UTC (rev 885) @@ -184,58 +184,10 @@ } } +//material Sta/TS/Background : OpenGate/BumpMapping +//{ +// set_texture_alias Image TausetiStationBackgroundPlain.png +// set_texture_alias ImageBumpMap TausetiStationBackgroundBM.png +// set_texture_alias ImageFallback TausetiStationBackground.png +//} -material OpenGate/SingleTexture -{ - receive_shadows on - technique - { - pass - { -// ambient 0.500000 0.500000 0.500000 1.000000 -// diffuse 0.900000 0.900000 0.900000 1.000000 - emissive 0.500000 0.500000 0.500000 1.000000 - texture_unit - { - texture_alias Image - } - } - } -} - -material Sta/TS/Background : OpenGate/BumpMapping -{ - set_texture_alias Image TausetiStationBackgroundPlain.png - set_texture_alias ImageBumpMap TausetiStationBackgroundBM.png - set_texture_alias ImageFallback TausetiStationBackground.png -} - -material Sta/TS/Window : OpenGate/BumpMapping -{ - set_texture_alias Image TausetiStationWindow.png - set_texture_alias ImageBumpMap TausetiStationWindowBM.png - set_texture_alias ImageFallback TausetiStationWindow.png -} - -material Sta/TS/Plain : OpenGate/SingleTexture -{ - set_texture_alias Image TausetiStationBackgroundPlain.png -} - -material Flashlight/Red -{ - technique - { - pass - { - lighting on -// scene_blend alpha_blend - scene_blend add - emissive 1.000000 0.000000 0.000000 1.000000 - texture_unit - { - texture flare.png - } - } - } -} Modified: trunk/data/materials/planet.material =================================================================== --- trunk/data/materials/planet.material 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/data/materials/planet.material 2008-04-24 19:45:36 UTC (rev 885) @@ -213,5 +213,4 @@ // set_texture_alias Image world.topo.200407.png // set_texture_alias ImageNormMap texture world.topo.200407Norm.png // set_texture_alias ImageSpecMap texture world.topo.200407Spec.png -} - +} \ No newline at end of file Modified: trunk/data/materials/simpleshield.material =================================================================== --- trunk/data/materials/simpleshield.material 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/data/materials/simpleshield.material 2008-04-24 19:45:36 UTC (rev 885) @@ -16,8 +16,8 @@ lighting off fragment_program_ref shader_fp/simpleshield_cg { - param_named_auto customParamColour custom 0 - param_named_auto time time_0_x 1 + param_named_auto customParamColour custom 0 + // param_named_auto time time_0_x 1 } } } Modified: trunk/data/materials/station.material =================================================================== --- trunk/data/materials/station.material 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/data/materials/station.material 2008-04-24 19:45:36 UTC (rev 885) @@ -1,3 +1,101 @@ +vertex_program VertexPrograms/StationNormSpec cg +{ + source station.cg + entry_point main_vp + profiles arbvp1 vp20 vs_1_1 + + default_params + { + param_named_auto modelViewProjection worldviewproj_matrix + param_named_auto camPos camera_position_object_space + } +} + +fragment_program FragmentPrograms/StationNormSpec cg +{ + source station.cg + entry_point main_fp + profiles arbfp1 fp20 ps_1_1 + default_params + { + } +} + +material StationNormSpec +{ + technique vpfp + { + scheme vpfp + + pass + { + vertex_program_ref BasicVertexPrograms/AmbientOneTextureUnified + { + param_named_auto ambient ambient_light_colour + } + } + pass + { + scene_blend add + + iteration once_per_light + vertex_program_ref VertexPrograms/StationNormSpec + { + param_named_auto lightPos light_position_object_space 0 + } + fragment_program_ref FragmentPrograms/StationNormSpec + { + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 +// param_named lightDiffuse float4 0.6 0.6 0.6 1.0 +// param_named lightSpecular float4 0.2 0.2 0.2 1.0 + param_named lightAmbient float4 0.2 0.2 0.2 1.0 + param_named exponent float 1 + } + + texture_unit + { + texture_alias Image + tex_coord_set 0 + } + texture_unit + { + texture_alias ImageNormMap + tex_coord_set 1 + } + texture_unit + { + texture_alias ImageSpecMap + tex_coord_set 2 + } + texture_unit + { + cubic_texture nm.png combinedUVW + tex_coord_set 3 + tex_address_mode clamp + colour_op_ex dotproduct src_texture src_current + colour_op_multipass_fallback dest_colour zero + } + } + } + technique fallback + { + scheme Default + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.900000 0.900000 0.900000 1.000000 + specular 0.900000 0.900000 0.900000 1.000000 + emissive 0.500000 0.500000 0.500000 1.000000 + texture_unit + { + texture_alias ImageFallback + tex_coord_set 0 + } + } + } +} + material Station/Tube { receive_shadows on @@ -16,7 +114,6 @@ } } - material Station/DockPad { receive_shadows on @@ -52,3 +149,61 @@ } } } + +material OpenGate/SingleTexture +{ + receive_shadows on + technique + { + pass + { +// ambient 0.500000 0.500000 0.500000 1.000000 +// diffuse 0.900000 0.900000 0.900000 1.000000 + emissive 0.500000 0.500000 0.500000 1.000000 + texture_unit + { + texture_alias Image + } + } + } +} + +material Sta/TS/Background : StationNormSpec +{ + set_texture_alias Image TausetiStationBackgroundPlain.png + set_texture_alias ImageNormMap TausetiStationBackgroundBM.png + set_texture_alias ImageSpecMap TausetiStationBackground.png + set_texture_alias ImageFallback TausetiStationBackground.png +} + +material Sta/TS/Window : StationNormSpec +{ + set_texture_alias Image TausetiStationWindow.png + set_texture_alias ImageNormMap TausetiStationWindowBM.png + set_texture_alias ImageSpecMap TausetiStationWindow.png + set_texture_alias ImageFallback TausetiStationWindow.png +} + +material Sta/TS/Plain : OpenGate/SingleTexture +{ + set_texture_alias Image TausetiStationBackgroundPlain.png +} + +material Flashlight/Red +{ + technique + { + pass + { + lighting off + alpha_rejection greater_equal 128 +// scene_blend alpha_blend + scene_blend add + emissive 1.000000 0.000000 0.000000 1.000000 + texture_unit + { + texture flare.png + } + } + } +} Modified: trunk/data/misc/testsector.xml =================================================================== --- trunk/data/misc/testsector.xml 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/data/misc/testsector.xml 2008-04-24 19:45:36 UTC (rev 885) @@ -16,7 +16,7 @@ <!-- <size>desired size of this object</size> --> <!-- <scale>scaling factor for the ogre mesh</scale> --> <!-- <direction>desired front direction</direction> --> -<!-- <texture>desired front direction</texture> --> +<!-- <texture>desired texture overide defaults</texture> --> <!-- </sectorobject> --> <!-- <station> --> @@ -47,27 +47,10 @@ <scale>20, 20, 20</scale> <material>Asteroid</material> </sectorobject> + + + <!-- <sectorobject> --> -<!-- <name>ogreheadStation1</name> --> -<!-- <mesh>ogrehead</mesh> --> -<!-- <position>5000.0, 1000.0, 0.0</position> --> -<!-- <size>500, 500, 500</size> --> -<!-- </sectorobject> --> -<!-- <sectorobject> --> -<!-- <name>ogrehead1</name> --> -<!-- <mesh>ogrehead</mesh> --> -<!-- <position>100,0,0</position> --> -<!-- <size>10, 10, 10</size> --> -<!-- <direction>1,0,0</direction> --> -<!-- </sectorobject> --> -<!-- <sectorobject> --> -<!-- <name>ogrehead2</name> --> -<!-- <mesh>ogrehead</mesh> --> -<!-- <position>-100.0, 0, 0.0</position> --> -<!-- <size>10, 10, 10</size> --> -<!-- <direction>1,0,0</direction> --> -<!-- </sectorobject> --> -<!-- <sectorobject> --> <!-- <name>astro6</name> --> <!-- <mesh>ice_oval_6</mesh> --> <!-- <position>0.0, -10, 0.0</position> --> Added: trunk/data/textures/clouds_1275.jpg =================================================================== (Binary files differ) Property changes on: trunk/data/textures/clouds_1275.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/src/AiManager.cpp =================================================================== --- trunk/src/AiManager.cpp (rev 0) +++ trunk/src/AiManager.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -0,0 +1,160 @@ +/*************************************************************************** + * Copyright (C) 2008 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "AiManager.h" +#include "AiObject.h" + +#include "common.h" +#include "ResourceManager.h" +#include "SectorObjects.h" +#include "Sector.h" +#include "UnDockedState.h" +#include "GameStateManager.h" +#include "Avatar.h" + +#include <iostream> +#include <iterator> +#include <set> + +#include <boost/thread.hpp> + +namespace OpenGate{ + +AiManager::AiManager( ResourceManager * resources ) : resources_( resources ){ + eraseAiObjectCB_ = new AiManagerCB( this, &AiManager::eraseAiObject ); + aiID_ = 1; +} + +AiManager::~AiManager( ){ + //std::cout << "AiManager::~AiManager( )" << std::endl; + killall(); + //std::cout << "AiManager::~AiManager( )" << aiObjects_.size() << std::endl; + + for_each( aiObjectHeap_.begin(), aiObjectHeap_.end(), deletePtr() ); + delete eraseAiObjectCB_; +} + +void AiManager::killall(){ + //std::cout << "AiManager::killall():" << aiObjects_.size() << std::endl; + //** ugly, kill direkt auf aiObjects_ ist schlecht weil sich die ai selbst gleichzeitig austragen + std::set< AiObject * > toKillTmpSet( aiObjects_ ); + for_each( toKillTmpSet.begin(), toKillTmpSet.end(), std::mem_fun( &AiObject::kill ) ); + aiThreads_.join_all(); +} + +class RunAiObject{ +public: + RunAiObject( AiObject * ai, AiManagerCB * endThreadCallback = NULL ) + : ai_( ai ), endThreadCallback_( endThreadCallback ) { + ai_->incReferenceCounter(); + } + RunAiObject( const RunAiObject & aio ) + : ai_( aio.ai() ), endThreadCallback_( aio.endThreadCallback() ) { + ai_->incReferenceCounter(); + } + ~RunAiObject( ){ + ai_->decReferenceCounter(); + //std::cout << "endThreadCallback_ " << ai_->referenceCounter() << std::endl; + if ( ai_->referenceCounter() == 0 && endThreadCallback_ ) { + (*endThreadCallback_)( ai_ ); + } + } + void operator()(){ ai_->run(); } + + AiObject * ai() const { return ai_; } + AiManagerCB * endThreadCallback() const { return endThreadCallback_; } + +protected: + AiObject * ai_; + AiManagerCB * endThreadCallback_; +}; + +void AiManager::cmd( const std::vector < std::string > & argv ){ + std::cout << "AiManager::cmd " << std::endl; + std::copy( argv.begin(), argv.end(), std::ostream_iterator< std::string >( std::cout, " " ) ); + std::cout << std::endl; + + AiObject * ai = spawnAi( ); +} + +AiObject * AiManager::spawnAi( ){ + std::string name( "aiMan-" + resources_->avatar->name() ); + AiObject * ai = createAiObject( name ); + + SectorObjectMoveableLocal *obj = NULL; + if ( resources_ ){ + if ( resources_->gameStateRoot->activeState( )->name() == "UnDockedState" ){ + + obj = dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() )->sector()-> + createMoveableObjectLocal( ai->name(), + resources_->network->userID(), ai->id(), + *VesselManager::getSingleton().vessel( "apteryx" ) ); + + std::cout << "Create " << obj->name() << " " << obj->thrust() << " " << obj->speed() << std::endl; + } else { + std::cout << "spawn only in undockedState" << std::endl; + } + } + ai->setSectorObject( obj ); + Ogre::Real xmin = -100.0, xmax = 200.0; + Ogre::Real ymin = -100.0, ymax = 200.0; + Ogre::Real zmin = -1000.0, zmax = -2000.0; + + obj->mainNode()->setPosition( Ogre::Math::RangeRandom( xmin, xmax ), + Ogre::Math::RangeRandom( ymin, ymax ), + Ogre::Math::RangeRandom( zmin, zmax ) ); + + return ai; +} + +AiObject * AiManager::createAiObject( const std::string & name ){ + AiObject *ai; + if ( aiObjectHeap_.size() ) { + ai = aiObjectHeap_.back(); + ai->reset(); + aiObjectHeap_.pop_back(); + } else { + ai = new AiObject( this->aiID() ); + aiID_ ++; + } + aiObjects_.insert( ai ); + ai->setName( name + "-" + toStr( ai->id() ) ); + std::cout << " creating starting:" << ai->name() << std::endl; + RunAiObject aio( ai, eraseAiObjectCB_ ); + aiThreads_.create_thread( aio ); + return ai; +} + +void AiManager::eraseAiObject( AiObject * ai ){ + boost::mutex::scoped_lock lock( eraseMutex_ ); + + SectorObjectMoveableLocal *obj = ai->sectorObject( ); + if ( obj ){ __D( obj->name() ) + obj->destroy(); + } + aiObjects_.erase( ai ); +} + +void AiManager::recycle( AiObject * ai ){ + aiObjectHeap_.push_back( ai ); +} + +} // namespace OpenGate{ + Added: trunk/src/AiManager.h =================================================================== --- trunk/src/AiManager.h (rev 0) +++ trunk/src/AiManager.h 2008-04-24 19:45:36 UTC (rev 885) @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (C) 2008 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _OPENGATE_AIMANAGER__H +#define _OPENGATE_AIMANAGER__H + +#include <string> +#include <vector> +#include <set> +#include <queue> +#include <iostream> + +#include <boost/thread.hpp> + +namespace OpenGate{ + +class ResourceManager; +class SectorObjectMoveableLocal; +class AiManager; +class AiObject; + +template < class Class, typename ReturnType, typename Parameter > class SingularCallBack{ +public: + typedef ReturnType ( Class::*Method )( Parameter ); + SingularCallBack( Class * class_instance, Method method ) : class_instance_( class_instance ), method_( method ) { } + + ReturnType operator()( Parameter parameter ) { return ( class_instance_->*method_ )( parameter ); } + ReturnType execute( Parameter parameter ){ return operator()( parameter ); } +private: + Class * class_instance_; + Method method_; +}; + +typedef SingularCallBack< AiManager, void, AiObject * > AiManagerCB; + +//! Manager for artificial intelligence (ai) objects. +/*! Manager for artificial intelligence (ai) objects. Communication with ai i.e. bots with this manager. Each ai runs in his own thread. */ +class AiManager{ +public: + AiManager( ResourceManager * resources = NULL ); + + ~AiManager( ); + + void cmd( const std::vector < std::string > & argv ); + + AiObject * spawnAi( ); + + /*! Create new ai an put to set of active ai, instance is taken from heap if available else create new*/ + AiObject * createAiObject( const std::string & name ); + + /*! Erase ai from set of active ai's. The instance will not destroyd but put on a heap for the next usage*/ + void eraseAiObject( AiObject * ai ); + + /*! The ai is dead and can be recycled. */ + void recycle( AiObject * ai ); + + /*! Check for any active ai's. */ + inline bool hasActiveObjects() const { return ( aiObjects_.size() > 0 ); } + + /*!Send kill signal to all ai and join all threads. Mainly used for shutdown the manager.*/ + void killall(); + + /*! ID of the last created ai */ + uint aiID() const { return aiID_; } + +protected: + ResourceManager * resources_; + + std::set< AiObject * > aiObjects_; + std::deque< AiObject * > aiObjectHeap_; + + //! ID counter for the ai + uint aiID_; + + boost::thread_group aiThreads_; + AiManagerCB * eraseAiObjectCB_; + boost::mutex eraseMutex_; + +}; + +} // namespace OpenGate{ + + +#endif // _OPENGATE_AIMANAGER__H Added: trunk/src/AiObject.cpp =================================================================== --- trunk/src/AiObject.cpp (rev 0) +++ trunk/src/AiObject.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2008 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "AiObject.h" + +#include "SectorObjects.h" + +#include "common.h" +#include <iostream> + +namespace OpenGate{ + +AiObject::AiObject( uint id ) : id_( id ), sectorObject_( NULL ){ + reset(); +} + +AiObject::~AiObject(){ +} + +//** protected copy constructor +AiObject::AiObject( const AiObject & ai ){ + copy_( ai ); +} + +//** protected assigenment operator +AiObject & AiObject::operator = ( const AiObject & ai ){ + if ( this != &ai ){ + copy_( ai ); + } return *this; +} + +void AiObject::copy_( const AiObject & ai ){ + +} + +void AiObject::reset( ){ + livetime_ = 0.0; + refCounter_ = 0; + name_ = "unknown"; + isAlive_ = true; + die_ = false; +} + +void AiObject::run(){ __D( name_ ) + isAlive_ = true; + while ( isAlive_ ){ + myMSleep( 300 ); + livetime_ += 300.0; + if ( livetime_ > 5000 || die_ ) isAlive_ = false; + } +} + +void AiObject::setSectorObject( SectorObjectMoveableLocal * obj ){ + sectorObject_ = obj; + if ( obj ){ + sectorObject_->setControler( this ); + } +} + +} // namespace OpenGate{ + Added: trunk/src/AiObject.h =================================================================== --- trunk/src/AiObject.h (rev 0) +++ trunk/src/AiObject.h 2008-04-24 19:45:36 UTC (rev 885) @@ -0,0 +1,106 @@ +/*************************************************************************** + * Copyright (C) 2008 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _OPENGATE_AIOBJECT__H +#define _OPENGATE_AIOBJECT__H + +#include <string> +#include <vector> +#include <set> +#include <queue> +#include <iostream> + +#include <boost/thread.hpp> + +namespace OpenGate{ + +class ResourceManager; +class SectorObjectMoveableLocal; +class AiManager; + +class AiObject{ +public: + AiObject( uint id ); + + ~AiObject( ); + + /*! Functor to the livecyle */ + void operator()(){ return run( ); } + + /*! Main livecyle */ + virtual void run(); + + /*! Set the instance which is controled by this ai */ + void setSectorObject( SectorObjectMoveableLocal * obj ); + + /*! Get the instance which is controled by this ai */ + SectorObjectMoveableLocal * sectorObject( ){ return sectorObject_; } + + double livetime( ) const { return livetime_; } + + bool isAlive() const { return isAlive_; } + + void kill() { die_ = true; } + + void reset(); + + void setName ( const std::string & name ){ name_ = name; } + + std::string name() const { return name_; } + + uint id() const { return id_;} + + //! reference counting used for threading, prob. better using smart pointer + uint referenceCounter() const { return refCounter_; } + void incReferenceCounter() { refCounter_ ++; } + void decReferenceCounter() { refCounter_ --; } +protected: + AiObject( const AiObject & ai ); + + AiObject & operator = ( const AiObject & ai ); + + void copy_( const AiObject & ai ); + + //! the graphical representation + SectorObjectMoveableLocal * sectorObject_; + + //! holds objects live status + bool isAlive_; + + //! prepare object to die + bool die_; + + //! holds objects livetime + double livetime_; + + //! objects name + std::string name_; + + //! unique id + uint id_; + + //! reference counter for threadholder + uint refCounter_; +}; + +} // namespace OpenGate{ + + +#endif // _OPENGATE_AIMANAGER__H Modified: trunk/src/Avatar.cpp =================================================================== --- trunk/src/Avatar.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/Avatar.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -23,7 +23,7 @@ namespace OpenGate{ -Avatar::Avatar( const std::string & name, int ID ): name_( name ), id_( ID ) { +Avatar::Avatar( const std::string & name, Uint32 ID ): name_( name ), id_( ID ) { cargoHold_ = 0; } Modified: trunk/src/Avatar.h =================================================================== --- trunk/src/Avatar.h 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/Avatar.h 2008-04-24 19:45:36 UTC (rev 885) @@ -21,6 +21,8 @@ #ifndef _OPENGATE_AVATAR__H #define _OPENGATE_AVATAR__H +#include "common.h" + #include <string> #include <list> #include <vector> @@ -35,15 +37,16 @@ /*! */ class Avatar{ public: - Avatar( const std::string & name, int id ); + Avatar( const std::string & name, Uint32 id ); ~Avatar( ); std::string name() const { return name_; } - int userID() const { return id_; } + Uint32 userID() const { return id_; } void setVessel( Vessel & vessel ); + Vessel * vessel() { return vessel_; } void addCargoToFloor( const std::vector < Entity * > & item ); @@ -59,12 +62,12 @@ protected: std::string name_; - int id_; + Uint32 id_; Vessel * vessel_; - int maxCargoHold_; - int cargoHold_; + Uint16 maxCargoHold_; + Uint16 cargoHold_; std::list< std::deque < Entity * > > floorCargo_; }; Modified: trunk/src/GameStateManager.cpp =================================================================== --- trunk/src/GameStateManager.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/GameStateManager.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -31,13 +31,16 @@ #include <OgreMesh.h> #include <OgreMeshManager.h> #include <OgreMaterialManager.h> + #include "LogManager.h" #include "Console.h" #include "Avatar.h" #include "Sector.h" #include "InputManager.h" +#include "AiManager.h" #include "VesselManager.h" #include "OpenALSoundManager.h" +#include "OpcodeWrapper.h" #include "UnDockedState.h" #include "ConfigDialog.h" #include "EntityManager.h" @@ -123,6 +126,11 @@ states_.pop_back(); } + if ( resources_.aiManager ) { + log_->info( "Shutdown ai manager." ); + delete resources_.aiManager; + resources_.aiManager = NULL; + } if ( resources_.console ){ log_->info( "Shutdown console." ); delete resources_.console; @@ -153,7 +161,7 @@ delete resources_.inputManager; resources_.inputManager = NULL; } - + log_->info( "Shutdown renderWindow." ); if ( resources_.renderWindow ) delete resources_.renderWindow; log_->info( "Shutdown ogreRoot." ); @@ -408,8 +416,11 @@ "initialise commodity manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), std::string >( &GameStateManager::initialiseEquipmentManager, - "initialise equipment manager" ) ); + "initialise equipment manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), + std::string >( &GameStateManager::initialiseAiManager, + "initialise ai manager" ) ); + loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), std::string >( &GameStateManager::createAvatar, "create avatar" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), @@ -456,11 +467,12 @@ resources_.ogreRoot->addFrameListener( resources_.console ); LogManager::getSingleton().setConsole( resources_.console ); - resources_.console->addCommand( "/q", &GameStateManager::CMD_shutdown, "Shutting down the client. Shortcut for /quit" ); - resources_.console->addCommand( "/quit", &GameStateManager::CMD_shutdown, "Shutting down the client" ); - resources_.console->addCommand( "/help", &GameStateManager::CMD_printHelp,"Show this help" ); - resources_.console->addCommand( "/time", &GameStateManager::CMD_printTime,"Show current system time" ); - resources_.console->addCommand( "/ai", &GameStateManager::CMD_spawnAi, "[name] Spawn ai subject. /ai help show all available ships." ); + resources_.console->addCommand( "/q", &GameStateManager::CMD_shutdown, "Shutting down the client. Shortcut for /quit" ); + resources_.console->addCommand( "/quit", &GameStateManager::CMD_shutdown, "Shutting down the client" ); + resources_.console->addCommand( "/help", &GameStateManager::CMD_printHelp,"Show this help" ); + resources_.console->addCommand( "/time", &GameStateManager::CMD_printTime,"Show current system time" ); + resources_.console->addCommand( "/spawn", &GameStateManager::CMD_spawnAi, "[name] Spawn ai subject. /spawn help show all available ships." ); + resources_.console->addCommand( "/ai", &GameStateManager::CMD_ai, " [command] interact with aimanager. /ai help show all commands." ); return true; } @@ -476,6 +488,16 @@ return true; } +bool GameStateManager::initialiseAiManager(){ + resources_.aiManager = new AiManager( &resources_ ); + return true; +} + +bool GameStateManager::initialiseCollisionManager(){ + resources_.collisionManager = new OpcodeCollisionDetection( &resources_ ); + return true; +} + bool GameStateManager::initialiseVesselManager(){ vesselManager_ = new VesselManager( ); vesselManager_->load( resources_.resourcePaths(), "ships" ); @@ -614,6 +636,10 @@ resources_.console->print( asctime( time ) ); } +void GameStateManager::CMD_ai( const std::vector < std::string > & argv ){ + resources_.aiManager->cmd( argv ); +} + void GameStateManager::CMD_spawnAi( const std::vector < std::string > & argv ){ std::string aiName = "Squid"; if ( argv.size() > 1 ){ Modified: trunk/src/GameStateManager.h =================================================================== --- trunk/src/GameStateManager.h 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/GameStateManager.h 2008-04-24 19:45:36 UTC (rev 885) @@ -68,7 +68,7 @@ bool initialiseOgreResources( ); bool initialiseCEGUIEngine( ); bool initialiseInputManager( ); - + bool initialiseConsole(); //** load id, rank matrix etc. @@ -77,12 +77,13 @@ bool initialiseVesselManager(); bool initialiseCommodityManager(); bool initialiseEquipmentManager(); + bool initialiseAiManager(); + bool initialiseCollisionManager(); bool createAvatar(); bool createConfigDialog(); bool createDockedState(); bool createUnDockedState(); - ConfigDialog * configDialog() { return configDialog_; } void switchConfigDialog( ); @@ -102,6 +103,9 @@ /*! Find a game state by name. \Remarks returns 0 on failure. */ virtual GameState * findByName( const std::string & stateName); + /*! Get the active gamestate. */ + GameState * activeState( ) { return stateStack_.back(); } + /*! Change to a game state. This replaces the current game state with a new game state. The current game state ends before the new begins. */ void changeGameState( GameState * state ); @@ -115,12 +119,11 @@ void CMD_printHelp( const std::vector < std::string > & argv ); void CMD_printTime( const std::vector < std::string > & argv ); void CMD_spawnAi( const std::vector < std::string > & argv ); + void CMD_ai( const std::vector < std::string > & argv ); /*! This is a special case function to cause a shutdown. */ void shutdown( ); -// bool enterDockedStateHack_; - std::vector< std::pair< bool (GameStateManager::*)( ), std::string > > * pLoadResourcesVector(){ return &loadResourcesVector_; } Modified: trunk/src/InputManager.cpp =================================================================== --- trunk/src/InputManager.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/InputManager.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -84,7 +84,8 @@ keyboard_->setEventCallback( this ); #ifndef WIN32 - if ( inputSystem_->numJoySticks() > 0 ) { + //** temporaly disabled + //if ( inputSystem_->numJoySticks() > 0 ) { // mJoysticks.resize( inputSystem_->numJoysticks() ); @@ -94,9 +95,9 @@ // (*itJoystick) = static_cast<OIS::JoyStick*>( inputSystem_->createInputObject( OIS::OISJoyStick, true ) ); // (*itJoystick)->setEventCallback( this ); // } - joyStick_ = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject( OIS::OISJoyStick, true)); - joyStick_->setEventCallback( this ); - } +// joyStick_ = static_cast<OIS::JoyStick*>(inputSystem_->createInputObject( OIS::OISJoyStick, true)); +// joyStick_->setEventCallback( this ); +// } #endif } } Modified: trunk/src/KeyMap.cpp =================================================================== --- trunk/src/KeyMap.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/KeyMap.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -81,6 +81,7 @@ unDockedActionMap_[ keycode( OIS::KC_F6 ) ] = &UnDockedState::keyActionAvatarSwitchDuelistTarget_DEV; unDockedActionMap_[ keycode( OIS::KC_F4 ) ] = &UnDockedState::keyActionAvatarChangeDockedState_DEV; unDockedActionMap_[ keycode( OIS::KC_F8 ) ] = &UnDockedState::keyActionAvatarSelfDestruct_DEV; + unDockedActionMap_[ keycode( OIS::KC_F7 ) ] = &UnDockedState::keyActionSpawnAi_DEV; } bool(UnDockedState::*KeyMap::unDockedKeyAction( const OIS::KeyEvent & e ))(bool) { Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/Makefile.am 2008-04-24 19:45:36 UTC (rev 885) @@ -1,6 +1,7 @@ bin_PROGRAMS = \ opengateclient \ - opengateserver + opengateserver \ + testaimanager opengateclient_SOURCES = \ opengateclient.cpp \ @@ -18,6 +19,10 @@ tinyxml/tinyxmlparser.cpp \ Avatar.h \ Avatar.cpp \ + AiManager.h \ + AiManager.cpp \ + AiObject.h \ + AiObject.cpp \ BaseDialog.h \ BaseDialog.cpp \ ConfigDialog.h \ @@ -108,6 +113,94 @@ opengateserver_CXXFLAGS = \ $(ogreopcode_CFLAGS) +testaimanager_SOURCES = \ + testaimanager.cpp \ + commonWithOgre.h \ + commonWithOgre.cpp \ + networkProtocol.h \ + networkProtocol.cpp \ + networkClient.h \ + networkClient.cpp \ + tinyxml/tinyxml.h \ + tinyxml/tinyxml.cpp \ + tinyxml/tinyxmlerror.cpp \ + tinyxml/tinyxmlparser.cpp \ + Avatar.h \ + Avatar.cpp \ + AiManager.h \ + AiManager.cpp \ + AiObject.h \ + AiObject.cpp \ + BaseDialog.h \ + BaseDialog.cpp \ + ConfigDialog.h \ + ConfigDialog.cpp \ + Console.h \ + Console.cpp \ + DockedState.h \ + DockedState.cpp \ + Entity.h \ + Entity.cpp \ + EntityManager.h \ + EntityManager.cpp \ + GameState.h \ + GameState.cpp \ + GameStateManager.h \ + GameStateManager.cpp \ + InputManager.h \ + InputManager.cpp \ + InitState.h \ + InitState.cpp \ + KeyMap.h \ + KeyMap.cpp \ + LogManager.h \ + LogManager.cpp \ + LogManagerBase.h \ + LogManagerBase.cpp \ + MarketDialog.h \ + MarketDialog.cpp \ + OpcodeWrapper.h \ + OpcodeWrapper.cpp \ + OpenALSoundManager.h \ + OpenALSoundManager.cpp \ + Planet.h \ + Planet.cpp \ + Projectile.h \ + Projectile.cpp \ + ResourceManager.h \ + ResourceManager.cpp \ + Sector.h \ + Sector.cpp \ + SectorObjects.h \ + SectorObjects.cpp \ + ShipConfigDialog.h \ + ShipConfigDialog.cpp \ + Station.h \ + Station.cpp \ + UnDockedState.cpp \ + UnDockedState.h \ + Vessel.h \ + Vessel.cpp \ + VesselManager.h \ + VesselManager.cpp \ + metaserver.h \ + metaserver.cpp \ + common.h \ + common.cpp + +testaimanager_LDFLAGS = $(OGRE_LIBS) \ + $(CEGUI_LIBS) \ + $(CEGUIOGRE_LIBS) \ + $(freealut_LIBS) \ + $(vorbisfile_LIBS) \ + $(OIS_LIBS) \ + $(ogreopcode_LIBS) + +testaimanager_CXXFLAGS = \ + $(OGRE_CFLAGS) \ + $(CEGUI_CFLAGS) \ + $(ogreopcode_CFLAGS) + #testopenalmanager_SOURCES = \ # testopenalmanager.cpp \ # common.h \ Modified: trunk/src/OpcodeWrapper.cpp =================================================================== --- trunk/src/OpcodeWrapper.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/OpcodeWrapper.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -21,6 +21,7 @@ #include "OpcodeWrapper.h" #include "SectorObjects.h" +#include "ResourceManager.h" #include "Projectile.h" #include <OgreOpcode.h> @@ -32,126 +33,148 @@ template<> OpcodeCollisionDetection * Ogre::Singleton< OpcodeCollisionDetection >::ms_Singleton = 0; +OpcodeCollisionDetection::OpcodeCollisionDetection( ResourceManager * resources ){ + std::cout << "OpcodeCollisionDetection::OpcodeCollisionDetection implement this " << std::endl; +} + OpcodeCollisionDetection::OpcodeCollisionDetection( Ogre::SceneManager * sceneMgr ){ - new OgreOpcode::CollisionManager( sceneMgr ); + active_ = true; + if ( active_ ){ + collisionManager_ = new OgreOpcode::CollisionManager( sceneMgr ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollClass( "SectorObject" ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollClass( "Station" ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollClass( "DockPad" ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollClass( "Bullet" ); + collisionManager_->addCollClass( "SectorObject" ); + collisionManager_->addCollClass( "Station" ); + collisionManager_->addCollClass( "DockPad" ); + collisionManager_->addCollClass( "Bullet" ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "Bullet", "Bullet", OgreOpcode::COLLTYPE_IGNORE ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "SectorObject", "Bullet", OgreOpcode::COLLTYPE_EXACT ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "Station", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "Station", "DockPad", OgreOpcode::COLLTYPE_IGNORE ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "Station", "Bullet", OgreOpcode::COLLTYPE_EXACT ); - OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "DockPad", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); -// OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_CONTACT ); - // OgreOpcode::CollisionManager::getSingletonPtr()->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_QUICK ); - collideInSectorContext_ = OgreOpcode::CollisionManager::getSingletonPtr()->getDefaultContext(); + collisionManager_->addCollType( "Bullet", "Bullet", OgreOpcode::COLLTYPE_IGNORE ); + collisionManager_->addCollType( "SectorObject", "Bullet", OgreOpcode::COLLTYPE_EXACT ); + collisionManager_->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); + collisionManager_->addCollType( "Station", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); + collisionManager_->addCollType( "Station", "DockPad", OgreOpcode::COLLTYPE_IGNORE ); + collisionManager_->addCollType( "Station", "Bullet", OgreOpcode::COLLTYPE_EXACT ); + collisionManager_->addCollType( "DockPad", "SectorObject", OgreOpcode::COLLTYPE_EXACT ); + + // collisionManager_->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_CONTACT ); + // collisionManager_->addCollType( "SectorObject", "SectorObject", OgreOpcode::COLLTYPE_QUICK ); + + collideInSectorContext_ = collisionManager_->getDefaultContext(); + } else { + std::cout << "OpcodeCollisionDetection deactivated" << std::endl; + } } OpcodeCollisionDetection::~OpcodeCollisionDetection(){ - delete OgreOpcode::CollisionManager::getSingletonPtr(); + delete collisionManager_; } bool OpcodeCollisionDetection::update( Ogre::Real elapsedTime ){ - collideInSectorContext_->collide( elapsedTime ); + if ( active_ ){ + collideInSectorContext_->collide( elapsedTime ); - OgreOpcode::CollisionReporter report( collideInSectorContext_->getCollisionReport() ); + OgreOpcode::CollisionReporter report( collideInSectorContext_->getCollisionReport() ); - int nCollids = report.getNumCollisions(); - if ( nCollids > 0 ){ - // std::cout << "Collisions: " << nCollids << std::endl; + int nCollids = report.getNumCollisions(); + if ( nCollids > 0 ){ + // std::cout << "Collisions: " << nCollids << std::endl; - OgreOpcode::CollisionPair **collisionReport; - report.getAllCollisions( collisionReport ); + OgreOpcode::CollisionPair **collisionReport; + report.getAllCollisions( collisionReport ); - for ( int i = 0; i < nCollids; i ++ ){ - OgreOpcode::CollisionObject* col1 = collisionReport[ i ]->this_object; - OgreOpcode::CollisionObject* col2 = collisionReport[ i ]->other_object; + for ( int i = 0; i < nCollids; i ++ ){ + OgreOpcode::CollisionObject* col1 = collisionReport[ i ]->this_object; + OgreOpcode::CollisionObject* col2 = collisionReport[ i ]->other_object; - static_cast< BaseObject * >( col1->getClientData() )->collide( static_cast< BaseObject * >( col2->getClientData() ) ); - static_cast< BaseObject * >( col2->getClientData() )->collide( static_cast< BaseObject * >( col1->getClientData() ) ); - } + static_cast< BaseObject * >( col1->getClientData() )->collide( static_cast< BaseObject * >( + col2->getClientData() ) ); + static_cast< BaseObject * >( col2->getClientData() )->collide( static_cast< BaseObject * >( + col1->getClientData() ) ); + } // std::cout << "CollisionContext attached objects: " + Ogre::StringConverter::toString(collideInSectorContext_->getAttachedObjectCount()) << std::endl; // std::cout << "CollisionContext owned objects: " + Ogre::StringConverter::toString(collideInSectorContext_->getOwnedObjectCount()) << std::endl; -// std::cout << "CollisionManager shapes: " + Ogre::StringConverter::toString(OgreOpcode::CollisionManager::getSingletonPtr()->getShapeCount())<< std::endl; +// std::cout << "CollisionManager shapes: " + Ogre::StringConverter::toString(collisionManager_->getShapeCount())<< std::endl; - } + } // if ncols + } return true; } OgreOpcode::CollisionObject * OpcodeCollisionDetection::createObject( Ogre::Entity * entity, BaseObject * obj, const std::string & collClass ){ + OgreOpcode::CollisionObject * collObj = NULL; + + if ( active_ ){ + OgreOpcode::EntityCollisionShape * collShape = collisionManager_ + ->createEntityCollisionShape( obj->name() + "/CollShape" ); + collShape->load( entity ); - OgreOpcode::EntityCollisionShape * collShape = OgreOpcode::CollisionManager::getSingletonPtr() - ->createEntityCollisionShape( obj->name() + "/CollShape" ); - collShape->load( entity ); + collObj = collideInSectorContext_->createObject( obj->name() + "/CollObj" ); + collObj->setCollClass( collisionManager_->queryCollClass( collClass ) ); + collObj->setShape( collShape ); - OgreOpcode::CollisionObject * collObj = collideInSectorContext_->createObject( obj->name() + "/CollObj" ); - collObj->setCollClass( OgreOpcode::CollisionManager::getSingletonPtr()->queryCollClass( collClass ) ); - collObj->setShape( collShape ); + collideInSectorContext_->addObject( collObj ); - collideInSectorContext_->addObject( collObj ); - - collObj->setClientData( obj ); + collObj->setClientData( obj ); + } return collObj; } OgreOpcode::CollisionObject * OpcodeCollisionDetection::createObject( SectorObject * obj ){ - return createObject( obj->entity(), obj, "SectorObject" ); + return createObject( obj->entity(), obj, "SectorObject" ); } -void OpcodeCollisionDetection::destroyObject( OgreOpcode::CollisionObject * obj ){ - - OgreOpcode::ICollisionShape *shape = obj->getShape(); - OgreOpcode::CollisionManager::getSingletonPtr()->detachShape(shape); - OgreOpcode::CollisionManager::getSingletonPtr()->destroyShape(shape); - - - collideInSectorContext_->destroyObject( obj ); - // OgreOpcode::CollisionManager::getSingletonPtr()->destroyShape( obj->getShape() ); +void OpcodeCollisionDetection::destroyObject( OgreOpcode::CollisionObject * obj ){ + + if ( active_ ){ + OgreOpcode::ICollisionShape * shape = obj->getShape(); + collideInSectorContext_->destroyObject( obj ); + + collisionManager_->detachShape( shape ); + collisionManager_->destroyShape( shape ); + } } bool OpcodeCollisionDetection::checkCollideRay( BaseObject * obj, const Ogre::Ray & ray, double rayLength){ - if ( !obj->isSetDestroyRequest() ){ - OgreOpcode::CollisionPair ** rayPickReport; - uint nColl = collideInSectorContext_->rayCheck( ray, rayLength, OgreOpcode::COLLTYPE_EXACT, - OgreOpcode::COLLTYPE_ALWAYS_EXACT, rayPickReport ); + if ( active_ ){ + if ( !obj->isSetDestroyRequest() ){ + OgreOpcode::CollisionPair ** rayPickReport; + uint nColl = collideInSectorContext_->rayCheck( ray, rayLength, OgreOpcode::COLLTYPE_EXACT, + OgreOpcode::COLLTYPE_ALWAYS_EXACT, rayPickReport ); + // std::cout << "checkCollideRay: " << " " << rayLength << " " << nColl <<std::endl; - for ( uint i = 0; i < nColl; i ++ ){ - OgreOpcode::CollisionObject* col1 = rayPickReport[ i ]->this_object; - OgreOpcode::CollisionObject* col2 = rayPickReport[ i ]->other_object; + for ( uint i = 0; i < nColl; i ++ ){ + OgreOpcode::CollisionObject* col1 = rayPickReport[ i ]->this_object; + OgreOpcode::CollisionObject* col2 = rayPickReport[ i ]->other_object; // std::cout << "checkCollideRay: " << i << " " // << static_cast< BaseObject * >( col1->getClientData() )->name() << "<->" // << static_cast< BaseObject * >( col2->getClientData() )->name() << std::endl; - if ( obj->getTypeID() == PROJECTILE_RTTI ){ - if ( dynamic_cast< Projectile * >( obj )->parent() != static_cast< BaseObject * >( col1->getClientData() ) ){ - obj->mainNode()->setPosition( rayPickReport[ i ]->contact ); - obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); - static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); - return true; - } - } else if ( obj != col1->getClientData() ){ - obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); - static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); - } - } - } - return false; + if ( obj->getTypeID() == PROJECTILE_RTTI ){ + if ( dynamic_cast< Projectile * >( obj )->parent() != + static_cast< BaseObject * >( col1->getClientData() ) ){ + obj->mainNode()->setPosition( rayPickReport[ i ]->contact ); + obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); + static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); + return true; + } + } else if ( obj != col1->getClientData() ){ + obj->collide( static_cast< BaseObject * >( col2->getClientData() ) ); + static_cast< BaseObject * >( col1->getClientData() )->collide( obj ); + } + } + } + } + return false; } void OpcodeCollisionDetection::changeCollClass( OgreOpcode::CollisionObject * collObj, const std::string & collClass ){ - if ( collObj ) collObj->setCollClass( OgreOpcode::CollisionManager::getSingletonPtr()->queryCollClass( collClass ) ); + if ( collObj ) collObj->setCollClass( collisionManager_->queryCollClass( collClass ) ); } OpcodeCollisionDetection & OpcodeCollisionDetection::getSingleton( ){ Modified: trunk/src/OpcodeWrapper.h =================================================================== --- trunk/src/OpcodeWrapper.h 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/OpcodeWrapper.h 2008-04-24 19:45:36 UTC (rev 885) @@ -26,6 +26,7 @@ namespace OgreOpcode{ class CollisionContext; + class CollisionManager; class CollisionObject; } @@ -34,9 +35,12 @@ class BaseObject; class SectorObject; class Projectile; +class ResourceManager; class OpcodeCollisionDetection : public Ogre::Singleton< OpcodeCollisionDetection >{ public: + OpcodeCollisionDetection( ResourceManager * resources = NULL ); + OpcodeCollisionDetection( Ogre::SceneManager * sceneMgr ); ~OpcodeCollisionDetection(); @@ -44,6 +48,7 @@ bool update( Ogre::Real elapsedTime ); OgreOpcode::CollisionObject * createObject( Ogre::Entity * entity, BaseObject * obj, const std::string & collClass ); + OgreOpcode::CollisionObject * createObject( SectorObject * obj ); void destroyObject( OgreOpcode::CollisionObject * obj ); @@ -58,6 +63,8 @@ protected: OgreOpcode::CollisionContext * collideInSectorContext_; + OgreOpcode::CollisionManager * collisionManager_; + bool active_; }; Modified: trunk/src/OpenALSoundManager.cpp =================================================================== --- trunk/src/OpenALSoundManager.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/OpenALSoundManager.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -277,7 +277,16 @@ bool OpenALOggStreamSource::release(){ alSourceStop( source_ ); empty_(); - alDeleteSources(1, &source_ ); + + //** alDeleteSources(1, & source_ ); + //** valgrind says:; + // Invalid read of size 4 +// ==10954== at 0x6129E42: (within /usr/lib64/libopenal.so.0.0.0) +// ==10954== by 0x612D083: (within /usr/lib64/libopenal.so.0.0.0) +// ==10954== by 0x6129B7F: alDeleteSources (in /usr/lib64/libopenal.so.0.0.0) +// ==10954== by 0x48ADCD: OpenGate::OpenALOggStreamSource::release() (OpenALSoundManager.cpp:280) +// ==10954== by 0x4899A6: OpenGate::OpenALSoundManager::destroySoundSource(OpenGate::OpenALSoundSource*) (OpenALSoundManager.cpp:639) + if ( soundMgr_->checkOpenALError( "OpenALOggStreamSource::release::alDeleteSources" ) ) return false; alDeleteBuffers(1, buffers_ ); if ( soundMgr_->checkOpenALError( "OpenALOggStreamSource::release::alDeleteBuffers" ) ) return false; @@ -455,7 +464,6 @@ OpenALSoundManager::~OpenALSoundManager(){ Ogre::Root::getSingleton().removeFrameListener( this ); - log_->info( "Shoutdown soundmanager." ); for ( std::map< std::string, OpenALSoundSource * >::iterator it = mapSoundSources_.begin(); it != mapSoundSources_.end(); ){ destroySoundSource( it++->second ); @@ -533,10 +541,13 @@ // } // deviceSpecifiers += strlen( deviceSpecifiers ) + 1; // } - - ALCdevice * device = alcOpenDevice( NULL ); +bool disable_ = false; +ALCdevice * device = NULL; + if ( !disable_ ){ + device = alcOpenDevice( NULL ); // Device = alcOpenDevice((ALubyte*)"DirectSound3D"); - + } + if ( !device ){ log_->warn( "No sound device detected." ); haveSoundDevice_ = false; Modified: trunk/src/Projectile.h =================================================================== --- trunk/src/Projectile.h 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/Projectile.h 2008-04-24 19:45:36 UTC (rev 885) @@ -56,8 +56,6 @@ Gun * gun() const { return gun_; } - virtual void destroyRequest(){} - protected: BaseObject * parent_; Modified: trunk/src/ResourceManager.cpp =================================================================== --- trunk/src/ResourceManager.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/ResourceManager.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -36,16 +36,18 @@ ResourceManager::ResourceManager( ){ log_ = LogManager::getSingletonPtr(); - ogreRoot = NULL; - renderWindow = NULL; - inputManager = NULL; - soundManager = NULL; - guiRenderer = NULL; - guiSystem = NULL; - console = NULL; - network = NULL; - gameStateRoot = NULL; - avatar = NULL; + ogreRoot = NULL; + renderWindow = NULL; + inputManager = NULL; + soundManager = NULL; + aiManager = NULL; + guiRenderer = NULL; + guiSystem = NULL; + console = NULL; + network = NULL; + gameStateRoot = NULL; + avatar = NULL; + collisionManager = NULL; keymap_ = new KeyMap(); keymap_->setDefaults(); languageSuffix_ = "en"; Modified: trunk/src/ResourceManager.h =================================================================== --- trunk/src/ResourceManager.h 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/ResourceManager.h 2008-04-24 19:45:36 UTC (rev 885) @@ -41,6 +41,7 @@ class NetworkClient; class InputManager; class LogManager; +class AiManager; class OpenALSoundManager; class GameState; class GameStateManager; @@ -49,6 +50,7 @@ class Entity; class Station; class KeyMap; +class OpcodeCollisionDetection; class ResourceManager : public Ogre::Singleton< ResourceManager > { public: @@ -62,7 +64,9 @@ Console * console; GameStateManager * gameStateRoot; Avatar * avatar; - + AiManager * aiManager; + OpcodeCollisionDetection * collisionManager; + ResourceManager( ); ~ResourceManager( ); Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2008-02-04 22:31:01 UTC (rev 884) +++ trunk/src/Sector.cpp 2008-04-24 19:45:36 UTC (rev 885) @@ -20,6 +20,7 @@ #include "Sector.h" #include "Avatar.h" +#include "AiObject.h" #include "OpcodeWrapper.h" #include "tinyxml/tinyxml.h" #include "ResourceManager.h" @@ -155,34 +156,28 @@ } populate( "testsector.xml" ); - -// createCircle(); - - itTarget_ = sectorObjects_.begin(); } Sector::~Sector( ){ for ( std::map< long, SectorObjectMoveable * >::iterator it = movableObjects_.begin(); it != movableObjects_.end();){ // log_->info( "Destructing: " + it->second->name() ); - destructMoveableObject_( (it++)->second ); + destruct_( (it++)->second ); // log_->info( "done: " ); } for ( std::set< SectorObject * >::iterator it = sectorObjects_.begin(); it != sectorObjects_.end(); ){ // log_->info( "Destructing: " + (*it)->name() ); - - if ( (*it)->isOnRadar() && radar_ ){ - Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); - Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); - radarMap->removeChild( (*it)->dotA()->getName() ); - radarMap->removeChild( (*it)->dotB()->getName() ); + + if ( radar_ && (*it)->isOnRadar() ){ + Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); + Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); + radarMap->removeChild( (*it)->dotA()->getName() ); + radarMap->removeChild( (*it)->dotB()->getName() ); } delete *it; sectorObjects_.erase( (*it++) ); - -// log_->info( "done: " ); } sceneMgr_->destroyLight("MainLight" ); @@ -264,7 +259,6 @@ } } - //** Load stations for ( pElem = hRoot.FirstChild( "station" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement("station") ) { std::string name; @@ -292,7 +286,6 @@ Ogre::Quaternion rot = ( obj->mainNode()->getOrientation().zAxis()* -1.0).getRotationTo( targetDirection ); obj->mainNode()->rotate( rot ); } - } //** Load passive sector objects @@ -313,7 +306,7 @@ mesh = std::string( pSubElem->FirstChild()->Value() ) + ".mesh"; Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load( mesh, - Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, true, true); @@ -417,47 +410,48 @@ for ( std::set< SectorObject * >::iterator it = sectorObjects_.begin(); it != sectorObjects_.end(); it++){ - Ogre::Vector3 relativPosition( (*it)->mainNode()->getPosition( ) - avatar_->mainNode()->getPosition( ) ); - Ogre::OverlayElement * dotA = (*it)->dotA(); - Ogre::OverlayElement * dotB = (*it)->dotB(); + if ( (*it) != avatar_ ){ + Ogre::Vector3 relativPosition( (*it)->mainNode()->getPosition( ) - avatar_->mainNode()->getPosition( ) ); + Ogre::OverlayElement * dotA = (*it)->dotA(); + Ogre::OverlayElement * dotB = (*it)->dotB(); - if ( relativPosition.length() < radarRange ){ + if ( relativPosition.length() < radarRange ){ - Ogre::Quaternion q; - q.FromAngleAxis( -avatar_->mainNode()->getOrientation( ).getYaw(), Ogre::Vector3::UNIT_Y); - relativPosition = q * relativPosition; + Ogre::Quaternion q; + q.FromAn... [truncated message content] |
From: <spo...@us...> - 2008-05-01 18:29:40
|
Revision: 887 http://opengate.svn.sourceforge.net/opengate/?rev=887&view=rev Author: spom_spom Date: 2008-05-01 11:29:14 -0700 (Thu, 01 May 2008) Log Message: ----------- Add some basic ai commands, e.i. dock at a station. Modified Paths: -------------- trunk/data/materials/station.material trunk/data/stations/tauseti_wake.mesh trunk/src/AiManager.cpp trunk/src/AiObject.cpp trunk/src/AiObject.h trunk/src/Console.cpp trunk/src/Console.h trunk/src/GameStateManager.cpp trunk/src/KeyMap.cpp trunk/src/Makefile.am trunk/src/OpcodeWrapper.cpp trunk/src/Projectile.h trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObjects.cpp trunk/src/SectorObjects.h trunk/src/Station.cpp trunk/src/Station.h trunk/src/UnDockedState.cpp trunk/src/UnDockedState.h trunk/src/Vessel.h trunk/src/common.h trunk/src/networkProtocol.cpp trunk/src/networkProtocol.h trunk/src/opengateclient.cpp Added Paths: ----------- trunk/src/AiCommands.cpp trunk/src/AiCommands.h Modified: trunk/data/materials/station.material =================================================================== --- trunk/data/materials/station.material 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/data/materials/station.material 2008-05-01 18:29:14 UTC (rev 887) @@ -150,6 +150,22 @@ } } +material Station/LaunchPad.001 : Station/LaunchPad +{ +} + +material Station/LaunchPad.002 : Station/LaunchPad +{ +} + +material Station/LaunchPad.003 : Station/LaunchPad +{ +} + +material Station/LaunchPad.004 : Station/LaunchPad +{ +} + material OpenGate/SingleTexture { receive_shadows on Modified: trunk/data/stations/tauseti_wake.mesh =================================================================== (Binary files differ) Added: trunk/src/AiCommands.cpp =================================================================== --- trunk/src/AiCommands.cpp (rev 0) +++ trunk/src/AiCommands.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -0,0 +1,346 @@ +/*************************************************************************** + * Copyright (C) 2008 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#include "common.h" +#include "AiObject.h" +#include "AiCommands.h" +#include "SectorObjects.h" + +#include <iostream> +#include <string> + +namespace OpenGate{ + +void AiCommandStop::start(){ + std::cout << "AiCommandStop start" << std::endl; + if ( ai_->sectorObject( ) ) ai_->sectorObject( )->setThrustRate( 0.0 ); + if ( turnaround_ ){ + addCommand( new AiCommandPitch( ai_, 180.0 ) ); + addCommand( new AiCommandAccelerate( ai_, -1.0, 1.0 ) ); + addCommand( new AiCommandPitch( ai_, 180.0 ) ); + addCommand( new AiCommandStop( ai_ ) ); + } else { + if ( ai_->sectorObject( ) ) ai_->sectorObject( )->setBreakPressed( true ); + std::cout << "braking speed: " << ai_->sectorObject( )->speed() << std::endl; + std::cout << "braking time est: " << ai_->brakingTime( ai_->sectorObject( )->speed() ) << std::endl; + std::cout << "braking way est: " << ai_->brakingDistance( ai_->sectorObject( )->speed() ) << std::endl; + startPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + } +} +bool AiCommandStop::update( ) { + if ( ai_->sectorObject( ) ) { + if ( ai_->sectorObject( )->speed( ) < 0.01 ) return false; + } + return true; +} +void AiCommandStop::AiCommandStop::stop(){ + std::cout << "AiCommandStop stop" << std::endl; + if ( ai_->sectorObject( ) ) { + ai_->sectorObject( )->setBreakPressed( false ); + std::cout << "braking time real: " << runtime_ << std::endl; + std::cout << "braking way real: " + << ( ai_->sectorObject( )->mainNode()->getWorldPosition()- startPos_ ).length() + << std::endl; + } +} + + +void AiCommandSelfDestruct::stop(){ ai_->kill(); } + + +void AiCommandYaw::start(){ + if ( ai_->sectorObject() ){ + Ogre::Quaternion q; q.FromAngleAxis( Ogre::Degree( degree_ ), Ogre::Vector3::UNIT_Y); + addCommand( new AiCommandLookAt( ai_, + ai_->sectorObject()->mainNode()->getWorldOrientation() * q * Ogre::Vector3::NEGATIVE_UNIT_Z ) ); + } +} + + +void AiCommandPitch::start(){ + if ( ai_->sectorObject() ){ + Ogre::Quaternion q; q.FromAngleAxis( Ogre::Degree( degree_ ), Ogre::Vector3::UNIT_X); + addCommand( new AiCommandLookAt( ai_, + ai_->sectorObject()->mainNode()->getWorldOrientation() * q * Ogre::Vector3::NEGATIVE_UNIT_Z ) ); + } +} + + +void AiCommandLookAt::start( ){ + std::cout << "AiCommandLookAt::start()" << std::endl; + if ( ai_->sectorObject() ){ + if ( isPosition_ ) { + std::cout << "ai pos: " << ai_->sectorObject()->mainNode()->getWorldPosition() << std::endl; + std::cout << "target: " << targetDir_ << std::endl; + targetDir_ = targetDir_ - ai_->sectorObject()->mainNode()->getWorldPosition(); + } + targetDir_.normalise(); + std::cout << "ai dir: " << ai_->sectorObject()->mainNode()->getWorldOrientation() + * Ogre::Vector3::NEGATIVE_UNIT_Z << std::endl; + std::cout << "target: " << targetDir_ << std::endl; + } +} +bool AiCommandLookAt::update( ){ + if ( ai_->sectorObject() ){ + + if ( runtime_ > 5.0 * 360.0 / ai_->sectorObject()->vessel()->yaw() ){ + //** maybee endless loop through gimbal ???, so look at fixed direction and try again + runtime_ = 0.0; + addCommand( new AiCommandLookAt( ai_, Ogre::Vector3( Ogre::Math::RangeRandom( -1.0, 1.0 ), + Ogre::Math::RangeRandom( -1.0, 1.0 ), + Ogre::Math::RangeRandom( -1.0, 1.0 ) ).normalisedCopy() ) ); + return true; + } + + Ogre::Quaternion currOrient( ai_->sectorObject()->mainNode()->getWorldOrientation() ); + Ogre::Vector3 currDir = currOrient * Ogre::Vector3::NEGATIVE_UNIT_Z; currDir.normalise(); + if ( ( targetDir_ - currDir).squaredLength() < 0.00005f ) return false; + + Ogre::Quaternion targetOrient; + Ogre::Degree yawTo, pitchTo, rollTo; + +// if ( ( currDir + targetDir_ ).squaredLength() < 0.00005f ){ +// // Oops, a 180 degree turn (infinite possible rotation axes) +// // Default to yaw i.e. use current UP +// //targetOrient = Ogre::Quaternion(-currOrient.y, -currOrient.z, currOrient.w, currOrient.x); +// ai_->sectorObject()->setScaledYaw( -1.0 ); +// return true; +// } else { + // Derive shortest arc to new direction +// Ogre::Quaternion rotQuat( currDir.getRotationTo( targetDir_ ) ); +// rotQuat.normalise(); +// targetOrient = rotQuat * currOrient; + + /*if ( ( currDir + targetDir_ ).squaredLength() < 0.00005f ){ + yawTo = -180; + } else*/ { + + pitchTo = Ogre::Radian( std::asin( targetDir_.y ) - std::asin( currDir.y ) ).valueDegrees(); + yawTo = Ogre::Radian( std::atan2( targetDir_.z, targetDir_.x )+Ogre::Math::PI/2.0 + - std::atan2( currDir.z, currDir.x )+Ogre::Math::PI/2.0 ).valueDegrees(); + + } + +// std::cout << "Yawto : " << yawTo.valueDegrees() +// << " " << currOrient.getYaw().valueDegrees() +// << " " << targetOrient.getYaw().valueDegrees() +// << " pitchto " << pitchTo.valueDegrees() +// << " " << currOrient.getPitch().valueDegrees() +// << " " << targetOrient.getPitch().valueDegrees() +// << std::endl; + + + if ( yawTo > Ogre::Degree( 180.0 ) ) + yawTo = Ogre::Degree( -360.0 ) + yawTo; + else if ( yawTo < Ogre::Degree( -180.0 ) ) + yawTo = Ogre::Degree( 360.0 ) + yawTo; + + + Ogre::Real rotFric = ai_->sectorObject()->rotFriction(); + + Ogre::Real scaledYaw = yawTo.valueDegrees() / ( elapsedTime_ * rotFric * + ai_->sectorObject()->vessel()->yaw() ); + Ogre::Real scaledPitch = pitchTo.valueDegrees() / ( elapsedTime_ * rotFric * + ai_->sectorObject()->vessel()->pitch() ); + Ogre::Real scaledRoll = rollTo.valueDegrees() / ( elapsedTime_ * rotFric * + ai_->sectorObject()->vessel()->roll() ); + + double yaw = max( -1.0f, scaledYaw ); yaw = min( yaw, 1.0 ); + double pitch = max( -1.0f, scaledPitch ); pitch = min( pitch, 1.0 ); + double roll = max( -1.0f, scaledRoll ); roll = min( roll, 1.0 ); + +// std::cout << nr_ << " t: " << elapsedTime_ << "/" << runtime_ << " y: " << yawTo.valueDegrees() << "/" << scaledYaw << " " << yaw << " p: " << pitchTo.valueDegrees() << "/" << scaledPitch << " " << pitch +// << " sum: " << ( targetDir_ - currDir).squaredLength() << std::endl; +// std::cout << targetDir_ << currDir << std::endl; + +// ai_->sectorObject()->setScaledPitch( pitch ); +// ai_->sectorObject()->setScaledYaw( yaw ); + + if ( fabs( pitchTo.valueDegrees() ) < 0.1 ) { + ai_->sectorObject()->setScaledPitch( 0.0 ); + ai_->sectorObject()->setScaledYaw( yaw ); + } else { + ai_->sectorObject()->setScaledPitch( pitch ); + ai_->sectorObject()->setScaledYaw( 0.0 ); + } +// ai_->sectorObject()->setScaledRoll( roll ); + + } + return true; +} +void AiCommandLookAt::stop( ){ + std::cout << "AiCommandLookAt::stop()" << std::endl; + if ( ai_->sectorObject( ) ) { + ai_->sectorObject()->setScaledYaw( 0.0 ); + ai_->sectorObject()->setScaledPitch( 0.0 ); + ai_->sectorObject()->setScaledRoll( 0.0 ); + std::cout << "curr: " << ai_->sectorObject()->mainNode()->getWorldOrientation() + * Ogre::Vector3::NEGATIVE_UNIT_Z << std::endl; + } +} + + +void AiCommandRoll::start(){ + if ( ai_->sectorObject( ) ) { + Ogre::Quaternion q; q.FromAngleAxis( Ogre::Radian( Ogre::Degree( degree_ ).valueRadians() ), Ogre::Vector3::UNIT_Z); + Ogre::Quaternion q2( ai_->sectorObject()->mainNode()->getWorldOrientation() ); + targetDir_ = (q*q2) * Ogre::Vector3::NEGATIVE_UNIT_Z; + targetDir_.normalise(); + } +} +bool AiCommandRoll::update(){ + if ( ai_->sectorObject( ) ) { + Ogre::Vector3 thisDir( ai_->sectorObject()->mainNode()->getWorldOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z ); + thisDir.normalise(); + Ogre::Quaternion rot( thisDir.getRotationTo( targetDir_ ) ); rot.normalise(); + Ogre::Degree valTo( rot.getRoll() ); + Ogre::Real scaledVal = valTo.valueDegrees() / + ( elapsedTime_ * ai_->sectorObject()->rotFriction() * ai_->sectorObject()->vessel()->roll() ); + float val = max( -1.0f, scaledVal ); val = min( val, 1.0f ); + if ( fabs( val ) < 0.1 ) return false; + + ai_->sectorObject()->setScaledRoll( val ); + + return true; + } else return false; +} +void AiCommandRoll::stop(){ if ( ai_->sectorObject( ) ) ai_->sectorObject()->setScaledPitch( 0.0 ); } + +void AiCommandSetThrust::start() { + if ( ai_->sectorObject( ) ) { + ai_->sectorObject( )->setThrustRate( thrustRate_ ); + } +} +void AiCommandTimedAccelerate::start() { + std::cout << "AiCommandTimedAccelerate start" << std::endl; + if ( ai_->sectorObject( ) ) { + ai_->sectorObject( )->setThrustRate( rate_ ); + initPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + } +} +void AiCommandTimedAccelerate::stop() { + std::cout << "AiCommandTimedAccelerate stop" << std::endl; + if ( ai_->sectorObject( ) ){ + ai_->sectorObject( )->setThrustRate( 0.0 ); + std::cout << " reclined way(real): " + << (ai_->sectorObject( )->mainNode()->getWorldPosition()- initPos_).length() << std::endl; + std::cout << " reclined way(ana): " + << ai_->wayAfterTime( runtime_, rate_ ) << std::endl; + } +} + +void AiCommandAccelerate::start(){ + std::cout << "AiCommandAccelerate::start()" << std::endl; + if ( ai_->sectorObject( ) ) { + ai_->sectorObject( )->setThrustRate( thrustRate_ ); + lastSpeed_ = ai_->sectorObject( )->speed(); + initPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + } +} +bool AiCommandAccelerate::update(){ + if ( ai_->sectorObject( ) ) { +// std::cout << "AiCommandAccelerate::update() " +// << speed_ << " " << ai_->sectorObject( )->speed() << std::endl; + if ( speed_ < 0.0 && + ( ai_->sectorObject( )->speed() < speed_ || ai_->sectorObject( )->speed() > lastSpeed_ ) ) { +// std::cout << " - speed reached " <<std::endl; + return false; + } + + if ( speed_ > 0.0 && ai_->sectorObject( )->speed() > speed_ ) { +// std::cout << " + speed reached " <<std::endl; + return false; + } + lastSpeed_ = ai_->sectorObject( )->speed(); + } else { + return false; + } + return true; +} +void AiCommandAccelerate::stop(){ + std::cout << "AiCommandAccelerate::stop" << std::endl; + if ( ai_->sectorObject( ) ) ai_->sectorObject( )->setThrustRate( 0.0 ); + std::cout << " reclined way(real): " + << (ai_->sectorObject( )->mainNode()->getWorldPosition()- initPos_).length() << std::endl; + std::cout << " reclined way(ana): " + << ai_->wayAfterTime( runtime_, thrustRate_ ) << std::endl; +} + + +void AiCommandApproach::start(){ + std::cout << "AiCommandApproach::start():" << std::endl; + if ( ai_->sectorObject( ) ) { + startPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + initDist_ = ( pos_ - ai_->sectorObject( )->mainNode()->getWorldPosition() ).length(); + std::cout << "ai pos: " << startPos_ << std::endl; + std::cout << "dist: " << initDist_ << std::endl; + std::cout << "target: " << pos_ << std::endl; + } + addCommand( new AiCommandLookAt( ai_, pos_, true ) ); + addCommand( new AiCommandSetThrust( ai_, 1.0 ) ); + // addCommand( new AiCommandWait( ai_, 1.0 ) ); +// addCommand( new AiCommandAccelerate( ai_, 230.0, 1.0 ) ); +// addCommand( new AiCommandStop( ai_, true ) ); +// addCommand( new AiCommandWait( ai_, 10.0 ) ); +} +bool AiCommandApproach::update(){ + if ( ai_->sectorObject( ) ) { + double dist = ( pos_ - ai_->sectorObject( )->mainNode()->getWorldPosition() ).length(); + + if ( ai_->brakingDistance( ai_->sectorObject( )->speed() ) > dist ){ + addCommand( new AiCommandStop( ai_, false ) ); + return true; + } + + if ( ai_->sectorObject( )->speed() < 0.05 ){ + std::cout << "dist: " << dist << std::endl; + if ( dist < 10.0 ) { // 10m snapping + return false; + } else { + addCommand( new AiCommandWait( ai_, 1.0 ) ); + addCommand( new AiCommandApproach( ai_, pos_, true ) ); + return true; + } + } + + + return true; + } else { + return false; + } +} + +void AiCommandApproach::stop(){ + std::cout << "AiCommandApproach::stop():" << std::endl; + if ( ai_->sectorObject( ) ) { + ai_->sectorObject( )->setThrustRate( 0.0 ); + std::cout << "ai pos: " << ai_->sectorObject( )->mainNode()->getWorldPosition() << std::endl; + std::cout << "dir: " << -ai_->sectorObject( )->mainNode()->getWorldOrientation().zAxis() + << std::endl; + std::cout << "pos: " + << startPos_ + initDist_ * -ai_->sectorObject( )->mainNode()->getWorldOrientation().zAxis() + << std::endl; + } + +} + + +} // namespace OpenGate{ Added: trunk/src/AiCommands.h =================================================================== --- trunk/src/AiCommands.h (rev 0) +++ trunk/src/AiCommands.h 2008-05-01 18:29:14 UTC (rev 887) @@ -0,0 +1,238 @@ +/*************************************************************************** + * Copyright (C) 2008 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _OPENGATE_AICOMMANDS__H +#define _OPENGATE_AICOMMANDS__H + +#include <string> +#include <vector> +#include <set> +#include <queue> +#include <iostream> + +namespace Ogre{ + class Timer; + class Vector3; +} +#include <OgreVector3.h> + +namespace OpenGate{ + +class SectorObjectMoveableLocal; +class AiObject; +class AiCommand; +class AiCommandWait; +class AiCommandStop; +class AiCommandTimedAccelerate; + +class AiCommand { +public: + AiCommand( AiObject * ai ) : ai_( ai ), abort_( false ), running_( false ), runtime_( 0.0 ), elapsedTime_ ( 0.0 ){} + + virtual ~AiCommand(){} + + virtual bool update( double elapsedTime ){ + elapsedTime_ = elapsedTime; + runtime_ += elapsedTime; + if ( !running_ ) { + start(); + running_ = true; + nr_ = 0; + } + nr_++; + if ( abort_ ){ + if ( !cmds_.empty() ){ + cmds_.front()->abort(); + } + stop(); + return false; + } + + if ( !cmds_.empty() ){ + if ( !cmds_.front()->update( elapsedTime_ ) ){ + delete cmds_.front(); + cmds_.pop_front(); + } + } else if ( !update( ) ) { + stop(); + return false; + } + return true; + } + + bool abort( ) { abort_ = true; } + + virtual void start() { std::cout << "AiCommand start" << std::endl; } + virtual bool update( ) { return false; } + virtual void stop() { std::cout << "AiCommand stop" << std::endl; } + + void addCommand( AiCommand * cmd ) { cmds_.push_back( cmd ); } + +protected: + AiObject * ai_; + bool abort_; + bool running_; + double runtime_; + double elapsedTime_; + uint nr_; + std::deque< AiCommand * > cmds_; +}; + +class AiCommandSelfDestruct : public AiCommand { + public: + AiCommandSelfDestruct( AiObject * ai ) : AiCommand( ai ) { } + virtual ~AiCommandSelfDestruct(){ } + virtual bool update( ) { return false; } + virtual void stop(); + protected: +}; + +class AiCommandStop : public AiCommand { +public: + AiCommandStop( AiObject * ai, bool turnaround = false ) : AiCommand( ai ), turnaround_( turnaround ) { } + virtual ~AiCommandStop(){ } + virtual void start( ); + virtual bool update( ); + virtual void stop( ); +protected: + bool turnaround_; + Ogre::Vector3 startPos_; +}; + +/*!Look at a direction or at a position if flag set. */ +class AiCommandLookAt : public AiCommand { +public: + AiCommandLookAt( AiObject * ai, const Ogre::Vector3 & dir, bool isPos = false) + : AiCommand( ai ), targetDir_( dir ), isPosition_( isPos ) { } + virtual ~AiCommandLookAt(){ } + virtual void start( ); + virtual bool update( ); + virtual void stop( ); +protected: + Ogre::Vector3 targetDir_; + bool isPosition_; +}; + +class AiCommandYaw : public AiCommand { +public: + AiCommandYaw( AiObject * ai, double degree ) : AiCommand( ai ), degree_( degree ) { } + virtual ~AiCommandYaw(){ } + virtual void start( ); +protected: + double degree_; +}; + +class AiCommandPitch : public AiCommand { +public: + AiCommandPitch( AiObject * ai, double degree ) : AiCommand( ai ), degree_( degree ) { } + virtual ~AiCommandPitch(){ } + virtual void start( ); +protected: + double degree_; +}; + +class AiCommandRoll : public AiCommand { +public: + AiCommandRoll( AiObject * ai, double degree ) : AiCommand( ai ), degree_( degree ) { } + virtual ~AiCommandRoll(){ } + virtual void start( ); + virtual bool update( ); + virtual void stop( ); +protected: + double degree_; + Ogre::Vector3 targetDir_; +}; + +class AiCommandSetThrust : public AiCommand { +public: + AiCommandSetThrust( AiObject * ai, double thrustRate ) + : AiCommand( ai ), thrustRate_( thrustRate ){} + virtual void start(); +protected: + double thrustRate_; +}; + + +/*! Accelerate to a given |speed|. The command finish if speed is greater or slower fabs( speed ) +depending on the sign of speed */ +class AiCommandAccelerate : public AiCommand { +public: + AiCommandAccelerate( AiObject * ai, double speed, double thrustRate ) + : AiCommand( ai ), speed_( speed ), thrustRate_( thrustRate ){ } + + virtual ~AiCommandAccelerate(){ } + virtual void start(); + virtual bool update( ); + virtual void stop(); +protected: + double speed_; + double lastSpeed_; + double thrustRate_; + Ogre::Vector3 initPos_; +}; + +class AiCommandApproach : public AiCommand { +public: + AiCommandApproach( AiObject * ai, const Ogre::Vector3 & pos, bool stop ) + : AiCommand( ai ), pos_( pos ), stop_( stop ){} + ~AiCommandApproach(){} + virtual void start(); + virtual bool update(); + virtual void stop(); +protected: + Ogre::Vector3 pos_; + Ogre::Vector3 startPos_; + bool stop_; + double lastDist_; + double initDist_; +}; + +class AiCommandWait : public AiCommand { +public: + AiCommandWait( AiObject * ai, double time ) : AiCommand( ai ), time_( time ){} + virtual ~AiCommandWait(){} + + virtual void start() { std::cout << "AiCommandWait start" << std::endl;} + virtual bool update( ){ + if ( runtime_ > time_ ) return false; + return true; + } + virtual void stop() { std::cout << "AiCommandWait stop: " << runtime_ << std::endl;} +protected: + double time_; +}; + +class AiCommandTimedAccelerate : public AiCommandWait { +public: + AiCommandTimedAccelerate( AiObject * ai, double time, double thrustRate ) + : AiCommandWait( ai, time ), rate_( thrustRate ) { } + + virtual ~AiCommandTimedAccelerate(){ } + virtual void start(); + virtual void stop(); +protected: + double rate_; + Ogre::Vector3 initPos_; +}; + +} // namespace OpenGate{ + + +#endif // _OPENGATE_AICOMMANDS__H Modified: trunk/src/AiManager.cpp =================================================================== --- trunk/src/AiManager.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/AiManager.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -28,6 +28,8 @@ #include "UnDockedState.h" #include "GameStateManager.h" #include "Avatar.h" +#include "Station.h" +#include "OgreSceneNode.h" #include <iostream> #include <iterator> @@ -52,7 +54,7 @@ } void AiManager::killall(){ - //std::cout << "AiManager::killall():" << aiObjects_.size() << std::endl; + std::cout << "AiManager::killall():" << aiObjects_.size() << std::endl; //** ugly, kill direkt auf aiObjects_ ist schlecht weil sich die ai selbst gleichzeitig austragen std::set< AiObject * > toKillTmpSet( aiObjects_ ); for_each( toKillTmpSet.begin(), toKillTmpSet.end(), std::mem_fun( &AiObject::kill ) ); @@ -95,7 +97,10 @@ } AiObject * AiManager::spawnAi( ){ - std::string name( "aiMan-" + resources_->avatar->name() ); + std::string name( "aiMan-" ); + if ( resources_ ){ + if ( resources_->avatar ) name += resources_->avatar->name(); + } AiObject * ai = createAiObject( name ); SectorObjectMoveableLocal *obj = NULL; @@ -106,21 +111,44 @@ createMoveableObjectLocal( ai->name(), resources_->network->userID(), ai->id(), *VesselManager::getSingleton().vessel( "apteryx" ) ); - - std::cout << "Create " << obj->name() << " " << obj->thrust() << " " << obj->speed() << std::endl; + obj->vessel( )->setPowerPlant( EquipmentManager::getSingleton().powerPlant( "Spud" ) ); + obj->vessel( )->setEngine( EquipmentManager::getSingleton().engine( "T-E-15" ) ); + obj->vessel( )->setRadar( EquipmentManager::getSingleton().radar( "Outlook" ) ); + obj->vessel( )->setShield( EquipmentManager::getSingleton().shield( "Kydango" ) ); + obj->vessel( )->setCapacitor( EquipmentManager::getSingleton().capacitor( "Sponge" ) ); + std::cout << "Create " << obj->name() << std::endl; } else { std::cout << "spawn only in undockedState" << std::endl; } } + //-250, 0, 500 ai->setSectorObject( obj ); - Ogre::Real xmin = -100.0, xmax = 200.0; - Ogre::Real ymin = -100.0, ymax = 200.0; - Ogre::Real zmin = -1000.0, zmax = -2000.0; + Ogre::Real xmin = -150.0, xmax = -200.0; + Ogre::Real ymin = 0.0, ymax = 100.0; + Ogre::Real zmin = 300.0, zmax = 400.0; - obj->mainNode()->setPosition( Ogre::Math::RangeRandom( xmin, xmax ), + if ( obj ) { + obj->mainNode()->setPosition( Ogre::Math::RangeRandom( xmin, xmax ), Ogre::Math::RangeRandom( ymin, ymax ), Ogre::Math::RangeRandom( zmin, zmax ) ); +// obj->mainNode()->setPosition( +// dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() +// )->sector()->station()->launchPadPosition() + +// dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() +// )->sector()->station()->launchPadOrientation().zAxis() * -100.0); +// +// obj->mainNode()->setOrientation( +// dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() +// )->sector()->station()->launchPadOrientation() ); + + ai->land( *dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() )->sector()->station() ); + } + + std::cout << "starting: " << ai->name() << std::endl; + + RunAiObject aio( ai, eraseAiObjectCB_ ); + aiThreads_.create_thread( aio ); return ai; } @@ -136,9 +164,7 @@ } aiObjects_.insert( ai ); ai->setName( name + "-" + toStr( ai->id() ) ); - std::cout << " creating starting:" << ai->name() << std::endl; - RunAiObject aio( ai, eraseAiObjectCB_ ); - aiThreads_.create_thread( aio ); + return ai; } Modified: trunk/src/AiObject.cpp =================================================================== --- trunk/src/AiObject.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/AiObject.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -18,20 +18,30 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + +#include "common.h" #include "AiObject.h" - +#include "AiCommands.h" #include "SectorObjects.h" +#include "Sector.h" +#include "Station.h" -#include "common.h" +#include <OgreTimer.h> +#include <OgreVector3.h> + #include <iostream> +#include <string> namespace OpenGate{ - + AiObject::AiObject( uint id ) : id_( id ), sectorObject_( NULL ){ + livetime_ = new Ogre::Timer(); reset(); } AiObject::~AiObject(){ + for_each( cmdQueue_.begin(), cmdQueue_.end(), deletePtr() ); + delete livetime_; } //** protected copy constructor @@ -47,32 +57,244 @@ } void AiObject::copy_( const AiObject & ai ){ - } void AiObject::reset( ){ - livetime_ = 0.0; + livetime_->reset(); + lasttime_ = 0; refCounter_ = 0; name_ = "unknown"; isAlive_ = true; die_ = false; + activeCmd_ = NULL; } -void AiObject::run(){ __D( name_ ) - isAlive_ = true; - while ( isAlive_ ){ - myMSleep( 300 ); - livetime_ += 300.0; - if ( livetime_ > 5000 || die_ ) isAlive_ = false; - } -} - void AiObject::setSectorObject( SectorObjectMoveableLocal * obj ){ sectorObject_ = obj; if ( obj ){ - sectorObject_->setControler( this ); + sectorObject_->setControler( this ); } } +void AiObject::run(){ __D( name_ ) + isAlive_ = true; + livetime_->reset(); + do { + if ( activeCmd_ ){ + unsigned long tmpTime = livetime_->getMicroseconds(); + // std::cout << tmpTime << " " << lasttime_ << std::endl; + if ( !activeCmd_->update( ( tmpTime - lasttime_ ) / 1e6 ) ) { + delete activeCmd_; + activeCmd_ = NULL; + } + lasttime_ = tmpTime; + } else if ( !cmdQueue_.empty() ){ + activeCmd_ = cmdQueue_.front(); + cmdQueue_.pop_front(); + } + myMSleep( 10 ); // 100fps + + //usleep( 100 ); // 100fps + + } while ( isAlive_ ); + + if ( activeCmd_ ) activeCmd_->abort(); + delete activeCmd_; + for_each( cmdQueue_.begin(), cmdQueue_.end(), deletePtr() ); cmdQueue_.clear(); + activeCmd_ = NULL; +} + +void AiObject::dance( ){ + cmdQueue_.push_back( new AiCommandWait( this, 2.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, 90.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -90.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, 180.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -27.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, 90.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -45.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, 180.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, 15.0 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -18.0 ) ); + cmdQueue_.push_back( new AiCommandWait( this, 2.0 ) ); + + cmdQueue_.push_back( new AiCommandRoll( this, 90.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, -90.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, 180.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, -27.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, 90.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, -45.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, 180.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, -15.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, 15.0 ) ); + cmdQueue_.push_back( new AiCommandRoll( this, -18.0 ) ); + +// cmdQueue_.push_back( new AiCommandPitch( this, 90.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -90.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, 180.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -27.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, 90.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -45.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, 180.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, 15.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -18.0 ) ); +// cmdQueue_.push_back( new AiCommandYaw( this, 90.0 ) ); +// cmdQueue_.push_back( new AiCommandYaw( this, -180.0 ) ); +// cmdQueue_.push_back( new AiCommandYaw( this, -90.0 ) ); +// cmdQueue_.push_back( new AiCommandYaw( this, 180.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, 90.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -180.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, 90.0 ) ); +// cmdQueue_.push_back( new AiCommandPitch( this, -180.0 ) ); + + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandPitch( this, -15.0 ) );cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandLookAt( this, Ogre::Vector3( 0.0, 0.0, 1.0 ) ) ); +} + +void AiObject::land( const StationObject & station ){ + cmdQueue_.push_back( new AiCommandWait( this, 2.0 ) ); + //Vector3(-0.563038, -77.3473, -1348.36) // dockpad + std::cout << "station docking pad: " << station.dockPadPosition( ) << std::endl; + + std::cout << "station ring end:" << station.dockingRingEnd( ) << std::endl; + // Vector3(-66.7835, -78.9126, -433.894) + std::cout << "station ring start:" << station.dockingRingStart( ) << std::endl; + + const_cast< StationObject * > (&station)->sector()->koordAxis()->setPosition( station.dockPadPosition( ) ) ; + // Vector3(-261.482, -5.00386, -1384.19) + std::cout << "station launch pad: " << station.launchPadPosition( ) << std::endl; + + //cmdQueue_.push_back( new AiCommandApproach( this, station.dockingRingStart( ), true ) ); + cmdQueue_.push_back( new AiCommandApproach( this, station.dockingRingStart( ), true ) ); + cmdQueue_.push_back( new AiCommandWait( this, 1.0 ) ); + cmdQueue_.push_back( new AiCommandApproach( this, station.dockPadPosition( ), true ) ); + + cmdQueue_.push_back( new AiCommandWait( this, 5.0 ) ); + cmdQueue_.push_back( new AiCommandSelfDestruct( this ) ); +} + +void AiObject::test( ){ + + cmdQueue_.push_back( new AiCommandWait( this, 0.5 ) ); + cmdQueue_.push_back( new AiCommandYaw( this, -90.0 ) ); + //cmdQueue_.push_back( new AiCommandYaw( this, 180.0 ) ); + cmdQueue_.push_back( new AiCommandTimedAccelerate( this, timeToSpeed( 200.0, 1.0 ), 1.0 ) ); + cmdQueue_.push_back( new AiCommandStop( this, true ) ); + cmdQueue_.push_back( new AiCommandWait( this, 2.0 ) ); + cmdQueue_.push_back( new AiCommandSelfDestruct( this ) ); +} + +// void AiObject::stop( ){ +// thrust( 0.0 ); +// yaw( 180 ); +// thrust( 1.0, time ); +// } +// + +//** v = a * t; +//** friction = drag * v^2; + +//** thrust = mass * a; +//** a = thrust / mass; + +//** s = v * t; + +//** vmax(th,d):=sqrt(th / d) +//** v(t):=(th-d * v(t)*v(t))/m * t + +//** t( thrust, v ) = v +//** v( thrust, t ) = +//** thrustFri = v * friction +//**a = ( -trust1 * thrust() - flightDir * friction ) / mass_; + + +// dg: 'diff(v,t) + d/m *v*v= th/m +// v[t] := v_max tanh( th / vmax * t) + +double AiObject::maxSpeed( double thrustRate ) const { + //** vmax(th,d):=sqrt( th/d ) ** P + double d = sectorObject_->vessel()->dragFactor(); + double th = sectorObject_->maxThrust() * thrustRate; + return sqrt( th / d ); +} + +double AiObject::speedAfterTime( double time, double thrustRate ) const { + //** v[ t ] := vmax * tanh( th / m / vmax * t ) ** P + double d = sectorObject_->vessel()->dragFactor(); + double m = sectorObject_->mass(); + double th = sectorObject_->maxThrust() * thrustRate; + double vmax = maxSpeed( thrustRate ); + double v = vmax * std::tanh( th / m / vmax * time ); +// std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; vmax: " << vmax << "; t: " << time +// << " v: " << v << std::endl; + return v; +} + +double AiObject::wayAfterTime( double time, double thrustRate ) const { + //** v[ t ] := vmax * tanh( th / m / vmax * t ) + //** s[t]:=integrate(v[t], t) + //** s = vmax^2/a * log( cosh( a / vmax * t ) ) ** P + double d = sectorObject_->vessel()->dragFactor(); + double m = sectorObject_->mass(); + double th = sectorObject_->maxThrust() * thrustRate; + double vmax = maxSpeed( thrustRate ); + double a = th / m; + double s = ( vmax * vmax ) / a * std::log( std::cosh( a / vmax * time ) ); +// std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; vmax: " << vmax << "; t: " << time +// << " s: " << s << std::endl; + return s; +} +double AiObject::brakingTime( double v ) const { + double d = sectorObject_->vessel()->dragFactor(); + double m = sectorObject_->mass(); + double a = sectorObject_->brakingAcc(); + double th = m * a; + //std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; v: " << v << "; t: " << time << std::endl; + double t = ( m * atan( ( d * v ) / sqrt( a * d * m ) ) ) / sqrt( a * d * m ); //see physics.m + return t; +} + +double AiObject::brakingDistance( double v ) const { + double d = sectorObject_->vessel()->dragFactor(); + double m = sectorObject_->mass(); + double a = sectorObject_->brakingAcc(); + double th = m * a; + + double t = brakingTime( v ); + double s = ( m * std::log( 1.0 / std::cos( (std::sqrt( a * d * m ) * t ) / m) ) ) / d; //see physics.m + //double s = ( v * v ) / a * std::log( std::cosh( a / v * brakingTime( v ) ) ); + return s; +} + +double atanh( double x ) { return 0.5 * std::log( ( 1.0 + x ) / ( 1.0 - x ) ); } + +double AiObject::timeToSpeed( double v, double thrustRate ) const { + + //** t(th,d,m,v):=( m * atanh( v / vmax ) ) / sqrt( d * th ) + double d = sectorObject_->vessel()->dragFactor(); + double m = sectorObject_->mass(); + double th = sectorObject_->maxThrust() * thrustRate; + double vmax = maxSpeed( thrustRate ); + v = min( v, 0.99 * vmax ); + + double t = m * atanh( v / vmax ) / sqrt( d * th ); +// std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; vmax: " << vmax << "; v: " << v +// << " t: " << t << std::endl; + return t; +} + + } // namespace OpenGate{ - Modified: trunk/src/AiObject.h =================================================================== --- trunk/src/AiObject.h 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/AiObject.h 2008-05-01 18:29:14 UTC (rev 887) @@ -29,11 +29,20 @@ #include <boost/thread.hpp> +namespace Ogre{ + class Timer; + class Vector3; +} +#include <OgreVector3.h> + namespace OpenGate{ class ResourceManager; class SectorObjectMoveableLocal; +class StationObject; class AiManager; +class AiObject; +class AiCommand; class AiObject{ public: @@ -51,13 +60,11 @@ void setSectorObject( SectorObjectMoveableLocal * obj ); /*! Get the instance which is controled by this ai */ - SectorObjectMoveableLocal * sectorObject( ){ return sectorObject_; } - - double livetime( ) const { return livetime_; } + inline SectorObjectMoveableLocal * sectorObject( ){ return sectorObject_; } bool isAlive() const { return isAlive_; } - void kill() { die_ = true; } + void kill() { isAlive_ = false; } void reset(); @@ -67,6 +74,37 @@ uint id() const { return id_;} + void dance( ); + + void test( ); + + void land( const StationObject & station ); + + /*! Idle and look every second for new orders */ + bool cmdIdle( ); + /*! Wait and do nothing */ + bool cmdWait( double time ); + /*! Accelerate a given time with a given thrustRate */ + bool cmdAccelerate( double time, double thrustRate ); + + /*! Calculate maximum speed from a given thrustRate [0..1]*/ + double maxSpeed( double thrustRate = 1.0 ) const; + + /*! Calculate speed from 0 with a given thrustRate [0..1] for a given time.*/ + double speedAfterTime( double time, double thrustRate = 1.0 ) const; + + /*! Calculate linear way starting with speed 0 and a given thrustRate [0..1] for a given time.*/ + double wayAfterTime( double time, double thrustRate ) const; + + /*! Calculate time until reach a speed from 0 with a given thrustRate [0..1].*/ + double timeToSpeed( double speed, double thrustRate = 1.0 ) const; + + /*! Calculate the braking distance without turnaround.*/ + double brakingDistance( double v ) const; + + /*! Calculate the braking time without turnaround.*/ + double brakingTime( double v ) const; + //! reference counting used for threading, prob. better using smart pointer uint referenceCounter() const { return refCounter_; } void incReferenceCounter() { refCounter_ ++; } @@ -81,15 +119,22 @@ //! the graphical representation SectorObjectMoveableLocal * sectorObject_; + std::deque< AiCommand * > cmdQueue_; + + AiCommand * activeCmd_; + //! holds objects live status bool isAlive_; - //! prepare object to die + //! prepare object to die, called by kill() and evaluated in run loop bool die_; //! holds objects livetime - double livetime_; + Ogre::Timer * livetime_; + //! time from last livecyle in microseconds + unsigned long lasttime_; + //! objects name std::string name_; @@ -98,6 +143,7 @@ //! reference counter for threadholder uint refCounter_; + }; } // namespace OpenGate{ Modified: trunk/src/Console.cpp =================================================================== --- trunk/src/Console.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/Console.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -161,6 +161,10 @@ LogManager::getSingleton().info( "wrote: " + tmp ); } return true; } +bool Console::keyActionShutdown_DEV( bool pressed ){ + if ( pressed ) ResourceManager::getSingleton().gameStateRoot->shutdown(); + return true; +} void Console::print( const std::string & t ){ CEGUI::colour col(1.0, 1.0, 1.0, 1.0); Modified: trunk/src/Console.h =================================================================== --- trunk/src/Console.h 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/Console.h 2008-05-01 18:29:14 UTC (rev 887) @@ -65,6 +65,7 @@ bool keyActionDoNothing( bool pressed = true ) { return false; } bool keyActionScreenshot( bool pressed = true ); + bool keyActionShutdown_DEV( bool pressed = true ); private: Modified: trunk/src/GameStateManager.cpp =================================================================== --- trunk/src/GameStateManager.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/GameStateManager.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -419,7 +419,7 @@ "initialise equipment manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), std::string >( &GameStateManager::initialiseAiManager, - "initialise ai manager" ) ); + "initialise ai manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), std::string >( &GameStateManager::createAvatar, "create avatar" ) ); Modified: trunk/src/KeyMap.cpp =================================================================== --- trunk/src/KeyMap.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/KeyMap.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -66,7 +66,8 @@ /*! Actions for console. */ consoleActionMap_[ keycode( OIS::KC_SYSRQ ) ] = &Console::keyActionScreenshot; - + consoleActionMap_[ keycode( OIS::KC_Q, KEY_CONTROL ) ]= &Console::keyActionShutdown_DEV; + /*! Actions for development, will removed later. */ unDockedActionMap_[ keycode( OIS::KC_F ) ] = &UnDockedState::keyActionToggleFiltering_DEV; unDockedActionMap_[ keycode( OIS::KC_R, KEY_CONTROL ) ] = &UnDockedState::keyActionTogglePolygonMode_DEV; @@ -82,6 +83,7 @@ unDockedActionMap_[ keycode( OIS::KC_F4 ) ] = &UnDockedState::keyActionAvatarChangeDockedState_DEV; unDockedActionMap_[ keycode( OIS::KC_F8 ) ] = &UnDockedState::keyActionAvatarSelfDestruct_DEV; unDockedActionMap_[ keycode( OIS::KC_F7 ) ] = &UnDockedState::keyActionSpawnAi_DEV; + unDockedActionMap_[ keycode( OIS::KC_I, KEY_CONTROL ) ] = &UnDockedState::keyActionShowInfos_DEV; } bool(UnDockedState::*KeyMap::unDockedKeyAction( const OIS::KeyEvent & e ))(bool) { Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/Makefile.am 2008-05-01 18:29:14 UTC (rev 887) @@ -19,6 +19,8 @@ tinyxml/tinyxmlparser.cpp \ Avatar.h \ Avatar.cpp \ + AiCommands.h \ + AiCommands.cpp \ AiManager.h \ AiManager.cpp \ AiObject.h \ @@ -131,6 +133,8 @@ AiManager.cpp \ AiObject.h \ AiObject.cpp \ + AiCommands.h \ + AiCommands.cpp \ BaseDialog.h \ BaseDialog.cpp \ ConfigDialog.h \ Modified: trunk/src/OpcodeWrapper.cpp =================================================================== --- trunk/src/OpcodeWrapper.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/OpcodeWrapper.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -131,9 +131,9 @@ if ( active_ ){ OgreOpcode::ICollisionShape * shape = obj->getShape(); collideInSectorContext_->destroyObject( obj ); - collisionManager_->detachShape( shape ); collisionManager_->destroyShape( shape ); + obj = NULL; } } @@ -155,7 +155,7 @@ // << static_cast< BaseObject * >( col1->getClientData() )->name() << "<->" // << static_cast< BaseObject * >( col2->getClientData() )->name() << std::endl; - if ( obj->getTypeID() == PROJECTILE_RTTI ){ + if ( obj->rtti() == PROJECTILE_RTTI ){ if ( dynamic_cast< Projectile * >( obj )->parent() != static_cast< BaseObject * >( col1->getClientData() ) ){ obj->mainNode()->setPosition( rayPickReport[ i ]->contact ); Modified: trunk/src/Projectile.h =================================================================== --- trunk/src/Projectile.h 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/Projectile.h 2008-05-01 18:29:14 UTC (rev 887) @@ -34,10 +34,10 @@ virtual ~Projectile(); + inline virtual long rtti() const { return PROJECTILE_RTTI; } + void fire( const Ogre::Vector3 & pos, const Ogre::Vector3 & relGunPos = Ogre::Vector3::ZERO); - inline virtual long getTypeID() const { return PROJECTILE_RTTI; } - virtual void collide( BaseObject * object ); inline Uint32 damage( ) const { return damage_; } Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/Sector.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -68,13 +68,14 @@ Sector::Sector( Ogre::SceneManager * sceneMgr, NetworkClient * network ) : sceneMgr_( sceneMgr ), network_( network ) { - radar_ = true; - planetNode_ = NULL; - planet_ = NULL; - starsNode_ = NULL; - avatar_ = NULL; - station_ = NULL; - log_ = LogManager::getSingletonPtr(); + radar_ = true; + planetNode_ = NULL; + planet_ = NULL; + koordAxisNode_ = NULL; + starsNode_ = NULL; + avatar_ = NULL; + station_ = NULL; + log_ = LogManager::getSingletonPtr(); avatarDeathSequenceTime_ = 0.0; @@ -123,7 +124,7 @@ mainLight->setPosition(-50000, 0, -40000 ); 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 ); planet_ = new Planet( "planet", sceneMgr_, Ogre::Vector3( 0000.0, 0000.0, 50000 ), 15000.0f, 64 ); @@ -156,6 +157,7 @@ } populate( "testsector.xml" ); + createKoordAxis( ); } Sector::~Sector( ){ @@ -192,6 +194,16 @@ if ( collisionDetection_ ) delete collisionDetection_; collisionDetection_ = NULL; + + + + if ( koordAxisNode_ ) { + koordAxisNode_->detachObject( koordAxisMO_ ); + sceneMgr_->destroyManualObject( koordAxisMO_->getName() ); + sceneMgr_->getRootSceneNode()->removeAndDestroyChild( koordAxisNode_->getName() ); + koordAxisNode_ = NULL; + } + } void Sector::populate( const std::string & fileName ){ @@ -550,18 +562,17 @@ SectorObjectMoveableAi * Sector::createAiMoveableObject( const Ogre::String & name, Uint32 userID, Uint8 childID, Vessel & vessel ){ + SectorObjectMoveableAi * obj = new SectorObjectMoveableAi( name, this, userID, childID, new Vessel( vessel ) ); + sectorObjects_.insert( obj ); + movableObjects_[ obj->globalID() ] = obj; + localAiObjects_[ obj->globalID() ] = obj; - SectorObjectMoveableAi * obj = new SectorObjectMoveableAi( name, this, userID, childID, new Vessel( vessel ) ); - sectorObjects_.insert( obj ); - movableObjects_[ obj->globalID() ] = obj; - localAiObjects_[ obj->globalID() ] = obj; - - return obj; + return obj; } void Sector::destruct_( SectorObject * obj ){ if ( obj ){ - log_->debug( "destruct Object: " + obj->name() + " " + toStr( obj->getTypeID() ) ); + log_->debug( "destruct Object: " + obj->name() + " " + toStr( obj->rtti() ) ); sectorObjects_.erase( obj ); if ( listener_->target() == obj ) selectNextTarget( ); @@ -579,7 +590,7 @@ } } - switch ( obj->getTypeID() ){ + switch ( obj->rtti() ){ case SECTOROBJECTMOVABLE_RTTI: movableObjects_.erase( obj->globalID() ); delete obj; @@ -601,7 +612,7 @@ obj = NULL; } break; default: - log_->fatal( "destructMoveableObject: object type unknown. this should not happen: " + toStr( obj->getTypeID() ) ); + log_->fatal( "destructMoveableObject: object type unknown. this should not happen: " + toStr( obj->rtti() ) ); } } else { log_->fatal( "destructMoveableObject: object is no valid: " ); @@ -627,7 +638,7 @@ obj->mainNode()->setPosition( Ogre::Math::RangeRandom( xmin, xmax ), Ogre::Math::RangeRandom( ymin, ymax ), Ogre::Math::RangeRandom( zmin, zmax ) ); - obj->setThrust( obj->maxThrust() ); + obj->setThrustRate( 1.0 ); // obj->mainNode()->setPosition( 0.0f, 0.0f, 200.0f); @@ -644,13 +655,13 @@ avatar_->reset(); if ( station_ ){ log_->info( std::string( "launch avatar from station " ) ); - avatar_->mainNode()->setPosition( station_->launchPadPosition() + station_->launchPadOrientation().zAxis() * -5.0); - avatar_->mainNode()->setOrientation( station_->launchPadOrientation() ); - avatar_->setVelocity( station_->launchPadOrientation().zAxis() * -20.0 ); + avatar_->mainNode()->setPosition( station_->launchPadPosition() + station_->launchPadDirection() * 5.0); + avatar_->mainNode()->setDirection( station_->launchPadDirection() ); + avatar_->setVelocity( station_->launchPadDirection() * 20.0 ); } else{ log_->info( std::string( "launch avatar from free position " ) ); - avatar_->mainNode()->setPosition( 0.0, 0.0, 500.0 ); - avatar_->mainNode()->setOrientation( Ogre::Quaternion( 1.0, 0.0, 0.0, 0.0 ) ); + avatar_->mainNode()->setPosition( 0.0, 0.0, 100.0 ); + avatar_->mainNode()->setDirection( Ogre::Vector3( 0.0, 0.0, -1.0 ) ); avatar_->setVelocity( Ogre::Vector3( 0.0, 0.0, -50.0 ) ); } @@ -714,6 +725,32 @@ return avatar_; } +void Sector::createKoordAxis( ){ + koordAxisNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( "axisnode" ); + koordAxisMO_ = sceneMgr_->createManualObject( koordAxisNode_->getName()+ "/manualObject" ); + Ogre::Real length = 20; + koordAxisMO_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); + unsigned point_index = 0; + koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->position( 1.0, 0.0, 0.0 ); + koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->position( 0.0, 1.0, 0.0 ); + koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->position( 0.0, 0.0, 1.0 ); + koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->position( -1.0, 0.0, 0.0 ); + koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->position( 0.0, -1.0, 0.0 ); + koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->position( 0.0, 0.0, -1.0 ); +// koordAxisMO_->line( 0, 1 ); +// koordAxisMO_->line( 0, 2 ); +// koordAxisMO_->line( 0, 3 ); + koordAxisMO_->end(); + koordAxisNode_->attachObject( koordAxisMO_ ); + koordAxisNode_->scale( length, length, length ); +} + void Sector::createCircle( ){ Ogre::String name = "testcircle"; @@ -784,7 +821,7 @@ obj->mainNode()->getPosition().ptr(), obj->velocity().ptr(), obj->mainNode()->getOrientation().ptr(), - obj->thrust(), + obj->thrustRate(), obj->scaledYaw(), obj->scaledPitch(), obj->scaledRoll(), Modified: trunk/src/Sector.h =================================================================== --- trunk/src/Sector.h 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/Sector.h 2008-05-01 18:29:14 UTC (rev 887) @@ -75,6 +75,8 @@ void spawnAiObject( const std::string & vesselName ); void createCircle( ); + void createKoordAxis( ); + Ogre::SceneNode * koordAxis() { return koordAxisNode_; } void selectNextTarget( ); @@ -108,11 +110,12 @@ void sendProjectile( const Projectile & projectile ); void receiveProjectile( const MessageBodyShipProjectileFired & msg ); + StationObject * station() { return station_; } protected: - //** do not destruct objects manualy, let them send false during update loop + +//** do not destruct objects manualy, let them send false during update loop void destruct_( SectorObject * obj ); - Ogre::SceneManager * sceneMgr_; NetworkClient * network_; LogManager * log_; @@ -126,7 +129,9 @@ Ogre::SceneNode * planetNode_; Ogre::SceneNode * starsNode_; - + Ogre::SceneNode * koordAxisNode_; + Ogre::ManualObject * koordAxisMO_; + std::set< SectorObject * > sectorObjects_; std::map< long, SectorObjectMoveable * > movableObjects_; Modified: trunk/src/SectorObjects.cpp =================================================================== --- trunk/src/SectorObjects.cpp 2008-04-24 20:30:07 UTC (rev 886) +++ trunk/src/SectorObjects.cpp 2008-05-01 18:29:14 UTC (rev 887) @@ -136,33 +136,24 @@ } void SectorObject::setShape( const Ogre::String & meshname ){ - entity_ = sceneMgr_->createEntity( name_ + "_shape", meshname ); - mainNodeEntityRot_->attachObject( entity_ ); - // mainNodeEntityRot_->_update( true, true ); - collObj_ = OpcodeCollisionDetection::getSingleton().createObject( this ); + entity_ = sceneMgr_->createEntity( name_ + "_shape", meshname ); + mainNodeEntityRot_->attachObject( entity_ ); + collObj_ = OpcodeCollisionDetection::getSingleton().createObject( this ); } void SectorObject::setBaseRot( const Ogre::Real & yaw, const Ogre::Real & pitch, const Ogre::Real & roll ){ - mainNodeEntityRot_->yaw( Ogre::Degree( yaw ) ); - mainNodeEntityRot_->pitch( Ogre::Degree( pitch ) ); - mainNodeEntityRot_->roll( Ogre::Degree( roll ) ); - // mainNodeEntityRot_->_update( true, true ); - std::cout << mainNodeEntityRot_->_getWorldAABB().getMaximum() << " " << - mainNodeEntityRot_->_getWorldAABB().getMinimum() << " " << - mainNodeEntityRot_->_getWorldAABB().getMaximum()-mainNodeEntityRot_->_getWorldAABB().getMinimum() - << std::endl; + mainNodeEntityRot_->yaw( Ogre::Degree( yaw ) ); + mainNodeEntityRot_->pitch( Ogre::Degree( pitch ) ); + mainNodeEntityRot_->roll( Ogre::Degree( roll ) ); } void SectorObject::scale( const Ogre::Vector3 & scale ){ mainNodeEntityScale_->scale( scale ); - //mainNodeEntityScale_->_update( true, true ); baseSize_ = scale * ( entity_->getBoundingBox().getMaximum() - entity_->getBoundingBox().getMinimum() ); } void SectorObject::setBaseSize( const Ogre::Vector3 & size ){ - // mainNode_->_update( true, true ); - - Ogre::Vector3 oldSize( mainNodeEntityRot_->getOrientation() * ( + Ogre::Vector3 oldSize( mainNodeEntityRot_->getOrientation() * ( mainNodeEntityRot_->_getWorldAABB().getMaximum()- mainNodeEntityRot_->_getWorldAABB().getMinimum() ) ); @@ -175,21 +166,21 @@ // entity_->getBoundingBox().getMinimum() ) ); // Ogre::Vector3 oldSize( mainNode_->_getWorldAABB().getMaximum() - mainNode_->_getWorldAABB().getMinimum() ); - Ogre::Vector3 scale( size / oldSize ); + Ogr... [truncated message content] |
From: <spo...@us...> - 2008-05-04 12:13:55
|
Revision: 888 http://opengate.svn.sourceforge.net/opengate/?rev=888&view=rev Author: spom_spom Date: 2008-05-04 05:13:52 -0700 (Sun, 04 May 2008) Log Message: ----------- Add support for missiles; you can try: F7 spawns autodocking ai -- select ai -- fire missile with mouse button 3; Start refactoring; The network is currently untested and marked as broken. Modified Paths: -------------- trunk/ToDo trunk/resources.cfg trunk/src/AiCommands.cpp trunk/src/AiCommands.h trunk/src/AiManager.cpp trunk/src/AiManager.h trunk/src/AiObject.cpp trunk/src/AiObject.h trunk/src/Avatar.cpp trunk/src/Avatar.h trunk/src/Entity.h trunk/src/EntityManager.cpp trunk/src/EntityManager.h trunk/src/GameStateManager.cpp trunk/src/Makefile.am trunk/src/MarketDialog.cpp trunk/src/OpcodeWrapper.cpp trunk/src/OpenALSoundManager.cpp trunk/src/OpenALSoundManager.h trunk/src/Projectile.cpp trunk/src/Projectile.h trunk/src/ResourceManager.cpp trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/ShipConfigDialog.cpp trunk/src/Station.cpp trunk/src/Station.h trunk/src/UnDockedState.cpp trunk/src/UnDockedState.h trunk/src/Vessel.cpp trunk/src/Vessel.h trunk/src/VesselManager.cpp trunk/src/opengateclient.cpp Added Paths: ----------- trunk/data/missiles/ trunk/data/missiles/firefly.mesh trunk/data/missiles/firefly_big.png trunk/data/missiles/firefly_small.png trunk/src/BaseObject.cpp trunk/src/BaseObject.h trunk/src/Equipment.h trunk/src/GunObject.cpp trunk/src/GunObject.h trunk/src/Moveable.cpp trunk/src/Moveable.h trunk/src/SectorObject.cpp trunk/src/SectorObject.h trunk/src/SectorObjectAvatar.cpp trunk/src/SectorObjectAvatar.h trunk/src/SectorObjectMissile.cpp trunk/src/SectorObjectMissile.h trunk/src/SectorObjectMoveable.cpp trunk/src/SectorObjectMoveable.h trunk/src/SectorObjectVessel.cpp trunk/src/SectorObjectVessel.h Removed Paths: ------------- trunk/src/SectorObjects.cpp trunk/src/SectorObjects.h Modified: trunk/ToDo =================================================================== --- trunk/ToDo 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/ToDo 2008-05-04 12:13:52 UTC (rev 888) @@ -31,7 +31,7 @@ - Speed/MaxSpeed - Acceleration - Mousecursor - - Bullseye/VCT-1 (Duelist) +# - Bullseye/VCT-1 (Duelist) - JG-like Radar - Simplest global chat @@ -45,7 +45,6 @@ - global/code - cleaning / refaktoring - - integrate in currect OpenGate framework # - add licence header - mark third persons thingies (mousecursor, skybox) #ALT-TAB - free mousepointer from widget contents @@ -74,10 +73,10 @@ # - read nonmovable objects # - read equipment and commodities - global config - + - keymap r/w - openal # - simplest testing - - soundmanger +# par - soundmanger - input - keymap @@ -127,11 +126,19 @@ # - fired partikel - station - - landing rings on the big ogrehead-mouth +# - landing rings on the big ogrehead-mouth - ai +# part - ai manager +# - multi threading aiobject +# part - set of ai commands that ca be combined # - simple follow - - calculate fireing solution +# - docking + - trading + - mining + - hunting + - protecting + - calculate fireing solution - rockets - pathfinding - genetic learning @@ -151,7 +158,7 @@ # OIS disables autorepeat, fire `xset r on` to enable - UTF support (\xFC\xF6\xE4) - since Ogre1.4 Overlay only support Ogre::UTFString, which throws exception by using umlaut + since Ogre1.4 Overlay only support Ogre::UTFString and throws exception by using umlaut IDEAS: @@ -183,7 +190,7 @@ 11. Flut 12. Tsunami 13. See - + ... Octavius (fire) --------------- 1. Funke @@ -199,5 +206,7 @@ 11. Asche 12. Candle 13. Torch,Flambeau - + ... + -Guns: Dazzler + -Missiles: Firefly, Dragonfly, Mosquito, Bee, Hummel, Hornet Added: trunk/data/missiles/firefly.mesh =================================================================== (Binary files differ) Property changes on: trunk/data/missiles/firefly.mesh ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/missiles/firefly_big.png =================================================================== (Binary files differ) Property changes on: trunk/data/missiles/firefly_big.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/missiles/firefly_small.png =================================================================== (Binary files differ) Property changes on: trunk/data/missiles/firefly_small.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/resources.cfg =================================================================== --- trunk/resources.cfg 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/resources.cfg 2008-05-04 12:13:52 UTC (rev 888) @@ -11,6 +11,7 @@ FileSystem=./data/ecms FileSystem=./data/power_plants FileSystem=./data/guns +FileSystem=./data/missiles FileSystem=./data/ships/octavius/apteryx FileSystem=./data/ships/quantar/storm FileSystem=./data/ships/tauseti/lady_kickstart Modified: trunk/src/AiCommands.cpp =================================================================== --- trunk/src/AiCommands.cpp 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/AiCommands.cpp 2008-05-04 12:13:52 UTC (rev 888) @@ -22,7 +22,8 @@ #include "common.h" #include "AiObject.h" #include "AiCommands.h" -#include "SectorObjects.h" +#include "SectorObjectVessel.h" +#include "Moveable.h" #include <iostream> #include <string> @@ -31,33 +32,33 @@ void AiCommandStop::start(){ std::cout << "AiCommandStop start" << std::endl; - if ( ai_->sectorObject( ) ) ai_->sectorObject( )->setThrustRate( 0.0 ); + if ( ai_->vesselObject( ) ) ai_->vesselObject( )->setThrustRate( 0.0 ); if ( turnaround_ ){ addCommand( new AiCommandPitch( ai_, 180.0 ) ); addCommand( new AiCommandAccelerate( ai_, -1.0, 1.0 ) ); addCommand( new AiCommandPitch( ai_, 180.0 ) ); addCommand( new AiCommandStop( ai_ ) ); } else { - if ( ai_->sectorObject( ) ) ai_->sectorObject( )->setBreakPressed( true ); - std::cout << "braking speed: " << ai_->sectorObject( )->speed() << std::endl; - std::cout << "braking time est: " << ai_->brakingTime( ai_->sectorObject( )->speed() ) << std::endl; - std::cout << "braking way est: " << ai_->brakingDistance( ai_->sectorObject( )->speed() ) << std::endl; - startPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + if ( ai_->vesselObject( ) ) ai_->vesselObject( )->setBreakPressed( true ); + std::cout << "braking speed: " << ai_->vesselObject( )->speed() << std::endl; + std::cout << "braking time est: " << ai_->brakingTime( ai_->vesselObject( )->speed() ) << std::endl; + std::cout << "braking way est: " << ai_->brakingDistance( ai_->vesselObject( )->speed() ) << std::endl; + startPos_ = ai_->vesselObject( )->mainNode()->getWorldPosition(); } } bool AiCommandStop::update( ) { - if ( ai_->sectorObject( ) ) { - if ( ai_->sectorObject( )->speed( ) < 0.01 ) return false; + if ( ai_->vesselObject( ) ) { + if ( ai_->vesselObject( )->speed( ) < 0.01 ) return false; } return true; } void AiCommandStop::AiCommandStop::stop(){ std::cout << "AiCommandStop stop" << std::endl; - if ( ai_->sectorObject( ) ) { - ai_->sectorObject( )->setBreakPressed( false ); + if ( ai_->vesselObject( ) ) { + ai_->vesselObject( )->setBreakPressed( false ); std::cout << "braking time real: " << runtime_ << std::endl; std::cout << "braking way real: " - << ( ai_->sectorObject( )->mainNode()->getWorldPosition()- startPos_ ).length() + << ( ai_->vesselObject( )->mainNode()->getWorldPosition()- startPos_ ).length() << std::endl; } } @@ -67,41 +68,41 @@ void AiCommandYaw::start(){ - if ( ai_->sectorObject() ){ + if ( ai_->vesselObject() ){ Ogre::Quaternion q; q.FromAngleAxis( Ogre::Degree( degree_ ), Ogre::Vector3::UNIT_Y); addCommand( new AiCommandLookAt( ai_, - ai_->sectorObject()->mainNode()->getWorldOrientation() * q * Ogre::Vector3::NEGATIVE_UNIT_Z ) ); + ai_->vesselObject()->mainNode()->getWorldOrientation() * q * Ogre::Vector3::NEGATIVE_UNIT_Z ) ); } } void AiCommandPitch::start(){ - if ( ai_->sectorObject() ){ + if ( ai_->vesselObject() ){ Ogre::Quaternion q; q.FromAngleAxis( Ogre::Degree( degree_ ), Ogre::Vector3::UNIT_X); addCommand( new AiCommandLookAt( ai_, - ai_->sectorObject()->mainNode()->getWorldOrientation() * q * Ogre::Vector3::NEGATIVE_UNIT_Z ) ); + ai_->vesselObject()->mainNode()->getWorldOrientation() * q * Ogre::Vector3::NEGATIVE_UNIT_Z ) ); } } void AiCommandLookAt::start( ){ std::cout << "AiCommandLookAt::start()" << std::endl; - if ( ai_->sectorObject() ){ + if ( ai_->vesselObject() ){ if ( isPosition_ ) { - std::cout << "ai pos: " << ai_->sectorObject()->mainNode()->getWorldPosition() << std::endl; + std::cout << "ai pos: " << ai_->vesselObject()->mainNode()->getWorldPosition() << std::endl; std::cout << "target: " << targetDir_ << std::endl; - targetDir_ = targetDir_ - ai_->sectorObject()->mainNode()->getWorldPosition(); + targetDir_ = targetDir_ - ai_->vesselObject()->mainNode()->getWorldPosition(); } targetDir_.normalise(); - std::cout << "ai dir: " << ai_->sectorObject()->mainNode()->getWorldOrientation() + std::cout << "ai dir: " << ai_->vesselObject()->mainNode()->getWorldOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z << std::endl; std::cout << "target: " << targetDir_ << std::endl; } } bool AiCommandLookAt::update( ){ - if ( ai_->sectorObject() ){ + if ( ai_->vesselObject() ){ - if ( runtime_ > 5.0 * 360.0 / ai_->sectorObject()->vessel()->yaw() ){ + if ( runtime_ > 5.0 * 360.0 / ai_->vesselObject()->moveable()->yaw() ){ //** maybee endless loop through gimbal ???, so look at fixed direction and try again runtime_ = 0.0; addCommand( new AiCommandLookAt( ai_, Ogre::Vector3( Ogre::Math::RangeRandom( -1.0, 1.0 ), @@ -110,7 +111,7 @@ return true; } - Ogre::Quaternion currOrient( ai_->sectorObject()->mainNode()->getWorldOrientation() ); + Ogre::Quaternion currOrient( ai_->vesselObject()->mainNode()->getWorldOrientation() ); Ogre::Vector3 currDir = currOrient * Ogre::Vector3::NEGATIVE_UNIT_Z; currDir.normalise(); if ( ( targetDir_ - currDir).squaredLength() < 0.00005f ) return false; @@ -121,7 +122,7 @@ // // Oops, a 180 degree turn (infinite possible rotation axes) // // Default to yaw i.e. use current UP // //targetOrient = Ogre::Quaternion(-currOrient.y, -currOrient.z, currOrient.w, currOrient.x); -// ai_->sectorObject()->setScaledYaw( -1.0 ); +// ai_->vesselObject()->setScaledYaw( -1.0 ); // return true; // } else { // Derive shortest arc to new direction @@ -154,14 +155,14 @@ yawTo = Ogre::Degree( 360.0 ) + yawTo; - Ogre::Real rotFric = ai_->sectorObject()->rotFriction(); + Ogre::Real rotFric = ai_->vesselObject()->rotFriction(); Ogre::Real scaledYaw = yawTo.valueDegrees() / ( elapsedTime_ * rotFric * - ai_->sectorObject()->vessel()->yaw() ); + ai_->vesselObject()->moveable()->yaw() ); Ogre::Real scaledPitch = pitchTo.valueDegrees() / ( elapsedTime_ * rotFric * - ai_->sectorObject()->vessel()->pitch() ); + ai_->vesselObject()->moveable()->pitch() ); Ogre::Real scaledRoll = rollTo.valueDegrees() / ( elapsedTime_ * rotFric * - ai_->sectorObject()->vessel()->roll() ); + ai_->vesselObject()->moveable()->roll() ); double yaw = max( -1.0f, scaledYaw ); yaw = min( yaw, 1.0 ); double pitch = max( -1.0f, scaledPitch ); pitch = min( pitch, 1.0 ); @@ -171,77 +172,77 @@ // << " sum: " << ( targetDir_ - currDir).squaredLength() << std::endl; // std::cout << targetDir_ << currDir << std::endl; -// ai_->sectorObject()->setScaledPitch( pitch ); -// ai_->sectorObject()->setScaledYaw( yaw ); +// ai_->vesselObject()->setScaledPitch( pitch ); +// ai_->vesselObject()->setScaledYaw( yaw ); if ( fabs( pitchTo.valueDegrees() ) < 0.1 ) { - ai_->sectorObject()->setScaledPitch( 0.0 ); - ai_->sectorObject()->setScaledYaw( yaw ); + ai_->vesselObject()->setScaledPitch( 0.0 ); + ai_->vesselObject()->setScaledYaw( yaw ); } else { - ai_->sectorObject()->setScaledPitch( pitch ); - ai_->sectorObject()->setScaledYaw( 0.0 ); + ai_->vesselObject()->setScaledPitch( pitch ); + ai_->vesselObject()->setScaledYaw( 0.0 ); } -// ai_->sectorObject()->setScaledRoll( roll ); +// ai_->vesselObject()->setScaledRoll( roll ); } return true; } void AiCommandLookAt::stop( ){ std::cout << "AiCommandLookAt::stop()" << std::endl; - if ( ai_->sectorObject( ) ) { - ai_->sectorObject()->setScaledYaw( 0.0 ); - ai_->sectorObject()->setScaledPitch( 0.0 ); - ai_->sectorObject()->setScaledRoll( 0.0 ); - std::cout << "curr: " << ai_->sectorObject()->mainNode()->getWorldOrientation() + if ( ai_->vesselObject( ) ) { + ai_->vesselObject()->setScaledYaw( 0.0 ); + ai_->vesselObject()->setScaledPitch( 0.0 ); + ai_->vesselObject()->setScaledRoll( 0.0 ); + std::cout << "curr: " << ai_->vesselObject()->mainNode()->getWorldOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z << std::endl; } } void AiCommandRoll::start(){ - if ( ai_->sectorObject( ) ) { + if ( ai_->vesselObject( ) ) { Ogre::Quaternion q; q.FromAngleAxis( Ogre::Radian( Ogre::Degree( degree_ ).valueRadians() ), Ogre::Vector3::UNIT_Z); - Ogre::Quaternion q2( ai_->sectorObject()->mainNode()->getWorldOrientation() ); + Ogre::Quaternion q2( ai_->vesselObject()->mainNode()->getWorldOrientation() ); targetDir_ = (q*q2) * Ogre::Vector3::NEGATIVE_UNIT_Z; targetDir_.normalise(); } } bool AiCommandRoll::update(){ - if ( ai_->sectorObject( ) ) { - Ogre::Vector3 thisDir( ai_->sectorObject()->mainNode()->getWorldOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z ); + if ( ai_->vesselObject( ) ) { + Ogre::Vector3 thisDir( ai_->vesselObject()->mainNode()->getWorldOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z ); thisDir.normalise(); Ogre::Quaternion rot( thisDir.getRotationTo( targetDir_ ) ); rot.normalise(); Ogre::Degree valTo( rot.getRoll() ); Ogre::Real scaledVal = valTo.valueDegrees() / - ( elapsedTime_ * ai_->sectorObject()->rotFriction() * ai_->sectorObject()->vessel()->roll() ); + ( elapsedTime_ * ai_->vesselObject()->rotFriction() * ai_->vesselObject()->moveable()->roll() ); float val = max( -1.0f, scaledVal ); val = min( val, 1.0f ); if ( fabs( val ) < 0.1 ) return false; - ai_->sectorObject()->setScaledRoll( val ); + ai_->vesselObject()->setScaledRoll( val ); return true; } else return false; } -void AiCommandRoll::stop(){ if ( ai_->sectorObject( ) ) ai_->sectorObject()->setScaledPitch( 0.0 ); } +void AiCommandRoll::stop(){ if ( ai_->vesselObject( ) ) ai_->vesselObject()->setScaledPitch( 0.0 ); } void AiCommandSetThrust::start() { - if ( ai_->sectorObject( ) ) { - ai_->sectorObject( )->setThrustRate( thrustRate_ ); + if ( ai_->vesselObject( ) ) { + ai_->vesselObject( )->setThrustRate( thrustRate_ ); } } void AiCommandTimedAccelerate::start() { std::cout << "AiCommandTimedAccelerate start" << std::endl; - if ( ai_->sectorObject( ) ) { - ai_->sectorObject( )->setThrustRate( rate_ ); - initPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + if ( ai_->vesselObject( ) ) { + ai_->vesselObject( )->setThrustRate( rate_ ); + initPos_ = ai_->vesselObject( )->mainNode()->getWorldPosition(); } } void AiCommandTimedAccelerate::stop() { std::cout << "AiCommandTimedAccelerate stop" << std::endl; - if ( ai_->sectorObject( ) ){ - ai_->sectorObject( )->setThrustRate( 0.0 ); + if ( ai_->vesselObject( ) ){ + ai_->vesselObject( )->setThrustRate( 0.0 ); std::cout << " reclined way(real): " - << (ai_->sectorObject( )->mainNode()->getWorldPosition()- initPos_).length() << std::endl; + << (ai_->vesselObject( )->mainNode()->getWorldPosition()- initPos_).length() << std::endl; std::cout << " reclined way(ana): " << ai_->wayAfterTime( runtime_, rate_ ) << std::endl; } @@ -249,27 +250,27 @@ void AiCommandAccelerate::start(){ std::cout << "AiCommandAccelerate::start()" << std::endl; - if ( ai_->sectorObject( ) ) { - ai_->sectorObject( )->setThrustRate( thrustRate_ ); - lastSpeed_ = ai_->sectorObject( )->speed(); - initPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); + if ( ai_->vesselObject( ) ) { + ai_->vesselObject( )->setThrustRate( thrustRate_ ); + lastSpeed_ = ai_->vesselObject( )->speed(); + initPos_ = ai_->vesselObject( )->mainNode()->getWorldPosition(); } } bool AiCommandAccelerate::update(){ - if ( ai_->sectorObject( ) ) { + if ( ai_->vesselObject( ) ) { // std::cout << "AiCommandAccelerate::update() " -// << speed_ << " " << ai_->sectorObject( )->speed() << std::endl; +// << speed_ << " " << ai_->vesselObject( )->speed() << std::endl; if ( speed_ < 0.0 && - ( ai_->sectorObject( )->speed() < speed_ || ai_->sectorObject( )->speed() > lastSpeed_ ) ) { + ( ai_->vesselObject( )->speed() < speed_ || ai_->vesselObject( )->speed() > lastSpeed_ ) ) { // std::cout << " - speed reached " <<std::endl; return false; } - if ( speed_ > 0.0 && ai_->sectorObject( )->speed() > speed_ ) { + if ( speed_ > 0.0 && ai_->vesselObject( )->speed() > speed_ ) { // std::cout << " + speed reached " <<std::endl; return false; } - lastSpeed_ = ai_->sectorObject( )->speed(); + lastSpeed_ = ai_->vesselObject( )->speed(); } else { return false; } @@ -277,9 +278,9 @@ } void AiCommandAccelerate::stop(){ std::cout << "AiCommandAccelerate::stop" << std::endl; - if ( ai_->sectorObject( ) ) ai_->sectorObject( )->setThrustRate( 0.0 ); + if ( ai_->vesselObject( ) ) ai_->vesselObject( )->setThrustRate( 0.0 ); std::cout << " reclined way(real): " - << (ai_->sectorObject( )->mainNode()->getWorldPosition()- initPos_).length() << std::endl; + << (ai_->vesselObject( )->mainNode()->getWorldPosition()- initPos_).length() << std::endl; std::cout << " reclined way(ana): " << ai_->wayAfterTime( runtime_, thrustRate_ ) << std::endl; } @@ -287,9 +288,9 @@ void AiCommandApproach::start(){ std::cout << "AiCommandApproach::start():" << std::endl; - if ( ai_->sectorObject( ) ) { - startPos_ = ai_->sectorObject( )->mainNode()->getWorldPosition(); - initDist_ = ( pos_ - ai_->sectorObject( )->mainNode()->getWorldPosition() ).length(); + if ( ai_->vesselObject( ) ) { + startPos_ = ai_->vesselObject( )->mainNode()->getWorldPosition(); + initDist_ = ( pos_ - ai_->vesselObject( )->mainNode()->getWorldPosition() ).length(); std::cout << "ai pos: " << startPos_ << std::endl; std::cout << "dist: " << initDist_ << std::endl; std::cout << "target: " << pos_ << std::endl; @@ -302,15 +303,15 @@ // addCommand( new AiCommandWait( ai_, 10.0 ) ); } bool AiCommandApproach::update(){ - if ( ai_->sectorObject( ) ) { - double dist = ( pos_ - ai_->sectorObject( )->mainNode()->getWorldPosition() ).length(); + if ( ai_->vesselObject( ) ) { + double dist = ( pos_ - ai_->vesselObject( )->mainNode()->getWorldPosition() ).length(); - if ( ai_->brakingDistance( ai_->sectorObject( )->speed() ) > dist ){ + if ( ai_->brakingDistance( ai_->vesselObject( )->speed() ) > dist ){ addCommand( new AiCommandStop( ai_, false ) ); return true; } - if ( ai_->sectorObject( )->speed() < 0.05 ){ + if ( ai_->vesselObject( )->speed() < 0.05 ){ std::cout << "dist: " << dist << std::endl; if ( dist < 10.0 ) { // 10m snapping return false; @@ -330,13 +331,13 @@ void AiCommandApproach::stop(){ std::cout << "AiCommandApproach::stop():" << std::endl; - if ( ai_->sectorObject( ) ) { - ai_->sectorObject( )->setThrustRate( 0.0 ); - std::cout << "ai pos: " << ai_->sectorObject( )->mainNode()->getWorldPosition() << std::endl; - std::cout << "dir: " << -ai_->sectorObject( )->mainNode()->getWorldOrientation().zAxis() + if ( ai_->vesselObject( ) ) { + ai_->vesselObject( )->setThrustRate( 0.0 ); + std::cout << "ai pos: " << ai_->vesselObject( )->mainNode()->getWorldPosition() << std::endl; + std::cout << "dir: " << -ai_->vesselObject( )->mainNode()->getWorldOrientation().zAxis() << std::endl; std::cout << "pos: " - << startPos_ + initDist_ * -ai_->sectorObject( )->mainNode()->getWorldOrientation().zAxis() + << startPos_ + initDist_ * -ai_->vesselObject( )->mainNode()->getWorldOrientation().zAxis() << std::endl; } Modified: trunk/src/AiCommands.h =================================================================== --- trunk/src/AiCommands.h 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/AiCommands.h 2008-05-04 12:13:52 UTC (rev 888) @@ -46,7 +46,9 @@ public: AiCommand( AiObject * ai ) : ai_( ai ), abort_( false ), running_( false ), runtime_( 0.0 ), elapsedTime_ ( 0.0 ){} - virtual ~AiCommand(){} + virtual ~AiCommand(){ + for_each( cmdQueue_.begin(), cmdQueue_.end(), deletePtr() ); cmdQueue_.clear(); + } virtual bool update( double elapsedTime ){ elapsedTime_ = elapsedTime; @@ -58,17 +60,17 @@ } nr_++; if ( abort_ ){ - if ( !cmds_.empty() ){ - cmds_.front()->abort(); + if ( !cmdQueue_.empty() ){ + cmdQueue_.front()->abort(); } stop(); return false; } - if ( !cmds_.empty() ){ - if ( !cmds_.front()->update( elapsedTime_ ) ){ - delete cmds_.front(); - cmds_.pop_front(); + if ( !cmdQueue_.empty() ){ + if ( !cmdQueue_.front()->update( elapsedTime_ ) ){ + delete cmdQueue_.front(); + cmdQueue_.pop_front(); } } else if ( !update( ) ) { stop(); @@ -83,7 +85,7 @@ virtual bool update( ) { return false; } virtual void stop() { std::cout << "AiCommand stop" << std::endl; } - void addCommand( AiCommand * cmd ) { cmds_.push_back( cmd ); } + void addCommand( AiCommand * cmd ) { cmdQueue_.push_back( cmd ); } protected: AiObject * ai_; @@ -92,7 +94,7 @@ double runtime_; double elapsedTime_; uint nr_; - std::deque< AiCommand * > cmds_; + std::deque< AiCommand * > cmdQueue_; }; class AiCommandSelfDestruct : public AiCommand { Modified: trunk/src/AiManager.cpp =================================================================== --- trunk/src/AiManager.cpp 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/AiManager.cpp 2008-05-04 12:13:52 UTC (rev 888) @@ -23,7 +23,8 @@ #include "common.h" #include "ResourceManager.h" -#include "SectorObjects.h" +#include "VesselManager.h" +#include "SectorObjectVessel.h" #include "Sector.h" #include "UnDockedState.h" #include "GameStateManager.h" @@ -103,14 +104,15 @@ } AiObject * ai = createAiObject( name ); - SectorObjectMoveableLocal *obj = NULL; + SectorObjectVessel *obj = NULL; if ( resources_ ){ if ( resources_->gameStateRoot->activeState( )->name() == "UnDockedState" ){ obj = dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() )->sector()-> - createMoveableObjectLocal( ai->name(), - resources_->network->userID(), ai->id(), - *VesselManager::getSingleton().vessel( "apteryx" ) ); + createVessel( ai->name(), + resources_->network->userID(), 0, + *VesselManager::getSingleton().vessel( "apteryx" ) ); + obj->vessel( )->setPowerPlant( EquipmentManager::getSingleton().powerPlant( "Spud" ) ); obj->vessel( )->setEngine( EquipmentManager::getSingleton().engine( "T-E-15" ) ); obj->vessel( )->setRadar( EquipmentManager::getSingleton().radar( "Outlook" ) ); @@ -122,7 +124,7 @@ } } //-250, 0, 500 - ai->setSectorObject( obj ); + ai->setVesselObject( obj ); Ogre::Real xmin = -150.0, xmax = -200.0; Ogre::Real ymin = 0.0, ymax = 100.0; Ogre::Real zmin = 300.0, zmax = 400.0; @@ -171,7 +173,7 @@ void AiManager::eraseAiObject( AiObject * ai ){ boost::mutex::scoped_lock lock( eraseMutex_ ); - SectorObjectMoveableLocal *obj = ai->sectorObject( ); + SectorObjectVessel *obj = ai->vesselObject( ); if ( obj ){ __D( obj->name() ) obj->destroy(); } Modified: trunk/src/AiManager.h =================================================================== --- trunk/src/AiManager.h 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/AiManager.h 2008-05-04 12:13:52 UTC (rev 888) @@ -32,7 +32,7 @@ namespace OpenGate{ class ResourceManager; -class SectorObjectMoveableLocal; +class SectorObjectVessel; class AiManager; class AiObject; Modified: trunk/src/AiObject.cpp =================================================================== --- trunk/src/AiObject.cpp 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/AiObject.cpp 2008-05-04 12:13:52 UTC (rev 888) @@ -22,7 +22,9 @@ #include "common.h" #include "AiObject.h" #include "AiCommands.h" -#include "SectorObjects.h" +#include "SectorObjectVessel.h" +#include "Moveable.h" +#include "Vessel.h" #include "Sector.h" #include "Station.h" @@ -34,7 +36,7 @@ namespace OpenGate{ -AiObject::AiObject( uint id ) : id_( id ), sectorObject_( NULL ){ +AiObject::AiObject( uint id ) : id_( id ), vesselObject_( NULL ){ livetime_ = new Ogre::Timer(); reset(); } @@ -67,12 +69,13 @@ isAlive_ = true; die_ = false; activeCmd_ = NULL; + for_each( cmdQueue_.begin(), cmdQueue_.end(), deletePtr() ); cmdQueue_.clear(); } -void AiObject::setSectorObject( SectorObjectMoveableLocal * obj ){ - sectorObject_ = obj; +void AiObject::setVesselObject( SectorObjectVessel * obj ){ + vesselObject_ = obj; if ( obj ){ - sectorObject_->setControler( this ); + vesselObject_->setControler( this ); } } @@ -226,16 +229,16 @@ double AiObject::maxSpeed( double thrustRate ) const { //** vmax(th,d):=sqrt( th/d ) ** P - double d = sectorObject_->vessel()->dragFactor(); - double th = sectorObject_->maxThrust() * thrustRate; + double d = vesselObject_->moveable()->dragFactor(); + double th = vesselObject_->maxThrust() * thrustRate; return sqrt( th / d ); } double AiObject::speedAfterTime( double time, double thrustRate ) const { //** v[ t ] := vmax * tanh( th / m / vmax * t ) ** P - double d = sectorObject_->vessel()->dragFactor(); - double m = sectorObject_->mass(); - double th = sectorObject_->maxThrust() * thrustRate; + double d = vesselObject_->vessel()->dragFactor(); + double m = vesselObject_->mass(); + double th = vesselObject_->maxThrust() * thrustRate; double vmax = maxSpeed( thrustRate ); double v = vmax * std::tanh( th / m / vmax * time ); // std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; vmax: " << vmax << "; t: " << time @@ -247,9 +250,9 @@ //** v[ t ] := vmax * tanh( th / m / vmax * t ) //** s[t]:=integrate(v[t], t) //** s = vmax^2/a * log( cosh( a / vmax * t ) ) ** P - double d = sectorObject_->vessel()->dragFactor(); - double m = sectorObject_->mass(); - double th = sectorObject_->maxThrust() * thrustRate; + double d = vesselObject_->vessel()->dragFactor(); + double m = vesselObject_->mass(); + double th = vesselObject_->maxThrust() * thrustRate; double vmax = maxSpeed( thrustRate ); double a = th / m; double s = ( vmax * vmax ) / a * std::log( std::cosh( a / vmax * time ) ); @@ -258,9 +261,9 @@ return s; } double AiObject::brakingTime( double v ) const { - double d = sectorObject_->vessel()->dragFactor(); - double m = sectorObject_->mass(); - double a = sectorObject_->brakingAcc(); + double d = vesselObject_->vessel()->dragFactor(); + double m = vesselObject_->mass(); + double a = vesselObject_->brakingAcc(); double th = m * a; //std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; v: " << v << "; t: " << time << std::endl; double t = ( m * atan( ( d * v ) / sqrt( a * d * m ) ) ) / sqrt( a * d * m ); //see physics.m @@ -268,9 +271,9 @@ } double AiObject::brakingDistance( double v ) const { - double d = sectorObject_->vessel()->dragFactor(); - double m = sectorObject_->mass(); - double a = sectorObject_->brakingAcc(); + double d = vesselObject_->vessel()->dragFactor(); + double m = vesselObject_->mass(); + double a = vesselObject_->brakingAcc(); double th = m * a; double t = brakingTime( v ); @@ -284,9 +287,9 @@ double AiObject::timeToSpeed( double v, double thrustRate ) const { //** t(th,d,m,v):=( m * atanh( v / vmax ) ) / sqrt( d * th ) - double d = sectorObject_->vessel()->dragFactor(); - double m = sectorObject_->mass(); - double th = sectorObject_->maxThrust() * thrustRate; + double d = vesselObject_->vessel()->dragFactor(); + double m = vesselObject_->mass(); + double th = vesselObject_->maxThrust() * thrustRate; double vmax = maxSpeed( thrustRate ); v = min( v, 0.99 * vmax ); Modified: trunk/src/AiObject.h =================================================================== --- trunk/src/AiObject.h 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/AiObject.h 2008-05-04 12:13:52 UTC (rev 888) @@ -38,7 +38,7 @@ namespace OpenGate{ class ResourceManager; -class SectorObjectMoveableLocal; +class SectorObjectVessel; class StationObject; class AiManager; class AiObject; @@ -57,10 +57,10 @@ virtual void run(); /*! Set the instance which is controled by this ai */ - void setSectorObject( SectorObjectMoveableLocal * obj ); + void setVesselObject( SectorObjectVessel * obj ); /*! Get the instance which is controled by this ai */ - inline SectorObjectMoveableLocal * sectorObject( ){ return sectorObject_; } + inline SectorObjectVessel * vesselObject( ){ return vesselObject_; } bool isAlive() const { return isAlive_; } @@ -117,7 +117,7 @@ void copy_( const AiObject & ai ); //! the graphical representation - SectorObjectMoveableLocal * sectorObject_; + SectorObjectVessel * vesselObject_; std::deque< AiCommand * > cmdQueue_; Modified: trunk/src/Avatar.cpp =================================================================== --- trunk/src/Avatar.cpp 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/Avatar.cpp 2008-05-04 12:13:52 UTC (rev 888) @@ -20,6 +20,7 @@ #include "Avatar.h" #include "VesselManager.h" +#include "Equipment.h" namespace OpenGate{ Modified: trunk/src/Avatar.h =================================================================== --- trunk/src/Avatar.h 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/Avatar.h 2008-05-04 12:13:52 UTC (rev 888) @@ -59,16 +59,16 @@ bool loadItem( Entity * item ); bool unLoadItem( Entity * item ); - + protected: - std::string name_; - Uint32 id_; + std::string name_; + Uint32 id_; - Vessel * vessel_; - - Uint16 maxCargoHold_; - Uint16 cargoHold_; - std::list< std::deque < Entity * > > floorCargo_; + Vessel * vessel_; + + Uint16 maxCargoHold_; + Uint16 cargoHold_; + std::list< std::deque < Entity * > > floorCargo_; }; } // namespace OpenGate{ Added: trunk/src/BaseObject.cpp =================================================================== --- trunk/src/BaseObject.cpp (rev 0) +++ trunk/src/BaseObject.cpp 2008-05-04 12:13:52 UTC (rev 888) @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2006-2007 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "BaseObject.h" +#include "Sector.h" + +#include <OgreEntity.h> + +#include <string> + +namespace OpenGate{ + +BaseObject::BaseObject( const Ogre::String & name, Sector * sector, Uint32 userID, Uint8 childID ) + : name_( name ), sector_( sector ), userID_( userID ), childID_( childID ), mainNode_( NULL ){ + globalID_ = createGlobalID( userID, childID ); + + sceneMgr_ = sector_->sceneManager(); + try{ + mainNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( name + "_MainNode" ); + } catch( Ogre::Exception & e ) { + LogManager::getSingleton().fatal( e.getFullDescription() ); + } + + destroyRequest_ = false; + lifeTime_ = 0.0; + selectable_ = false; + collObj_ = NULL; +} + +BaseObject::~BaseObject(){ + sceneMgr_->getRootSceneNode()->removeAndDestroyChild( mainNode_->getName() ); +} + + +} // namespace OpenGate Added: trunk/src/BaseObject.h =================================================================== --- trunk/src/BaseObject.h (rev 0) +++ trunk/src/BaseObject.h 2008-05-04 12:13:52 UTC (rev 888) @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (C) 2006-2007 by OpenGate development team * + * spo...@us... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _OPENGATE_BASEOBJECT__H +#define _OPENGATE_BASEOBJECT__H + +//#include <OgrePrerequisites.h> + +#include "common.h" + +#include <OgreSceneNode.h> + +namespace OgreOpcode{ + class CollisionObject; +} + +namespace OpenGate{ + +#define PROJECTILE_RTTI 100001 +#define SECTOROBJECT_RTTI 100002 +#define SECTOROBJECTMOVABLE_RTTI 100003 +#define SECTOROBJECTVESSEL_RTTI 100004 +#define SECTOROBJECTMISSILE_RTTI 100005 +#define AVATAR_RTTI 100006 +#define DOCKPAD_RTTI 100007 +#define STATIONPAD_RTTI 100008 +#define STATION_RTTI 100009 + +class Sector; + +class BaseObject{ +public: + BaseObject( const Ogre::String & name, Sector * sector, Uint32 userId = 0, Uint8 childId = 0 ); + + virtual ~BaseObject(); + + virtual long rtti() const = 0; + + virtual void collide( BaseObject * object ) = 0; + + inline virtual Uint32 userID() const { return userID_; } + + inline virtual Uint8 childID() const { return childID_; } + + inline virtual Uint32 globalID() const { return globalID_; } + + virtual bool isChild() const { return childID_ > 0; } + + Ogre::String name() const { return name_; } + + inline Ogre::SceneNode * mainNode() { return mainNode_; } + + inline Ogre::SceneNode mainNode() const { return *mainNode_; } + + virtual bool update( Ogre::Real elapsedTime ) = 0; + + virtual void hitByAmmo( Uint32 damage ){} + + Sector * sector( ) { return sector_; } + + virtual Ogre::Vector3 velocity() const { return Ogre::Vector3::ZERO; } + + bool selectable() const { return selectable_ ;} + + void setSelectable( bool selectable ) { selectable_ = selectable; } + + Ogre::Vector3 position() const; + + /*! Mark the object for destruction. + To keep destruction thread safe, we just notify and let the update cycle do the job */ + void destroy() { destroyRequest_ = true; } + + bool isSetDestroyRequest() const { return destroyRequest_; } + +protected: + Ogre::String name_; + Sector * sector_; + Uint32 userID_; + Uint8 childID_; + Uint32 globalID_; + + Ogre::SceneNode * mainNode_; + + bool selectable_; + Ogre::SceneManager * sceneMgr_; + OgreOpcode::CollisionObject * collObj_; + Ogre::Real lifeTime_; + bool destroyRequest_; +}; + +} //namespace OpenGate + +#endif + + Modified: trunk/src/Entity.h =================================================================== --- trunk/src/Entity.h 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/Entity.h 2008-05-04 12:13:52 UTC (rev 888) @@ -45,390 +45,113 @@ class Entity{ public: + Entity(); - Entity(); + virtual ~Entity(){ } - virtual ~Entity(){ } - - virtual EntityType entityType() const { return rtti_; } + virtual EntityType entityType() const { return rtti_; } - inline std::string factionName( ) const { return factionName_; } + inline std::string factionName( ) const { return factionName_; } - void setFactionID( int id ); - inline int factionID( ) const { return factionID_; } + void setFactionID( int id ); + inline int factionID( ) const { return factionID_; } - inline void setName( const std::string & name ) { name_ = name; } - inline std::string name( ) const { return name_; } + inline void setName( const std::string & name ) { name_ = name; } + inline std::string name( ) const { return name_; } - inline void setClassName( const std::string & name ) { className_ = name; } - inline std::string className( ) const { return className_; } + inline void setClassName( const std::string & name ) { className_ = name; } + inline std::string className( ) const { return className_; } - inline void setID( int id ){ id_ = id; } - inline int id( ) const { return id_; } + inline void setID( int id ){ id_ = id; } + inline int id( ) const { return id_; } - void setBaseSize( float length, float width, float height ); + /*! Base sizes are necessary for resizing the ogremesh */ + void setBaseSize( float length, float width, float height ); - /*! If size is a scalar value, the length of the entity. */ - void setBaseSize( float size ); + /*! If size is a scalar value, the length of the entity.*/ + void setBaseSize( float size ); + Ogre::Vector3 baseSize( ) const; - Ogre::Vector3 baseSize( ) const; + /*! Base sizes are necessary for resizing the ogremesh */ + inline void setBaseYaw( Ogre::Real baseYaw ){ baseYaw_ = baseYaw; } + inline Ogre::Real baseYaw( ) const { return baseYaw_; } - inline void setBaseYaw( Ogre::Real baseYaw ){ baseYaw_ = baseYaw; } - inline Ogre::Real baseYaw( ) const { return baseYaw_; } + /*! Base sizes are necessary for resizing the ogremesh */ + inline void setBasePitch( Ogre::Real basePitch ){ basePitch_ = basePitch; } + inline Ogre::Real basePitch( ) const { return basePitch_; } - inline void setBasePitch( Ogre::Real basePitch ){ basePitch_ = basePitch; } - inline Ogre::Real basePitch( ) const { return basePitch_; } + /*! Base sizes are necessary for resizing the ogremesh */ + inline void setBaseRoll( Ogre::Real baseRoll ){ baseRoll_ = baseRoll; } + inline Ogre::Real baseRoll( ) const { return baseRoll_; } - inline void setBaseRoll( Ogre::Real baseRoll ){ baseRoll_ = baseRoll; } - inline Ogre::Real baseRoll( ) const { return baseRoll_; } + inline void setTechLevel( int level ){ techLevel_ = level; } + inline int techLevel( ) const { return techLevel_; } - inline void setTechLevel( int level ){ techLevel_ = level; } - inline int techLevel( ) const { return techLevel_; } + inline void setMass( long mass ){ mass_ = mass; } + inline Uint32 mass( ) const { return mass_; } - inline void setMass( long mass ){ mass_ = mass; } - inline Uint32 mass( ) const { return mass_; } + inline void setSize( int size ){ size_ = size; } + inline int size( ) const { return size_; } - inline void setSize( int size ){ size_ = size; } - inline int size( ) const { return size_; } + inline void setDescription( const std::string & description ){ description_ = description; } + inline std::string description( ) const { return description_; } - inline void setDescription( const std::string & description ){ description_ = description; } - inline std::string description( ) const { return description_; } + inline void setImageName( const std::string & imageFileName ) { imageFileName_ = imageFileName; } + inline std::string imageName() const { return imageFileName_; } + inline std::string ceguiImageName() { if ( !imageInitialised_ ) loadImages_(); return ceguiImageName_; } + inline std::string ceguiSmallImageName() { if ( !imageInitialised_ ) loadImages_(); return ceguiSmallImageName_; } - inline void setImageName( const std::string & imageFileName ) { imageFileName_ = imageFileName; } - inline std::string imageName() const { return imageFileName_; } - inline std::string ceguiImageName() { if ( !imageInitialised_ ) loadImages_(); return ceguiImageName_; } - inline std::string ceguiSmallImageName() { if ( !imageInitialised_ ) loadImages_(); return ceguiSmallImageName_; } + bool initialiseImage( const std::string & imageName, const std::string & targetName, bool verbose = false ); - bool initialiseImage( const std::string & imageName, const std::string & targetName, bool verbose = false ); + inline void setProductionCenters( const std::set < std::string > & productionCenters ) { + productionCenters_ = productionCenters; } + inline std::set < std::string > productionCenters( ) const { return productionCenters_; } - inline void setProductionCenters( const std::set < std::string > & productionCenters ) { - productionCenters_ = productionCenters; } - inline std::set < std::string > productionCenters( ) const { return productionCenters_; } + inline void setRequieredComponents( const std::set < Commodity * > & requieredComponents ) { + requieredComponents_ = requieredComponents; } + inline std::set < Commodity * > requieredComponents( ) const { return requieredComponents_; } - inline void setRequieredComponents( const std::set < Commodity * > & requieredComponents ) { - requieredComponents_ = requieredComponents; } - inline std::set < Commodity * > requieredComponents( ) const { return requieredComponents_; } - protected: - inline void setFactionName_( const std::string & name ) { factionName_ = name; } - void loadImages_( ); + inline void setFactionName_( const std::string & name ) { factionName_ = name; } + void loadImages_( ); - std::string name_; - std::string className_; - /*! A rather long description of this component */ - std::string description_; - - std::string factionName_; - int factionID_; - - //** geometric parameters - Ogre::Vector3 baseSize_; - Ogre::Real baseYaw_; - Ogre::Real basePitch_; - Ogre::Real baseRoll_; - - std::string imageFileName_; - std::string ceguiSmallImageName_; - std::string ceguiImageName_; - bool imageInitialised_; - - /*! The places where this part of equipment is built */ - std::set < std::string > productionCenters_; - - /*! The components required to build this equipment part */ - std::set < Commodity * > requieredComponents_; - - /*! A unique ID to find this object \todo maybe push to a string and merge with Commodity.commodityID_ */ - Uint16 id_; - /*! The required tech level to interact with this object */ - int techLevel_; - /*! The mass of this entity. */ - Uint32 mass_; - /*! The amount of slots necessary to plug in such a device. */ - int size_; - - /*! For runtime identification of an entity item. */ - EntityType rtti_; -}; - -/** - * \brief This abstract class defines the basics for Eqiupment that is plugged - * into a vessel. - * - * So if you plug in an engine (which is a child class of this) you plug in an - * equipment part. It has power consumption etc. This class only - * defines whatever is common for all equipments parts. - * - * \author Christoph Brill <eg...@us...> - */ - -class Equipment : public Entity{ -public: - - inline void setManufacturer( const std::string & manufacturer ) { manufacturer_ = manufacturer; } - inline std::string manufacturer( ) const { return manufacturer_; } - - /*! Sets the Efficiency of this Equipment between 0(min) and 1(max) */ - inline void setEfficiency( double efficiency ) { efficiency_ = efficiency; } - inline double efficiency( ) const { return efficiency_; } - - virtual void setPowerConsumption( Uint32 powerConsumption ) { - powerConsumption_ = powerConsumption; - //** if input power is < 1000, then input is scaled in kW - if ( powerConsumption_ < 1e3 ) powerConsumption_ *= 1000; - } - virtual Uint32 powerConsumption( ) const { return powerConsumption_; } - -protected: - Equipment() : Entity(), manufacturer_( "unkown" ) { - size_ = 0; - efficiency_ = 1.0; - powerConsumption_ = 0; - } - - virtual ~Equipment() { } - - /*! Name of the company that produces this equipment */ - std::string manufacturer_; - - /*! Stores the efficiency of this equipment */ - double efficiency_; - - /*! Stores the power consumption of this equipment */ - Uint32 powerConsumption_; -}; - -/*! - * \brief This class stores the basical information of a PowerPlant - * - * This class, like all other equipment classes, is filled by loading the - * information from an XML file. It defines the details for a PowerPlant, which - * is a component that is plugged into the ship. - * \author Christoph Brill <eg...@us...> - */ -class PowerPlant : public Equipment { -public: - PowerPlant() : Equipment(){ - rtti_ = POWERPLANT; - powerOutput_ = 0; - } - inline void setPowerOutput( Uint32 power ) { - powerOutput_ = power; - //** if input power is < 100kW, then input is scaled in kW - if ( powerOutput_ < 1e5 ) powerOutput_ *= 1000; - } - inline Uint32 powerOutput( ) const { return powerOutput_; } - -protected: - Uint32 powerOutput_; -}; - -/*! - * \brief This class stores the basical information of an engine - * - * This class, like all other equipment classes, is filled by loading the - * information from an XML file. It defines the details for an engine, which - * is a component that is plugged into the ship. - * \author Christoph Brill <eg...@us...> - */ -class Engine : public Equipment { -public: - - Engine() : Equipment() { - rtti_ = ENGINE; - maxThrust_ = 0; - } - - inline void setMaxThrust( Uint32 maxThrust ) { - maxThrust_ = maxThrust; - //** if input thrust is < 100kN, then input is scaled in kN - if ( maxThrust_ < 1e5 ) maxThrust_ *= 1000; - } - inline Uint32 maxThrust( ) { return maxThrust_; } - - virtual Uint32 powerConsumption( ) const { return (Uint32)rint( (float)maxThrust_ / efficiency_ ); } - -private: - /*! Stores the maximum thrust of this engine */ - Uint32 maxThrust_; -}; - -/*! - * \brief This class stores the basical information of a radar - * - * This class, like all other equipment classes, is filled by loading the - * information from an XML file. It defines the details for a radar, which - * is a component that is plugged into the ship. - * \author Christoph Brill <eg...@us...> - */ -class Radar : public Equipment { -public: - Radar() : Equipment(){ - rtti_ = RADAR; - } - inline void setMaxRange( Uint32 range ){ range_ = range; } - inline Uint32 maxRange() const{ return range_; } - -protected: - Uint32 range_; -}; - -/*! - * \brief This class stores the basical information of an Ecm (Evasion and Counter Measures) - * - * This class, like all other equipment classes, is filled by loading the - * information from an XML file. It defines the details for a Ecm, which - * is a component that is plugged into the ship. - * \author Christoph Brill <eg...@us...> - */ -class Ecm : public Equipment{ -public: - - Ecm() : Equipment() { - rtti_ = ECM; - sensorLevel_ = 0; - } - - inline void setSensorLevel( short sensorLevel ) { sensorLevel_ = sensorLevel; } - inline short sensorLevel( ) { return sensorLevel_; } - -private: - /*! Stores the sensorlevel of this Ecm */ - short sensorLevel_; -}; - -/*! - * \brief This class stores the basical information of a Shield - * - * This class, like all other equipment classes, is filled by loading the - * information from an XML file. It defines the details for a shield, which - * is a component that is plugged into the ship. - * \author Christoph Brill <eg...@us...> - */ -class Shield : public Equipment { -public: - Shield() : Equipment(){ - rtti_ = SHIELD; - } - - inline void setMaxDeflection( Uint32 deflection ){ - setMaximumDeflection_ = deflection; - //** if input deflection is < 100kJ, then input is scaled in kJ - if ( setMaximumDeflection_ < 1e5 ) setMaximumDeflection_ *= 1000; - } - inline Uint32 maxDeflection( ) const { return setMaximumDeflection_; } - - inline void setRegenerationRate( Uint32 regenRate ){ - regenerationRate_ = regenRate; - //** if input regeneration rate is < 10kJ, then input is scaled in kJ - if ( regenerationRate_ < 1e4 ) regenerationRate_ *= 1000; - } - inline Uint32 regenerationRate( ) const { return regenerationRate_; } - - inline Uint32 powerConsumption( ) const { return (Uint32) rint( regenerationRate_ / efficiency_ ); } - -protected: - Uint32 regenerationRate_; - Uint32 setMaximumDeflection_; -}; - -/*! - * \brief This class stores the basical information of a capactitor - * - * This class, like all other equipment classes, is filled by loading the - * information from an XML file. It defines the details for a capacitor, which - * is a component that is plugged into the ship. - * \author Christoph Brill <eg...@us...> - */ -class Capacitor : public Equipment{ -public: - - Capacitor() : Equipment() { - rtti_ = CAPACITOR; - capacity_ = 0; - } - - inline void setCapacity( Uint32 capacity ) { - capacity_ = capacity; - //** if input capacity is < 100kJ, then input is scaled in kJ - if ( capacity_ < 1e5 ) capacity_ *= 1000; - } - inline Uint32 capacity( ) { return capacity_; } - -private: - /*! Stores the capacity of a capacitor */ - Uint32 capacity_; -}; - -class Gun : public Equipment{ -public: - Gun(): Equipment(){ - rtti_ = GUN; - type_ = UNKNOWN; - } - - inline void setType( GunType type ) { type_ = type; } - inline GunType type() const { return type_; } - - inline void setEnergy( Uint32 energy ){ - powerConsumption_ = energy; if ( powerConsumption_ < 1e4 ) powerConsumption_ *= 1000; } + std::string name_; + std::string className_; - inline void setDamage( Uint32 damage ) { - damage_ = damage; if ( damage_ < 1e4 ) damage_ *= 1000; } + /*! A rather long description of this component */ + std::string description_; - inline Uint32 damage( ) const { return damage_; } + std::string factionName_; + int factionID_; - inline void setSpeed( Uint32 speed ) { speed_ = speed; } - inline Uint32 speed() const { return speed_; } + //** geometric parameters + Ogre::Vector3 baseSize_; + Ogre::Real baseYaw_; + Ogre::Real basePitch_; + Ogre::Real baseRoll_; - inline void setLifeTime( Ogre::Real lifeTime ) { lifeTime_ = lifeTime; } - inline Ogre::Real lifeTime() const { return lifeTime_; }; + std::string imageFileName_; + std::string ceguiSmallImageName_; + std::string ceguiImageName_; + bool imageInitialised_; - inline void setFireDelay( Ogre::Real fireDelay ) { fireDelay_ = fireDelay; } - inline Ogre::Real fireDelay() const { return fireDelay_; } + /*! The places where this part of equipment is built */ + std::set < std::string > productionCenters_; -protected: - GunType type_; - Uint32 damage_; - Uint32 speed_; - Ogre::Real lifeTime_; - Ogre::Real fireDelay_; -}; + /*! The components required to build this equipment part */ + std::set < Commodity * > requieredComponents_; + /*! A unique ID to find this object \todo maybe push to a string and merge with Commodity.commodityID_ */ + Uint16 id_; + /*! The required tech level to interact with this object */ + int techLevel_; + /*! The mass of this entity. */ + Uint32 mass_; + /*! The amount of slots necessary to plug in such a device. */ + int size_; -/*! - * \brief This class defines a commodity (goods, ore, etc. to build stuff from) - * - * This class is handled like equipment. But since it's not plugable into a - * ship it's a seperate class. This stores some information about a commodity, - * like its mass, its melting point, etc. - * \author Christoph Brill <eg...@us...> - */ -class Commodity : public Entity{ -public: - - Commodity(): Entity(), commodityID_( "unknownID" ) { - rtti_ = COMMODITY; - meltingPoint_ = 0; - graviticSig_ = 0.0; - } - - inline void setMeltingPoint( int meltingPoint ){ meltingPoint_ = meltingPoint; } - inline int meltingPoint( ) const { return meltingPoint_; } - - inline void setGraviticSig( double graviticSig ){ graviticSig_ = graviticSig; } - inline double graviticSig( ) const { return graviticSig_; } - - inline void setCommodityID( const std::string & commodityID ) { commodityID_ = commodityID; } - inline std::string commodityID( ) const { return commodityID_; } - -protected: - /*! The unique name of this commodity \todo check if that can be merged with EntityTemlpate.id_ */ - std::string commodityID_; - /*! The specific melting point of this commodity */ - int meltingPoint_; - /*! The specific atomic wheight of this commodity */ - double graviticSig_; + /*! For runtime identification of an entity item. */ + EntityType rtti_; }; } // namespace OpenGate Modified: trunk/src/EntityManager.cpp =================================================================== --- trunk/src/EntityManager.cpp 2008-05-01 18:29:14 UTC (rev 887) +++ trunk/src/EntityManager.cpp 2008-05-04 12:13:52 UTC (rev 888) @@ -21,6 +21,9 @@ #include "EntityManager.h" #include "ResourceManager.h" #include "tinyxml/tinyxml.h" +#include "Vessel.h" +#include "Equipment.h" + #include <OgreArchive.h> #include <OgreArchiveManager.h> #include <OgreFileSystem.h> @@ -35,6 +38,55 @@ templatesByID_.end(); } +EntityType EntityManager::categoryType( const std::string & category ){ + if ( category == "Commodity" || category == "Commoditys" || + category == "commodity" || category == "commoditys" ) return COMMODITY; + else if ( category == "Power Plant" || category == "Power Plants" || + category == "Powerplant" || category == "Powerplants" || + category == "Power plant" || category == "Power plants" || + category == "powerplant" || category == "powerplants" ) return POWERPLANT; + else if ( category == "Engine" || category == "Engines" || + category == "engine" || category == "engines" ) return ENGINE; + else if ( category == "Radar" || category == "Radars" || + category == "radar" || category == "radars" ) return RADAR; + else if ( category == "ECM" || category == "ECMs" || + category == "Ecm" || category == "Ecms" || + category == "ecm" || category == "ecms" ) return ECM; + else if ( category == "Capacitor" || category == "Capacitors" || + category == "capacitor" || category == "capacitors" ) return CAPACITOR; + else if ( category == "Shield" || category == "Shields" || + category == "shield" || category == "shields" ) return SHIELD; + else if ( category == "Gun" || category == "Guns" || + category == "gun" || category == "guns" ) return GUN; + else if ( category == "Missile" || category == "Missiles" || + category == "missile" || category == "missiles" ) return MISSILE; + else if ( category == "MODX" || category == "MODXs" || + category == "MODx" || category == "MODxs" || + category == "modx" || category == "modxs" ) return MODX; + + LogManager::getSingleton().warn("Request entity rtti for " + category + " unknown" ); + return ENTITY; +} + + +Entity * EntityManager::entity( const std::string & name ){ + if ( templatesByName_.count( name ) ){ + return templatesByName_[ name ]; + } else { + ... [truncated message content] |
From: <spo...@us...> - 2008-05-11 11:57:57
|
Revision: 890 http://opengate.svn.sourceforge.net/opengate/?rev=890&view=rev Author: spom_spom Date: 2008-05-11 04:58:03 -0700 (Sun, 11 May 2008) Log Message: ----------- Further refactoring: started merging the several entitymanager, fixed some evel bugs Modified Paths: -------------- trunk/data/MediaFromOgre/AdvancedMaterials/Examples-Advanced.material trunk/data/ecms/ghost.xml trunk/data/guns/duster.xml trunk/data/guns/excavator.xml trunk/data/materials/planet.material trunk/data/misc/ids.xml trunk/data/misc/testsector.xml trunk/src/AiManager.cpp trunk/src/BaseObject.cpp trunk/src/BaseObject.h trunk/src/Entity.cpp trunk/src/Entity.h trunk/src/EntityManager.cpp trunk/src/EntityManager.h trunk/src/Equipment.h trunk/src/GameStateManager.cpp trunk/src/Makefile.am trunk/src/MarketDialog.cpp trunk/src/Moveable.cpp trunk/src/Moveable.h trunk/src/OpcodeWrapper.cpp trunk/src/OpcodeWrapper.h trunk/src/Projectile.cpp trunk/src/ResourceManager.cpp trunk/src/ResourceManager.h trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObject.cpp trunk/src/SectorObject.h trunk/src/SectorObjectAvatar.cpp trunk/src/SectorObjectAvatar.h trunk/src/SectorObjectMissile.cpp trunk/src/SectorObjectMissile.h trunk/src/SectorObjectMoveable.cpp trunk/src/SectorObjectMoveable.h trunk/src/SectorObjectVessel.cpp trunk/src/SectorObjectVessel.h trunk/src/ShipConfigDialog.cpp trunk/src/ShipConfigDialog.h trunk/src/Station.cpp trunk/src/UnDockedState.cpp trunk/src/Vessel.cpp trunk/src/Vessel.h trunk/src/common.h Added Paths: ----------- trunk/data/materials/missiles.material trunk/data/materials/station.cg trunk/data/missiles/bee.xml trunk/data/missiles/bee_big.png trunk/data/missiles/bee_small.png trunk/src/Equipment.cpp Modified: trunk/data/MediaFromOgre/AdvancedMaterials/Examples-Advanced.material =================================================================== --- trunk/data/MediaFromOgre/AdvancedMaterials/Examples-Advanced.material 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/data/MediaFromOgre/AdvancedMaterials/Examples-Advanced.material 2008-05-11 11:58:03 UTC (rev 890) @@ -1,74 +1,4 @@ -// ------------------------------- -// Cel Shading Section -// ------------------------------- -vertex_program Ogre/CelShadingVP cg -{ - source Example_CelShading.cg - entry_point main_vp - profiles vs_1_1 arbvp1 - default_params - { - param_named_auto lightPosition light_position_object_space 0 - param_named_auto eyePosition camera_position_object_space - param_named_auto worldViewProj worldviewproj_matrix - param_named shininess float 10 - } -} - -fragment_program Ogre/CelShadingFP cg -{ - source Example_CelShading.cg - entry_point main_fp - profiles ps_1_1 arbfp1 fp20 -} - - -material Examples/CelShading -{ - technique - { - pass - { - vertex_program_ref Ogre/CelShadingVP - { - // map shininess from custom renderable param 1 - param_named_auto shininess custom 1 - } - fragment_program_ref Ogre/CelShadingFP - { - // map diffuse from custom renderable param 2 - param_named_auto diffuse custom 2 - // map specular from custom renderable param 2 - param_named_auto specular custom 3 - } - texture_unit - { - texture cel_shading_diffuse.png 1d - tex_address_mode clamp - filtering none - } - texture_unit - { - texture cel_shading_specular.png 1d - tex_address_mode clamp - filtering none - tex_coord_set 1 - } - texture_unit - { - texture cel_shading_edge.png 1d - tex_address_mode clamp - filtering none - tex_coord_set 2 - } - } - } - -} - - - //------------------------ // Bump mapping section //------------------------ @@ -620,154 +550,7 @@ } -//---------------------------- -// Distortion effects -//---------------------------- -vertex_program Examples/FresnelRefractReflectVP cg -{ - source Example_Fresnel.cg - entry_point main_vp - profiles vs_1_1 arbvp1 -} -vertex_program Examples/FresnelRefractReflectVPold cg -{ - source Example_Fresnel.cg - entry_point main_vp_old - profiles vs_1_1 arbvp1 -} - -fragment_program Examples/FresnelRefractReflectFP cg -{ - source Example_Fresnel.cg - entry_point main_fp - // sorry, ps_1_1 and fp20 can't do this - profiles ps_2_0 arbfp1 -} - -fragment_program Examples/FresnelRefractReflectPS asm -{ - source Example_FresnelPS.asm - // sorry, only for ps_1_4 :) - syntax ps_1_4 - -} - -material Examples/FresnelReflectionRefraction -{ - // ps_2_0 / arbfp1 - technique - { - pass - { - - vertex_program_ref Examples/FresnelRefractReflectVP - { - param_named_auto worldViewProjMatrix worldviewproj_matrix - param_named_auto eyePosition camera_position_object_space - param_named_auto timeVal time 0.05 - param_named scroll float 1 - param_named scale float 1 - param_named noise float 1 - // scroll and noisePos will need updating per frame - } - fragment_program_ref Examples/FresnelRefractReflectFP - { - param_named fresnelBias float -0.1 - param_named fresnelScale float 1.8 - param_named fresnelPower float 8 - param_named tintColour float4 0 0.0.05 0.05 1 - param_named noiseScale float 0.05 - } - // Noise - texture_unit - { - // Perlin noise volume - texture waves2.dds - // min / mag filtering, no mip - filtering linear linear none - } - // Reflection - texture_unit - { - // Will be filled in at runtime - texture Reflection - tex_address_mode clamp - // needed by ps.1.4 - tex_coord_set 1 - } - // Refraction - texture_unit - { - // Will be filled in at runtime - texture Refraction - tex_address_mode clamp - // needed by ps.1.4 - tex_coord_set 2 - } - } - - - } - - // ATI 8500 + - technique - { - pass - { - vertex_program_ref Examples/FresnelRefractReflectVPold - { - param_named_auto worldViewProjMatrix worldviewproj_matrix - param_named_auto eyePosition camera_position_object_space - param_named fresnelBias float -0.3 - param_named fresnelScale float 1.4 - param_named fresnelPower float 8 - param_named_auto timeVal time_0_1 20 - param_named scroll float 1 - param_named scale float 4 - param_named noise float 1 - // scroll and noisePos will need updating per frame - } - - // for ATI RADEON 8500 - 9200 - fragment_program_ref Examples/FresnelRefractReflectPS - { - // distortionRange - param_indexed 0 float 0.025 - // tintColour - param_indexed 1 float4 0.05 0.12 0.15 1 - } - - // Noise - texture_unit - { - // Perlin noise volume - texture perlinvolume.dds 3d - // min / mag filtering, no mip - filtering linear linear none - } - // Reflection - texture_unit - { - // Will be filled in at runtime - texture Reflection - tex_address_mode clamp - // needed by ps.1.4 - tex_coord_set 1 - } - // Refraction - texture_unit - { - // Will be filled in at runtime - texture Refraction - tex_address_mode clamp - // needed by ps.1.4 - tex_coord_set 2 - } - } - } -} - // Normal-mapped Athene statue material Examples/Athene/NormalMapped { Modified: trunk/data/ecms/ghost.xml =================================================================== --- trunk/data/ecms/ghost.xml 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/data/ecms/ghost.xml 2008-05-11 11:58:03 UTC (rev 890) @@ -20,7 +20,7 @@ <!-- Specific data --> <sensorlevel>3</sensorlevel> - <power>970000</power> + <power_input>970000</power_input> <!-- Production Data --> <manufacturer>Amananth</manufacturer> Modified: trunk/data/guns/duster.xml =================================================================== (Binary files differ) Modified: trunk/data/guns/excavator.xml =================================================================== (Binary files differ) Added: trunk/data/materials/missiles.material =================================================================== --- trunk/data/materials/missiles.material (rev 0) +++ trunk/data/materials/missiles.material 2008-05-11 11:58:03 UTC (rev 890) @@ -0,0 +1,42 @@ +material Missile/Thruster +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.000000 0.000000 0.000000 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + } + } +} +material Missile/Nose +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.461176 0.018824 0.018824 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + } + } +} +material Missile/Hull +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 +// diffuse 0.480000 0.480000 0.480000 1.000000 +// specular 0.500000 0.500000 0.500000 1.000000 12.500000 +// emissive 0.000000 0.000000 0.000000 1.000000 + } + } +} Modified: trunk/data/materials/planet.material =================================================================== --- trunk/data/materials/planet.material 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/data/materials/planet.material 2008-05-11 11:58:03 UTC (rev 890) @@ -165,7 +165,8 @@ } texture_unit { - texture clouds_2500x1250.jpg + texture clouds_1275.jpg +// texture clouds_2500x1250.jpg } } } @@ -213,4 +214,4 @@ // set_texture_alias Image world.topo.200407.png // set_texture_alias ImageNormMap texture world.topo.200407Norm.png // set_texture_alias ImageSpecMap texture world.topo.200407Spec.png -} \ No newline at end of file +} Added: trunk/data/materials/station.cg =================================================================== --- trunk/data/materials/station.cg (rev 0) +++ trunk/data/materials/station.cg 2008-05-11 11:58:03 UTC (rev 890) @@ -0,0 +1,71 @@ +float3 expand( float3 v ) { return (v - 0.5) * 2; } + +struct vertexOutput { + float4 clipPos : POSITION; + float2 uv : TEXCOORD0; + float4 pos : TEXCOORD1; + float3 normal : TEXCOORD2; + float3 binormal : TEXCOORD3; + float3 tangent : TEXCOORD4; + float4 lightPos : TEXCOORD5; + float3 camPos : TEXCOORD6; + float3 tsLightDir : TEXCOORD7; +}; + +void main_vp( float4 objectPos : POSITION, + float2 uv : TEXCOORD0, + float3 normal : NORMAL, + float3 tangent : TANGENT, + out vertexOutput OUT, + uniform float4 lightPos, + uniform float3 camPos, + uniform float4x4 modelViewProjection) +{ + OUT.clipPos = mul( modelViewProjection, objectPos ); // position (view space) + OUT.uv = uv; + + OUT.pos = objectPos; + OUT.normal = normal; + OUT.tangent = tangent; + OUT.lightPos = lightPos; + OUT.camPos = camPos; + + float3 lightDir = lightPos.xyz - ( objectPos * lightPos.w ); + OUT.binormal = cross( tangent, normal ); + float3x3 rotation = float3x3( tangent, OUT.binormal, normal ); + OUT.tsLightDir = mul( rotation, lightDir ); +} + +float4 main_fp( vertexOutput IN, + uniform float exponent, + uniform float4 lightDiffuse, + uniform float4 lightSpecular, + uniform float4 lightAmbient, + uniform sampler2D decalTexture : TEXUNIT0, + uniform sampler2D normTexture : TEXUNIT1, + uniform sampler2D specTexture : TEXUNIT2, + uniform samplerCUBE normalCubeMap : TEXUNIT3 ) : COLOR { + + float3 lightDir = normalize( IN.lightPos.xyz - ( IN.pos * IN.lightPos.w ) ); + float3 camDir = normalize( IN.camPos - IN.pos.xyz ); + float3 halfAngle = normalize( lightDir ); + + float3 nN = normalize( IN.normal ); + float NdotL = dot( lightDir, nN ); + float NdotH = dot( halfAngle, nN ); + + //cg docs say using their lit function is the fastest + float4 Lit = lit( NdotL, NdotH, exponent ); + + float3 lightVec = expand( texCUBE( normalCubeMap, IN.tsLightDir ).xyz ); + + float3 n = expand( tex2D( normTexture, IN.uv ).xyz); + float4 d = tex2D( decalTexture, IN.uv ); + float4 s = tex2D( specTexture, IN.uv ); + + //return lightDiffuse * saturate( dot(n, lightVec) );//bumpVec; + // return d * dot(bumpVec, lightVec); + // return lightDiffuse * Lit.y + lightSpecular * Lit.z * s + d * dot(bumpVec, lightVec); + return lightDiffuse * Lit.y + lightSpecular * Lit.z * s + lightAmbient * d + saturate( dot(n, lightVec) ) * d; +} + Modified: trunk/data/misc/ids.xml =================================================================== (Binary files differ) Modified: trunk/data/misc/testsector.xml =================================================================== --- trunk/data/misc/testsector.xml 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/data/misc/testsector.xml 2008-05-11 11:58:03 UTC (rev 890) @@ -47,9 +47,28 @@ <scale>20, 20, 20</scale> <material>Asteroid</material> </sectorobject> + <sectorobject> + <name>beacon</name> + <mesh>beacon</mesh> + <position> -650, 0, 800</position> + <scale>20, 20, 20</scale> + <material>Sta/TS/Background</material> + </sectorobject> + <sectorobject> + <name>ring</name> + <mesh>ring</mesh> + <position> -650, 100, 800</position> + <scale>35, 35, 35</scale> + </sectorobject> + +<!-- <sectorobject> + <name>ring2</name> + <mesh>ring2</mesh> + <position> -650, 300, 800</position> + <scale>100, 100, 100</scale> + <material>Sta/TS/Background</material> + </sectorobject>--> - - <!-- <sectorobject> --> <!-- <name>astro6</name> --> <!-- <mesh>ice_oval_6</mesh> --> Added: trunk/data/missiles/bee.xml =================================================================== --- trunk/data/missiles/bee.xml (rev 0) +++ trunk/data/missiles/bee.xml 2008-05-11 11:58:03 UTC (rev 890) @@ -0,0 +1,31 @@ +<?xml version="1.0"?> + +<container> + <object_id>10002</object_id> + <name_de>bee</name_de> + <name_en>bee</name_en> + <mesh>firefly</mesh> + <category_id>11</category_id> + <faction_id>3</faction_id> + <description_en>Offense anti vessel missile for small ships</description_en> +<!-- <production_center>Octavius Great Pillars</production_center> + <production_center>Octavius Outpost</production_center> + <manufacturer>Octave Propulsion Laboratories</manufacturer>--> + <required_rank>2</required_rank> + <size>1</size> + <mass>150</mass> + <thrust>150000</thrust> + <damage>10400</damage> + <yaw>90</yaw> + <pitch>90</pitch> + <roll>90</roll> + <armor>90</armor> + <lifetime>22</lifetime> + <drag>1</drag> + <basesize>1</basesize> + <required_component>aluminium</required_component> + <required_component>magnesium</required_component> + <required_component>laser components</required_component> + <required_component>magnetic components</required_component> + <required_political_status>0</required_political_status> +</container> Added: trunk/data/missiles/bee_big.png =================================================================== (Binary files differ) Property changes on: trunk/data/missiles/bee_big.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/data/missiles/bee_small.png =================================================================== (Binary files differ) Property changes on: trunk/data/missiles/bee_small.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/AiManager.cpp =================================================================== --- trunk/src/AiManager.cpp 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/src/AiManager.cpp 2008-05-11 11:58:03 UTC (rev 890) @@ -113,11 +113,11 @@ resources_->network->userID(), 0, *VesselManager::getSingleton().vessel( "apteryx" ) ); - obj->vessel( )->setPowerPlant( EquipmentManager::getSingleton().powerPlant( "Spud" ) ); - obj->vessel( )->setEngine( EquipmentManager::getSingleton().engine( "T-E-15" ) ); - obj->vessel( )->setRadar( EquipmentManager::getSingleton().radar( "Outlook" ) ); - obj->vessel( )->setShield( EquipmentManager::getSingleton().shield( "Kydango" ) ); - obj->vessel( )->setCapacitor( EquipmentManager::getSingleton().capacitor( "Sponge" ) ); + obj->vessel( )->setPowerPlant( resources_->entityManager->powerPlant( "Spud" ) ); + obj->vessel( )->setEngine( resources_->entityManager->engine( "T-E-15" ) ); + obj->vessel( )->setRadar( resources_->entityManager->radar( "Outlook" ) ); + obj->vessel( )->setShield( resources_->entityManager->shield( "Kydango" ) ); + obj->vessel( )->setCapacitor( resources_->entityManager->capacitor( "Sponge" ) ); std::cout << "Create " << obj->name() << std::endl; } else { std::cout << "spawn only in undockedState" << std::endl; Modified: trunk/src/BaseObject.cpp =================================================================== --- trunk/src/BaseObject.cpp 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/src/BaseObject.cpp 2008-05-11 11:58:03 UTC (rev 890) @@ -20,6 +20,7 @@ #include "BaseObject.h" #include "Sector.h" +#include "OpcodeWrapper.h" #include <OgreEntity.h> @@ -28,25 +29,38 @@ namespace OpenGate{ BaseObject::BaseObject( const Ogre::String & name, Sector * sector, Uint32 userID, Uint8 childID ) - : name_( name ), sector_( sector ), userID_( userID ), childID_( childID ), mainNode_( NULL ){ + : name_( name ), sector_( sector ), userID_( userID ), childID_( childID ), mainNode_( NULL ), collObj_( NULL ){ globalID_ = createGlobalID( userID, childID ); - sceneMgr_ = sector_->sceneManager(); - try{ - mainNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( name + "_MainNode" ); - } catch( Ogre::Exception & e ) { - LogManager::getSingleton().fatal( e.getFullDescription() ); - } + sceneMgr_ = sector_->sceneManager(); + try{ + mainNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( name + "_MainNode" ); + } catch( Ogre::Exception & e ) { + LogManager::getSingleton().fatal( e.getFullDescription() ); + } - destroyRequest_ = false; - lifeTime_ = 0.0; - selectable_ = false; - collObj_ = NULL; + lifeTime_ = 0.0; + selectable_ = false; + destroyRequest_ = false; + active_ = true; } BaseObject::~BaseObject(){ - sceneMgr_->getRootSceneNode()->removeAndDestroyChild( mainNode_->getName() ); + sceneMgr_->getRootSceneNode()->removeAndDestroyChild( mainNode_->getName() ); } +void BaseObject::setActive( bool activate ){ + // std::cout << "BaseObject::setActive " << mainNode_->getName() << " " << activate << std::endl; + if ( active_ && !activate ){ + setVisible( false ); + active_ = false; + deactivate_(); + } else if ( !active_ && activate ){ + setVisible( true ); + active_ = true; + destroyRequest_ = false; + lifeTime_ = 0.0; + } +} } // namespace OpenGate Modified: trunk/src/BaseObject.h =================================================================== --- trunk/src/BaseObject.h 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/src/BaseObject.h 2008-05-11 11:58:03 UTC (rev 890) @@ -55,14 +55,20 @@ virtual void collide( BaseObject * object ) = 0; - inline virtual Uint32 userID() const { return userID_; } + inline void setUserID( Uint32 ID ) { userID_ = ID; } + + inline Uint32 userID() const { return userID_; } - inline virtual Uint8 childID() const { return childID_; } + inline void setChildID( Uint8 ID ) { childID_ = ID; } + + inline Uint8 childID() const { return childID_; } inline virtual Uint32 globalID() const { return globalID_; } virtual bool isChild() const { return childID_ > 0; } + void setName( const std::string & name ) { name_ = name; } + Ogre::String name() const { return name_; } inline Ogre::SceneNode * mainNode() { return mainNode_; } @@ -91,20 +97,29 @@ virtual void setVisible( bool visible ) { mainNode_->setVisible( visible ); } + virtual void setActive( bool active ); + + inline virtual bool isActive() const { return active_; } + protected: - Ogre::String name_; - Sector * sector_; - Uint32 userID_; - Uint8 childID_; - Uint32 globalID_; + + virtual void deactivate_(){ } + + Ogre::String name_; + Sector * sector_; + Uint32 userID_; + Uint8 childID_; + Uint32 globalID_; - Ogre::SceneNode * mainNode_; - - bool selectable_; - Ogre::SceneManager * sceneMgr_; - OgreOpcode::CollisionObject * collObj_; - Ogre::Real lifeTime_; - bool destroyRequest_; + Ogre::SceneNode * mainNode_; + Ogre::SceneManager * sceneMgr_; + Ogre::Real lifeTime_; + + OgreOpcode::CollisionObject * collObj_; + + bool selectable_; + bool destroyRequest_; + bool active_; }; } //namespace OpenGate Modified: trunk/src/Entity.cpp =================================================================== --- trunk/src/Entity.cpp 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/src/Entity.cpp 2008-05-11 11:58:03 UTC (rev 890) @@ -33,6 +33,12 @@ Entity::Entity() : name_( "unknown" ), className_( "unknown" ), description_("Please fill in description"), imageFileName_("unknown"), ceguiImageName_( "unknownEntityImageset") { + //** just an idea +// addProperty< float >( "baseYaw", this, setBaseYaw, baseYaw, mandatory, default, description ) + //Property * prop = new Property< Uint32 >( "mass", this, &OpenGate::Entity::setMass, &OpenGate::Entity::mass ); + //properties_.push_back( new Property< Uint32 >( "mass", this, &OpenGate::Entity::setMass, &OpenGate::Entity::mass ) ); + + id_ = 0; techLevel_ = 0; mass_ = 1; @@ -43,7 +49,7 @@ baseYaw_ = 0; basePitch_ = 0; baseRoll_ = 0; - + imageInitialised_ = false; setFactionName_( ResourceManager::getSingleton().factionName( factionID_ ) ); } @@ -118,4 +124,47 @@ return !fail; } +bool Entity::readPropertiesFromXML( TiXmlHandle & hRoot ){ + if ( !readXMLNode< std::string >( hRoot, "name_"+ ResourceManager::getSingleton().languageSuffix(), + this, &OpenGate::Entity::setName, false ) ){ + readXMLNode< std::string >( hRoot, "name", this, &OpenGate::Entity::setName, true ); + } + //readXMLNode< std::string >( hRoot, "name_de", entity, &OpenGate::Entity::setName, true ); + readXMLNode< Uint16 >( hRoot, "object_id", this, &OpenGate::Entity::setID, true ); + readXMLNode< Uint8 >( hRoot, "faction_id", this, &OpenGate::Entity::setFactionID, true ); + + readXMLNode< Uint8 >( hRoot, "class_id", this, &OpenGate::Entity::setClassID, false ); + readXMLNode< Uint8 >( hRoot, "techlevel", this, &OpenGate::Entity::setTechLevel, false ); + //readXMLNode< Uint8 >( hRoot, "required_rank", entity, &OpenGate::Entity::setRequieredRank, true ); + + readXMLNode< int >( hRoot, "size", this, &OpenGate::Entity::setSize, false ); + readXMLNode< int >( hRoot, "mass", this, &OpenGate::Entity::setMass, false ); + + if ( !readXMLNode< std::string >( hRoot, "description_" + ResourceManager::getSingleton().languageSuffix(), this, + &OpenGate::Entity::setDescription, false ) ){ + readXMLNode< std::string >( hRoot, "description", this, &OpenGate::Entity::setDescription, false ); + } + readXMLNodes< std::string >( hRoot, "production-center", this, &OpenGate::Entity::addProductionCenter ); + readXMLNode< float >( hRoot, "baseyaw", this, &OpenGate::Entity::setBaseYaw, false ); + readXMLNode< float >( hRoot, "basepitch", this, &OpenGate::Entity::setBasePitch, false ); + readXMLNode< float >( hRoot, "baseroll", this, &OpenGate::Entity::setBaseRoll, false ); + +// Ogre::Real length = 0; +// pElem = hRoot.ChildElement( "length", 0 ).Element(); +// if ( pElem ) length = toDouble( pElem->FirstChild()->Value() ); +// +// Ogre::Real width = 0; +// pElem = hRoot.ChildElement( "width", 0 ).Element(); +// if ( pElem ) width = toDouble( pElem->FirstChild()->Value() ); +// +// Ogre::Real height = 0; +// pElem = hRoot.ChildElement( "height", 0 ).Element(); +// if ( pElem ) height = toDouble( pElem->FirstChild()->Value() ); +// if ( length > 0 && width > 0 && height > 0 ) vessel->setBaseSize( width, height, length ); + + + return true; +} + + } // namespace OpenGate Modified: trunk/src/Entity.h =================================================================== --- trunk/src/Entity.h 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/src/Entity.h 2008-05-11 11:58:03 UTC (rev 890) @@ -31,8 +31,27 @@ namespace OpenGate{ +enum EntityType{NONE,ENTITY,VESSEL,COMMODITY,POWERPLANT,ENGINE,RADAR,ECM,CAPACITOR,SHIELD,GUN,MISSILE,MODX}; + class Commodity; +// class Property { +// public: +// template < class Class, class Setter, class Getter > Property( const std::string & name, Class * instance, Setter setter, Getter getter ) +// : name_( name ), instance_ ( instance ), setter_( &setter ), getter_( &getter ){ +// } +// +// void operator( )(){ +// (instance_->*setter_)( ); +// } +// protected: +// std::string name_; +// void * instance_; +// void * setter_; +// void * getter_; +// +// }; + /*! * \brief This class definies the basic structure of all entity templates. * @@ -50,7 +69,9 @@ virtual ~Entity(){ } virtual EntityType entityType() const { return rtti_; } - + + virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ); + inline std::string factionName( ) const { return factionName_; } void setFactionID( int id ); @@ -58,7 +79,9 @@ inline void setName( const std::string & name ) { name_ = name; } inline std::string name( ) const { return name_; } - + + inline void setClassID( Uint8 id ) { className_ = ResourceManager::getSingleton().className( id ); } + inline void setClassName( const std::string & name ) { className_ = name; } inline std::string className( ) const { return className_; } @@ -103,8 +126,9 @@ bool initialiseImage( const std::string & imageName, const std::string & targetName, bool verbose = false ); - inline void setProductionCenters( const std::set < std::string > & productionCenters ) { - productionCenters_ = productionCenters; } + inline void addProductionCenter( const std::string & productionCenter ) { + productionCenters_.insert( productionCenter ); + } inline std::set < std::string > productionCenters( ) const { return productionCenters_; } inline void setRequieredComponents( const std::set < Commodity * > & requieredComponents ) { @@ -152,6 +176,8 @@ /*! For runtime identification of an entity item. */ EntityType rtti_; + + //std::vector < Property< class ValueType > * > properties_; }; } // namespace OpenGate Modified: trunk/src/EntityManager.cpp =================================================================== --- trunk/src/EntityManager.cpp 2008-05-04 15:50:32 UTC (rev 889) +++ trunk/src/EntityManager.cpp 2008-05-11 11:58:03 UTC (rev 890) @@ -29,13 +29,20 @@ #include <OgreFileSystem.h> #include <OgreSharedPtr.h> +#include <string> + namespace OpenGate { +EntityManager::EntityManager() { + log_ = LogManager::getSingletonPtr(); + resources_ = ResourceManager::getSingletonPtr(); +} + EntityManager::~EntityManager(){ - for ( std::map< Uint16, Entity * >::iterator it = templatesByID_.begin(); it != templatesByID_.end(); it ++ ){ - delete it->second; - } - templatesByID_.end(); + for ( std::map< Uint16, Entity * >::iterator it = templatesByID_.begin(); it != templatesByID_.end(); it ++ ){ + delete it->second; + } + templatesByID_.end(); } EntityType EntityManager::categoryType( const std::string & category ){ @@ -45,17 +52,17 @@ category == "Powerplant" || category == "Powerplants" || category == "Power plant" || category == "Power plants" || category == "powerplant" || category == "powerplants" ) return POWERPLANT; + else if ( category == "Capacitor" || category == "Capacitors" || + category == "capacitor" || category == "capacitors" ) return CAPACITOR; else if ( category == "Engine" || category == "Engines" || category == "engine" || category == "engines" ) return ENGINE; + else if ( category == "Shield" || category == "Shields" || + category == "shield" || category == "shields" ) return SHIELD; else if ( category == "Radar" || category == "Radars" || category == "radar" || category == "radars" ) return RADAR; else if ( category == "ECM" || category == "ECMs" || category == "Ecm" || category == "Ecms" || category == "ecm" || category == "ecms" ) return ECM; - else if ( category == "Capacitor" || category == "Capacitors" || - category == "capacitor" || category == "capacitors" ) return CAPACITOR; - else if ( category == "Shield" || category == "Shields" || - category == "shield" || category == "shields" ) return SHIELD; else if ( category == "Gun" || category == "Guns" || category == "gun" || category == "guns" ) return GUN; else if ( category == "Missile" || category == "Missiles" || @@ -63,84 +70,62 @@ else if ( category == "MODX" || category == "MODXs" || category == "MODx" || category == "MODxs" || category == "modx" || category == "modxs" ) return MODX; + else if ( category == "Vessel" || category == "Vessels" || + category == "vessel" || category == "Vessels" ) return VESSEL; LogManager::getSingleton().warn("Request entity rtti for " + category + " unknown" ); return ENTITY; } +std::string EntityManager::categoryName( EntityType type ){ + switch( type ){ + case COMMODITY: return "Commodity"; + case POWERPLANT: return "Powerplant"; + case CAPACITOR: return "Capacitor"; + case ENGINE: return "Engine"; + case SHIELD: return "Shield"; + case RADAR: return "Radar"; + case ECM: return "ECM"; + case GUN: return "GUN"; + case MISSILE: return "MISSILE"; + case MODX: return "MODx"; + case VESSEL: return "Vessel"; + } -Entity * EntityManager::entity( const std::string & name ){ - if ( templatesByName_.count( name ) ){ - return templatesByName_[ name ]; - } else { - LogManager::getSingleton().warn("Request for entity: " + name + " unknown" ); - return NULL; - } - } - - Entity * EntityManager::entity( Uint16 ID ){ - if ( templatesByID_.count( ID ) ){ - return templatesByID_[ ID ]; - } else { - LogManager::getSingleton().warn( ("Request for entity id: ") + toStr(ID) + " unknown" ); - return NULL; - } - } - -void EntityManager::load( const std::set < std::string > & resourcePaths, const std::string & resourceName ){ - - Ogre::FileSystemArchive * pArch = new Ogre::FileSystemArchive( (*resourcePaths.begin()) + "/" + resourceName, "FileSystem" ); - - Ogre::StringVectorPtr files = pArch->find( "*.xml", true, false); - for ( unsigned int i = 0; i < (*files).size(); i ++ ){ - log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); - loadAndCreate( (*resourcePaths.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); - } - - delete pArch; + LogManager::getSingleton().warn("Request name for category " + toStr( type ) + " unknown" ); + return "unknown"; } -template<> EquipmentManager * Ogre::Singleton< EquipmentManager >::ms_Singleton = 0; - -EquipmentManager::EquipmentManager(): EntityManager(){ - Entity * entity = new Missile(); - entity->setName( "firefly" ); - entity->setID( 10001 ); - dynamic_cast< Missile * >( entity )->setDamage( 10000000 ); - dynamic_cast< Missile * >( entity )->setThrust( 150000 ); - dynamic_cast< Missile * >( entity )->setYaw( 90 ); - dynamic_cast< Missile * >( entity )->setPitch( 90 ); - dynamic_cast< Missile * >( entity )->setRoll( 90 ); - dynamic_cast< Missile * >( entity )->setArmor( 1 ); - dynamic_cast< Missile * >( entity )->setMass( 150 ); - dynamic_cast< Missile * >( entity )->setLifeTime( 20 ); - dynamic_cast< Missile * >( entity )->setDragFactor( 1 ); - dynamic_cast< Missile * >( entity )->setBaseSize(0.2, 0.2, 1.0 ); - try{ - dynamic_cast< Missile * >(entity)->setMesh( "firefly.mesh", false ); - } catch( Ogre::Exception & e ){ - LogManager::getSingleton().warn( e.what() ); +Entity * EntityManager::entity( const std::string & name ) { + if ( templatesByName_.count( name ) ){ + return templatesByName_[ name ]; + } else { + LogManager::getSingleton().warn("Request for entity: " + name + " unknown" ); + return NULL; } - templatesByName_[ entity->name() ] = entity; - templatesByID_[ entity->id() ] = entity; } -EquipmentManager::~EquipmentManager() { +Entity * EntityManager::entity( Uint16 ID ){ + if ( templatesByID_.count( ID ) ){ + return templatesByID_[ ID ]; + } else { + LogManager::getSingleton().warn( ("Request for entity id: ") + toStr(ID) + " unknown" ); + return NULL; + } } + +PowerPlant * EntityManager::powerPlant( const std::string & name ){ return entity_< PowerPlant >( name ); } +Engine * EntityManager::engine( const std::string & name ){ return entity_< Engine >( name ); } +Radar * EntityManager::radar( const std::string & name ){ return entity_< Radar >( name ); } +Shield * EntityManager::shield( const std::string & name ){ return entity_< Shield >( name ); } +Capacitor * EntityManager::capacitor( const std::string & name ){ return entity_< Capacitor >( name ); } +Gun * EntityManager::gun( const std::string & name ){ return entity_< Gun >( name ); } +Missile * EntityManager::missile( const std::string & name ){ return entity_< Missile >( name ); } +ModX * EntityManager::modx( const std::string & name ){ return entity_< ModX >( name ); } +Ecm * EntityManager::ecm( const std::string & name ){ return entity_< Ecm >( name ); } +Vessel * EntityManager::vessel( const std::string & name ){ return entity_< Vessel >( name ); } -EquipmentManager & EquipmentManager::getSingleton( ){ - assert( ms_Singleton ); - return ( *ms_Singleton ); -} - -EquipmentManager * EquipmentManager::getSingletonPtr( ){ - if ( ms_Singleton == NULL ){ - LogManager::getSingleton().fatal( "CommodityManager not initialized." ); - } - return ms_Singleton; -} - - std::vector < Entity * > EquipmentManager::allByCategory( const std::string & category ){ +std::vector < Entity * > EntityManager::allByCategory( const std::string & category ){ EntityType rtti = NONE; if ( category != "All" ) rtti = categoryType( category ); std::vector < Entity * > items; @@ -151,347 +136,398 @@ } return items; } - -PowerPlant * EquipmentManager::powerPlant( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == POWERPLANT ) { - return dynamic_cast< PowerPlant * >(item); - } else { - LogManager::getSingleton().warn( name + " is no power plant." ); - } - return NULL; -} -Engine * EquipmentManager::engine( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == ENGINE ) { - return dynamic_cast< Engine * >(item); - } else { - LogManager::getSingleton().warn( name + " is no engine." ); - } - return NULL; -} +void EntityManager::load( const std::set < std::string > & resourcePaths, const std::string & resourceName ){ + Ogre::FileSystemArchive * pArch = new Ogre::FileSystemArchive( (*resourcePaths.begin()) + "/" + resourceName, "FileSystem" ); -Radar * EquipmentManager::radar( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == RADAR ) { - return dynamic_cast< Radar * >(item); - } else { - LogManager::getSingleton().warn( name + " is no radar." ); - } - return NULL; -} + Ogre::StringVectorPtr files = pArch->find( "*.xml", true, false); + for ( unsigned int i = 0; i < (*files).size(); i ++ ){ + log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); + loadAndCreate( (*resourcePaths.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); + } -Shield * EquipmentManager::shield( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == SHIELD ) { - return dynamic_cast< Shield * >(item); - } else { - LogManager::getSingleton().warn( name + " is no shield." ); - } - return NULL; + delete pArch; } -Capacitor * EquipmentManager::capacitor( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == CAPACITOR ) { - return dynamic_cast< Capacitor * >(item); - } else { - LogManager::getSingleton().warn( name + " is no capacitor." ); - } - return NULL; -} +Entity * EntityManager::loadAndCreate( const std::string & fileName ){ + log_->fout( "Read equipment: " + fileName ); -Gun * EquipmentManager::gun( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == GUN ) { - return dynamic_cast< Gun * >(item); - } else { - LogManager::getSingleton().warn( name + " is no gun." ); - } - return NULL; -} - -Missile * EquipmentManager::missile( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) return NULL; - - if ( item->entityType() == MISSILE ) { - return dynamic_cast< Missile * >(item); - } else { - LogManager::getSingleton().warn( name + " is no missile." ); + TiXmlDocument doc( fileName ); + bool loadOkay = doc.LoadFile(); + + if ( !loadOkay ) { + log_->fatal( std::string( "Failed to load equipment file: " + fileName ) ); + return NULL; } - return NULL; -} - -Entity * EquipmentManager::loadAndCreate( const std::string & fileName ){ - log_->fout( "Read equipment: " + fileName ); + TiXmlHandle docHandle( &doc ); + TiXmlElement * pElem; + TiXmlHandle hRoot( 0 ); - TiXmlDocument doc( fileName ); - bool loadOkay = doc.LoadFile(); + pElem = docHandle.FirstChildElement().Element(); + hRoot = TiXmlHandle( pElem ); - if ( !loadOkay ) { - log_->fatal( std::string( "Failed to load equipment file: " + fileName ) ); - return NULL; - } + if ( !pElem ) { + log_->fatal( fileName + " cannot read first node." ); + return NULL; + } - TiXmlHandle docHandle( &doc ); - TiXmlElement *pElem; - TiXmlHandle hRoot( 0 ); + if ( strcmp( "equipment", pElem->Value() ) != 0 && strcmp( "container", pElem->Value() ) != 0 ) { + log_->fatal( fileName + " is no entity description" ); + return NULL; + } + + Entity * entity; - pElem = docHandle.FirstChildElement().Element(); - hRoot = TiXmlHandle( pElem ); - - if ( !pElem ) { - log_->fatal( fileName + " cannot read first node." ); - return NULL; - } - - if ( strcmp( "equipment", pElem->Value() ) != 0 && strcmp( "container", pElem->Value() ) != 0 ) { - log_->fatal( fileName + " is no equipment description" ); - return NULL; - } - -// Equipment * entity = 0; -// std::string equipmentType = pElem->Attribute("type"); - - -// if ( equipmentType == "Engine" ) entity = new Engine(); -// else if ( equipmentType == "ECM" ) entity = new Ecm(); -// else if ( equipmentType == "Capacitor" ) entity = new Capacitor(); -// else { -// log_->fatal( fileName + " has no type of equipment defined" ); -// return NULL; -// } - - - Entity * entity; - - //** Mandatory elements; - pElem = hRoot.ChildElement( "category_id", 0 ).Element(); - if ( !pElem ) { //** fallback - pElem = hRoot.ChildElement( "categorie_id", 0 ).Element(); - } - - if ( pElem ) { - int category = toInt( pElem->FirstChild()->Value() ); - - switch( category ){ - case 1: entity = new Commodity(); break; - case 2: entity = new PowerPlant(); break; - case 4: entity = new Capacitor(); break; - case 6: entity = new Engine(); break; - case 7: entity = new Shield(); break; - case 8: entity = new Radar(); break; - case 10: entity = new Gun(); break; - case 11: entity = new Missile(); break; - default: - log_->fatal( fileName + " category_id " + toStr( category ) + " unknown." ); - return NULL; + //** Mandatory elements; + pElem = hRoot.ChildElement( "category_id", 0 ).Element(); + if ( !pElem ) { //** fallback + pElem = hRoot.ChildElement( "categorie_id", 0 ).Element(); } - } else { - log_->fatal( fileName + " has no category_id (mandatory)." ); - return NULL; - } - //** Mandatory elements; - pElem = hRoot.ChildElement( "name_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); - if ( !pElem ){ //** fallback to english - pElem = hRoot.ChildElement( "name_en", 0 ).Element(); - } - if ( pElem ) { - entity->setName( pElem->FirstChild()->Value() ); - } else { - log_->fatal( fileName + " has no name_en (mandatory)." ); - return NULL; - } - - pElem = hRoot.ChildElement( "object_id", 0 ).Element(); - if ( pElem ) { - entity->setID( toInt( pElem->FirstChild()->Value() ) ); - } else { - log_->fatal( fileName + " has no object_id (mandatory)." ); - return NULL; - } - - - pElem = hRoot.ChildElement( "faction_id", 0 ).Element(); - if ( pElem ) { - entity->setFactionID( toInt( pElem->FirstChild()->Value() ) ); - } else { - log_->fatal( fileName + " has no faction_id (mandatory)." ); - return NULL; - } - - //** Image name for the entity is derived from filename; - std::string basename( fileName.substr( fileName.rfind( "/" ) + 1 ) ); - entity->setImageName( basename.substr( 0, basename.find( ".xml" ) ) ); - - //** Generic elements - pElem = hRoot.ChildElement( "class_id", 0 ).Element(); - if ( pElem ) entity->setClassName( ResourceManager::getSingleton().className( toInt( pElem->FirstChild()->Value() ) ) ); - - pElem = hRoot.ChildElement( "techlevel", 0 ).Element(); - if ( pElem ) entity->setTechLevel( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "required_rank", 0 ).Element(); - if ( pElem ) entity->setTechLevel( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "size", 0 ).Element(); - if ( pElem ) entity->setSize( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "mass", 0 ).Element(); - if ( pElem ) entity->setMass( toInt( pElem->FirstChild()->Value() ) ); - - double efficiency = 1.0; - pElem = hRoot.ChildElement( "efficiency", 0 ).Element(); - if ( pElem ) { - efficiency = toDouble( pElem->FirstChild()->Value() ); - if ( efficiency > 1 ) efficiency /= 100; - } - - Uint32 powerConsumption = 0; - pElem = hRoot.ChildElement( "power_input", 0 ).Element(); - if ( pElem ) powerConsumption = toInt( pElem->FirstChild()->Value() ); - - pElem = hRoot.ChildElement( "description_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); - if ( !pElem ){ //** fallback to english - pElem = hRoot.ChildElement( "description_en", 0 ).Element(); - } - if ( !pElem ){ //** fallback to english - pElem = hRoot.ChildElement( "description_en", 0 ).Element(); - } - if ( pElem ) { - std::cout << entity->description() << std::endl; - entity->setDescription( pElem->FirstChild()->Value() ); - } - - //** Specific elements; - switch ( entity->entityType() ){ - case POWERPLANT: - pElem = hRoot.ChildElement( "power_output", 0 ).Element(); - if ( pElem ) dynamic_cast< PowerPlant * >( entity )->setPowerOutput( toInt( pElem->FirstChild()->Value() ) ); - break; - case ENGINE: - dynamic_cast< Engine * >( entity )->setEfficiency( efficiency ); - pElem = hRoot.ChildElement( "maximum_thrust", 0 ).Element(); - if ( pElem ) dynamic_cast< Engine * >( entity )->setMaxThrust( toInt( pElem->FirstChild()->Value() ) ); - - break; - case RADAR: - dynamic_cast< Radar * >( entity )->setEfficiency( efficiency ); - dynamic_cast< Radar * >( entity )->setPowerConsumption( powerConsumption ); - - pElem = hRoot.ChildElement( "maximum_range", 0 ).Element(); - if ( pElem ) dynamic_cast< Radar * >( entity )->setMaxRange( toInt( pElem->FirstChild()->Value() ) ); - - break; - case ECM: - dynamic_cast< Ecm * >( entity )->setPowerConsumption( powerConsumption ); - - pElem = hRoot.ChildElement( "sensorlevel", 0 ).Element(); - if ( pElem ) dynamic_cast< Ecm * >( entity )->setSensorLevel( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "power", 0 ).Element(); - if ( pElem ) dynamic_cast< Ecm * >( entity )->setPowerConsumption( toInt( pElem->FirstChild()->Value() ) ); - break; - case CAPACITOR: - dynamic_cast< Capacitor * >( entity )->setEfficiency( efficiency ); - - pElem = hRoot.ChildElement( "capacity", 0 ).Element(); - if ( pElem ) dynamic_cast< Capacitor * >( entity )->setCapacity( toInt( pElem->FirstChild()->Value() ) ); - break; - case SHIELD: - dynamic_cast< Shield * >( entity )->setEfficiency( efficiency ); - - pElem = hRoot.ChildElement( "regeneration_rate", 0 ).Element(); - if ( pElem ) dynamic_cast< Shield * >( entity )->setRegenerationRate( toInt( pElem->FirstChild()->Value() ) ); - pElem = hRoot.ChildElement( "maximum_deflection", 0 ).Element(); - if ( pElem ) dynamic_cast< Shield * >( entity )->setMaxDeflection( toInt( pElem->FirstChild()->Value() ) ); - - break; - case GUN: - pElem = hRoot.ChildElement( "type", 0 ).Element(); if ( pElem ) { - if ( strcmp( pElem->FirstChild()->Value(), "laser" ) == 0 ){ - dynamic_cast< Gun * >( entity )->setType( LASER ); - } else if ( strcmp( pElem->FirstChild()->Value(), "mininglaser" ) == 0 ){ - dynamic_cast< Gun * >( entity )->setType( MININGLASER ); - } else if ( strcmp( pElem->FirstChild()->Value(), "bullet" ) == 0 ){ - dynamic_cast< Gun * >( entity )->setType( BULLET ); - } - } + int category = toInt( pElem->FirstChild()->Value() ); - pElem = hRoot.ChildElement( "velocity", 0 ).Element(); - if ( pElem ) dynamic_cast< Gun * >( entity )->setSpeed( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "life_time", 0 ).Element(); - if ( pElem ) dynamic_cast< Gun * >( entity )->setLifeTime( toDouble( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "fire_delay", 0 ).Element(); - if ( pElem ) dynamic_cast< Gun * >( entity )->setFireDelay( toDouble( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "power_per_shot", 0 ).Element(); - if ( pElem ) dynamic_cast< Gun * >( entity )->setEnergy( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "damage", 0 ).Element(); - if ( pElem ) dynamic_cast< Gun * >( entity )->setDamage( toInt( pElem->FirstChild()->Value() ) ); - break; - case MISSILE: - break; - case MODX: - break; - default: - break; - } - - //** Production Data; - std::set < std::string > productionCenters; - for ( pElem = hRoot.FirstChild( "production-center" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { - productionCenters.insert( pElem->FirstChild()->Value() ); //!< \todo check return value! - } - - entity->setProductionCenters( productionCenters ); - CommodityManager* commodityMgr = CommodityManager::getSingletonPtr(); - if ( !commodityMgr ) { - log_->fatal( "Cannot find the commodity manager, no production data available" ); - return NULL; - } - std::set < Commodity * > commodities; - for ( pElem = hRoot.FirstChild( "required-component" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { - Commodity *commodity = commodityMgr->findByName ( pElem->FirstChild()->Value() ); //!< \todo check return value! - if ( commodity ) { - commodities.insert( commodity ); + switch( category ){ + case 1: entity = new Commodity(); break; + case 2: entity = new PowerPlant(); break; + case 4: entity = new Capacitor(); break; + case 6: entity = new Engine(); break; + case 7: entity = new Shield(); break; + case 8: entity = new Radar(); break; + case 10: entity = new Gun(); break; + case 11: entity = new Missile(); break; + default: + log_->fatal( fileName + " category_id " + toStr( category ) + " unknown." ); + return NULL; + } } else { - log_->warn( fileName + " has unsatisfied commodities." ); + log_->fatal( fileName + " has no category_id (mandatory)." ); + return NULL; } - } - entity->setRequieredComponents( commodities ); + //** Image name for the entity is derived from filename; + std::string basename( fileName.substr( fileName.rfind( "/" ) + 1 ) ); + entity->setImageName( basename.substr( 0, basename.find( ".xml" ) ) ); + + try{ + entity->readPropertiesFromXML( hRoot ); + } catch ( std::invalid_argument e ){ + log_->warn( e.what() ); + return NULL; + } + + if ( templatesByName_.count( entity->name() ) == 0 ){ + templatesByName_[ entity->name() ] = entity; + templatesByID_[ entity->id() ] = entity; + factions_.insert( entity->factionName() ); + } else { + log_->warn( std::string( "Equipment with name: " ) + entity->factionName() + "/" + entity->name() + + " already loaded" ); + } - if ( templatesByName_.count( entity->name() ) == 0 ){ - templatesByName_[ entity->name() ] = entity; - templatesByID_[ entity->id() ] = entity; - - factions_.insert( entity->factionName() ); - } else { - log_->warn( std::string( "Equipment with name: " ) + entity->factionName() + "/" + entity->name() + - " already loaded" ); - } - return entity; + return entity; } + +// template<> EquipmentManager * Ogre::Singleton< EquipmentManager >::ms_Singleton = 0; +// +// EquipmentManager::EquipmentManager(): EntityManager(){ +// Entity * entity = new Missile(); +// entity->setName( "firefly" ); +// entity->setID( 10001 ); +// dynamic_cast< Missile * >( entity )->setDamage( 10400 ); +// dynamic_cast< Missile * >( entity )->setThrust( 150000 ); +// // dynamic_cast< Missile * >( entity )->setYaw( 90 ); +// // dynamic_cast< Missile * >( entity )->setPitch( 90 ); +// // dynamic_cast< Missile * >( entity )->setRoll( 90 ); +// //dynamic_cast< Missile * >( entity )->setArmor( 1 ); +// //dynamic_cast< Missile * >( entity )->setMass( 150 ); +// dynamic_cast< Missile * >( entity )->setLifeTime( 20 ); +// // dynamic_cast< Missile * >( entity )->setDragFactor( 1 ); +// dynamic_cast< Missile * >( entity )->setBaseSize(0.2, 0.2, 1.0 ); +// try{ +// dynamic_cast< Missile * >(entity)->setMesh( "firefly.mesh", false ); +// +// +// } catch( Ogre::Exception & e ){ +// LogManager::getSingleton().warn( e.what() ); +// } +// templatesByName_[ entity->name() ] = entity; +// templatesByID_[ entity->id() ] = entity; +// } +// +// EquipmentManager::~EquipmentManager() { +// } +// +// EquipmentManager & EquipmentManager::getSingleton( ){ +// assert( ms_Singleton ); +// return ( *ms_Singleton ); +// } +// +// EquipmentManager * EquipmentManager::getSingletonPtr( ){ +// if ( ms_Singleton == NULL ){ +// LogManager::getSingleton().fatal( "CommodityManager not initialized." ); +// } +// return ms_Singleton; +// } +// +// +// +// Entity * EquipmentManager::loadAndCreate( const std::string & fileName ){ +// +// log_->fout( "Read equipment: " + fileName ); +// +// TiXmlDocument doc( fileName ); +// bool loadOkay = doc.LoadFile(); +// +// if ( !loadOkay ) { +// log_->fatal( std::string( "Failed to load equipment file: " + fileName ) ); +// return NULL; +// } +// +// TiXmlHandle docHandle( &doc ); +// TiXmlElement *pElem; +// TiXmlHandle hRoot( 0 ); +// +// pElem = docHandle.FirstChildElement().Element(); +// hRoot = TiXmlHandle( pElem ); +// +// if ( !pElem ) { +// log_->fatal( fileName + " cannot read first node." ); +// return NULL; +// } +// +// if ( strcmp( "equipment", pElem->Value() ) != 0 && strcmp( "container", pElem->Value() ) != 0 ) { +// log_->fatal( fileName + " is no equipment description" ); +// return NULL; +// } +// +// // Equipment * entity = 0; +// // std::string equipmentType = pElem->Attribute("type"); +// +// +// // if ( equipmentType == "Engine" ) entity = new Engine(); +// // else if ( equipmentType == "ECM" ) entity = new Ecm(); +// // else if ( equipmentType == "Capacitor" ) entity = new Capacitor(); +// // else { +// // log_->fatal( fileName + " has no type of equipment defined" ); +// // return NULL; +// // } +// +// +// Entity * entity; +// +// //** Mandatory elements; +// pElem = hRoot.ChildElement( "category_id", 0 ).Element(); +// if ( !pElem ) { //** fallback +// pElem = hRoot.ChildElement( "categorie_id", 0 ).Element(); +// } +// +// if ( pElem ) { +// int category = toInt( pElem->FirstChild()->Value() ); +// +// switch( category ){ +// case 1: entity = new Commodity(); break; +// case 2: entity = new PowerPlant(); break; +// case 4: entity = new Capacitor(); break; +// case 6: entity = new Engine(); break; +// case 7: entity = new Shield(); break; +// case 8: entity = new Radar(); break; +// case 10: entity = new Gun(); break; +// case 11: entity = new Missile(); break; +// default: +// log_->fatal( fileName + " category_id " + toStr( category ) + " unknown." ); +// return NULL; +// } +// } else { +// log_->fatal( fileName + " has no category_id (mandatory)." ); +// return NULL; +// } +// +// //** Mandatory elements; +// pElem = hRoot.ChildElement( "name_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); +// if ( !pElem ){ //** fallback to english +// pElem = hRoot.ChildElement( "name_en", 0 ).Element(); +// } +// if ( pElem ) { +// entity->setName( pElem->FirstChild()->Value() ); +// } else { +// log_->fatal( fileName + " has no name_en (mandatory)." ); +// return NULL; +// } +// +// pElem = hRoot.ChildElement( "object_id", 0 ).Element(); +// if ( pElem ) { +// entity->setID( toInt( pElem->FirstChild()->Value() ) ); +// } else { +// log_->fatal( fileName + " has no object_id (mandatory)." ); +// return NULL; +// } +// +// +// pElem = hRoot.ChildElement( "faction_id", 0 ).Element(); +// if ( pElem ) { +// entity->setFactionID( toInt( pElem->FirstChild()->Value() ) ); +// } else { +// log_->fatal( fileName + " has no faction_id (mandatory)." ); +// return NULL; +// } +// +// //** Image name for the entity is derived from filename; +// std::string basename( fileName.substr( fileName.rfind( "/" ) + 1 ) ); +// entity->setImageName( basename.substr( 0, basename.find( ".xml" ) ) ); +// +// //** Generic elements +// pElem = hRoot.ChildElement( "class_id", 0 ).Element(); +// if ( pElem ) entity->setClassName( ResourceManager::getSingleton().className( toInt( pElem->FirstChild()->Value() ) ) ); +// +// pElem = hRoot.ChildElement( "techlevel", 0 ).Element(); +// if ( pElem ) entity->setTechLevel( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "required_rank", 0 ).Element(); +// if ( pElem ) entity->setTechLevel( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "size", 0 ).Element(); +// if ( pElem ) entity->setSize( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "mass", 0 ).Element(); +// if ( pElem ) entity->setMass( toInt( pElem->FirstChild()->Value() ) ); +// +// double efficiency = 1.0; +// pElem = hRoot.ChildElement( "efficiency", 0 ).Element(); +// if ( pElem ) { +// efficiency = toDouble( pElem->FirstChild()->Value() ); +// if ( efficiency > 1 ) efficiency /= 100; +// } +// +// Uint32 powerConsumption = 0; +// pElem = hRoot.ChildElement( "power_input", 0 ).Element(); +// if ( pElem ) powerConsumption = toInt( pElem->FirstChild()->Value() ); +// +// pElem = hRoot.ChildElement( "description_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); +// if ( !pElem ){ //** fallback to english +// pElem = hRoot.ChildElement( "description_en", 0 ).Element(); +// } +// if ( !pElem ){ //** fallback to english +// pElem = hRoot.ChildElement( "description_en", 0 ).Element(); +// } +// if ( pElem ) { +// std::cout << entity->description() << std::endl; +// entity->setDescription( pElem->FirstChild()->Value() ); +// } +// +// //** Specific elements; +// switch ( entity->entityType() ){ +// case POWERPLANT: +// pElem = hRoot.ChildElement( "power_output", 0 ).Element(); +// if ( pElem ) dynamic_cast< PowerPlant * >( entity )->setPowerOutput( toInt( pElem->FirstChild()->Value() ) ); +// break; +// case ENGINE: +// dynamic_cast< Engine * >( entity )->setEfficiency( efficiency ); +// pElem = hRoot.ChildElement( "maximum_thrust", 0 ).Element(); +// if ( pElem ) dynamic_cast< Engine * >( entity )->setMaxThrust( toInt( pElem->FirstChild()->Value() ) ); +// +// break; +// case RADAR: +// dynamic_cast< Radar * >( entity )->setEfficiency( efficiency ); +// dynamic_cast< Radar * >( entity )->setPowerConsumption( powerConsumption ); +// +// pElem = hRoot.ChildElement( "maximum_range", 0 ).Element(); +// if ( pElem ) dynamic_cast< Radar * >( entity )->setMaxRange( toInt( pElem->FirstChild()->Value() ) ); +// +// break; +// case ECM: +// dynamic_cast< Ecm * >( entity )->setPowerConsumption( powerConsumption ); +// +// pElem = hRoot.ChildElement( "sensorlevel", 0 ).Element(); +// if ( pElem ) dynamic_cast< Ecm * >( entity )->setSensorLevel( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "power", 0 ).Element(); +// if ( pElem ) dynamic_cast< Ecm * >( entity )->setPowerConsumption( toInt( pElem->FirstChild()->Value() ) ); +// break; +// case CAPACITOR: +// dynamic_cast< Capacitor * >( entity )->setEfficiency( efficiency ); +// +// pElem = hRoot.ChildElement( "capacity", 0 ).Element(); +// if ( pElem ) dynamic_cast< Capacitor * >( entity )->setCapacity( toInt( pElem->FirstChild()->Value() ) ); +// break; +// case SHIELD: +// dynamic_cast< Shield * >( entity )->setEfficiency( efficiency ); +// +// pElem = hRoot.ChildElement( "regeneration_rate", 0 ).Element(); +// if ( pElem ) dynamic_cast< Shield * >( entity )->setRegenerationRate( toInt( pElem->FirstChild()->Value() ) ); +// pElem = hRoot.ChildElement( "maximum_deflection", 0 ).Element(); +// if ( pEl... [truncated message content] |
From: <spo...@us...> - 2008-05-11 22:19:51
|
Revision: 893 http://opengate.svn.sourceforge.net/opengate/?rev=893&view=rev Author: spom_spom Date: 2008-05-11 15:19:57 -0700 (Sun, 11 May 2008) Log Message: ----------- Fixed some problems that lead to segfault Modified Paths: -------------- trunk/data/ships/escape_capsule.xml trunk/data/ships/octavius/apteryx/apteryx.xml trunk/data/ships/octavius/condor/condor.xml trunk/data/ships/octavius/phoenix/phoenix.xml trunk/data/ships/quantar/storm/storm.xml trunk/data/ships/quantar/typhoon/typhoon.xml trunk/data/ships/squadrok/squid/s-1.xml trunk/data/ships/squadrok/squid/s-2.xml trunk/data/ships/squadrok/squid/s-3.xml trunk/data/ships/squadrok/squid/squid.xml trunk/src/AiManager.cpp trunk/src/Avatar.cpp trunk/src/Entity.cpp trunk/src/Entity.h trunk/src/EntityManager.cpp trunk/src/EntityManager.h trunk/src/GameStateManager.cpp trunk/src/GameStateManager.h trunk/src/Makefile.am trunk/src/MarketDialog.cpp trunk/src/Moveable.cpp trunk/src/OpcodeWrapper.cpp trunk/src/OpcodeWrapper.h trunk/src/Planet.cpp trunk/src/ResourceManager.cpp trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObject.cpp trunk/src/SectorObject.h trunk/src/SectorObjectMissile.cpp trunk/src/SectorObjectMissile.h trunk/src/SectorObjectMoveable.cpp trunk/src/SectorObjectMoveable.h trunk/src/SectorObjectVessel.cpp trunk/src/SectorObjectVessel.h trunk/src/ShipConfigDialog.cpp trunk/src/Vessel.cpp trunk/src/Vessel.h trunk/src/common.h Removed Paths: ------------- trunk/src/VesselManager.cpp trunk/src/VesselManager.h Modified: trunk/data/ships/escape_capsule.xml =================================================================== (Binary files differ) Modified: trunk/data/ships/octavius/apteryx/apteryx.xml =================================================================== --- trunk/data/ships/octavius/apteryx/apteryx.xml 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/data/ships/octavius/apteryx/apteryx.xml 2008-05-11 22:19:57 UTC (rev 893) @@ -2,6 +2,7 @@ <ship> <!-- Naming --> + <category_id>9</category_id> <faction>octavius</faction> <faction_id>3</faction_id> <object_id>301</object_id> Modified: trunk/data/ships/octavius/condor/condor.xml =================================================================== --- trunk/data/ships/octavius/condor/condor.xml 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/data/ships/octavius/condor/condor.xml 2008-05-11 22:19:57 UTC (rev 893) @@ -2,6 +2,7 @@ <ship> <!-- Naming --> + <category_id>9</category_id> <faction>Ocavius</faction> <name>Condor</name> @@ -32,4 +33,4 @@ <pitch>0.000681</pitch> <!-- 39.0 in jossh --> <roll>0.000489</roll> <!-- 28.0 in jossh --> <yaw>0.000489</yaw> <!-- 28.0 in jossh --> -</ship> \ No newline at end of file +</ship> Modified: trunk/data/ships/octavius/phoenix/phoenix.xml =================================================================== --- trunk/data/ships/octavius/phoenix/phoenix.xml 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/data/ships/octavius/phoenix/phoenix.xml 2008-05-11 22:19:57 UTC (rev 893) @@ -2,6 +2,7 @@ <!DOCTYPE ship SYSTEM "opengate.dtd"> <ship> <!-- Naming --> + <category_id>9</category_id> <name>Phoenix</name> <class>Fighter</class> <faction>Ocavius</faction> @@ -32,4 +33,4 @@ <pitch>0.001134</pitch> <!-- 90.0 in jossh --> <roll>0.001222</roll> <!-- 70.0 in jossh --> <yaw>0.001047</yaw> <!-- 80.0 in jossh --> -</ship> \ No newline at end of file +</ship> Modified: trunk/data/ships/quantar/storm/storm.xml =================================================================== --- trunk/data/ships/quantar/storm/storm.xml 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/data/ships/quantar/storm/storm.xml 2008-05-11 22:19:57 UTC (rev 893) @@ -2,6 +2,7 @@ <ship> <!-- Naming --> + <category_id>9</category_id> <faction_id>2</faction_id> <object_id>201</object_id> <name>storm</name> Modified: trunk/data/ships/quantar/typhoon/typhoon.xml =================================================================== --- trunk/data/ships/quantar/typhoon/typhoon.xml 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/data/ships/quantar/typhoon/typhoon.xml 2008-05-11 22:19:57 UTC (rev 893) @@ -2,6 +2,7 @@ <ship> <!-- Naming --> + <category_id>9</category_id> <faction>Quantar</faction> <name>Typhoon</name> Modified: trunk/data/ships/squadrok/squid/s-1.xml =================================================================== (Binary files differ) Modified: trunk/data/ships/squadrok/squid/s-2.xml =================================================================== (Binary files differ) Modified: trunk/data/ships/squadrok/squid/s-3.xml =================================================================== (Binary files differ) Modified: trunk/data/ships/squadrok/squid/squid.xml =================================================================== --- trunk/data/ships/squadrok/squid/squid.xml 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/data/ships/squadrok/squid/squid.xml 2008-05-11 22:19:57 UTC (rev 893) @@ -2,6 +2,7 @@ <ship> <!-- Naming --> + <category_id>9</category_id> <faction_id>4</faction_id> <name>Squid</name> <object_id>401</object_id> Modified: trunk/src/AiManager.cpp =================================================================== --- trunk/src/AiManager.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/AiManager.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -23,7 +23,8 @@ #include "common.h" #include "ResourceManager.h" -#include "VesselManager.h" +#include "EntityManager.h" +#include "Vessel.h" #include "SectorObjectVessel.h" #include "Sector.h" #include "UnDockedState.h" @@ -109,18 +110,18 @@ if ( resources_->gameStateRoot->activeState( )->name() == "UnDockedState" ){ obj = dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() )->sector()-> - createVessel( ai->name(), - resources_->network->userID(), 0, - *VesselManager::getSingleton().vessel( "apteryx" ) ); + createVessel( ai->name(), + resources_->network->userID(), 0, + *resources_->entityManager->vessel( "apteryx" ) ); obj->vessel( )->setPowerPlant( resources_->entityManager->powerPlant( "Spud" ) ); obj->vessel( )->setEngine( resources_->entityManager->engine( "T-E-15" ) ); obj->vessel( )->setRadar( resources_->entityManager->radar( "Outlook" ) ); obj->vessel( )->setShield( resources_->entityManager->shield( "Kydango" ) ); obj->vessel( )->setCapacitor( resources_->entityManager->capacitor( "Sponge" ) ); - std::cout << "Create " << obj->name() << std::endl; + std::cout << "AiManager::spawnAi( ): " << obj->name() << std::endl; } else { - std::cout << "spawn only in undockedState" << std::endl; + std::cout << "AiManager::spawnAi( ): spawn only in undockedState" << std::endl; } } //-250, 0, 500 @@ -133,6 +134,7 @@ obj->mainNode()->setPosition( Ogre::Math::RangeRandom( xmin, xmax ), Ogre::Math::RangeRandom( ymin, ymax ), Ogre::Math::RangeRandom( zmin, zmax ) ); + obj->launch(); // obj->mainNode()->setPosition( // dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() // )->sector()->station()->launchPadPosition() + @@ -143,7 +145,7 @@ // dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() // )->sector()->station()->launchPadOrientation() ); - ai->land( dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() )->sector()->station() ); + ai->land( dynamic_cast < UnDockedState *>(resources_->gameStateRoot->activeState() )->sector()->station() ); } startAiObject( ai ); Modified: trunk/src/Avatar.cpp =================================================================== --- trunk/src/Avatar.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Avatar.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -19,7 +19,7 @@ ***************************************************************************/ #include "Avatar.h" -#include "VesselManager.h" +#include "Vessel.h" #include "Equipment.h" namespace OpenGate{ Modified: trunk/src/Entity.cpp =================================================================== --- trunk/src/Entity.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Entity.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -125,43 +125,47 @@ } bool Entity::readPropertiesFromXML( TiXmlHandle & hRoot ){ - if ( !readXMLNode< std::string >( hRoot, "name_"+ ResourceManager::getSingleton().languageSuffix(), - this, &OpenGate::Entity::setName, false ) ){ - readXMLNode< std::string >( hRoot, "name", this, &OpenGate::Entity::setName, true ); - } - //readXMLNode< std::string >( hRoot, "name_de", entity, &OpenGate::Entity::setName, true ); + readXMLNode< std::string >( hRoot, "name_"+ ResourceManager::getSingleton().languageSuffix() + " name_en name", + this, &OpenGate::Entity::setName, true ); + readXMLNode< Uint16 >( hRoot, "object_id", this, &OpenGate::Entity::setID, true ); readXMLNode< Uint8 >( hRoot, "faction_id", this, &OpenGate::Entity::setFactionID, true ); - + readXMLNode< Uint8 >( hRoot, "class_id", this, &OpenGate::Entity::setClassID, false ); - readXMLNode< Uint8 >( hRoot, "techlevel", this, &OpenGate::Entity::setTechLevel, false ); - //readXMLNode< Uint8 >( hRoot, "required_rank", entity, &OpenGate::Entity::setRequieredRank, true ); - + readXMLNode< Uint8 >( hRoot, "techlevel required_rank", this, &OpenGate::Entity::setTechLevel, false ); + readXMLNode< int >( hRoot, "size", this, &OpenGate::Entity::setSize, false ); readXMLNode< int >( hRoot, "mass", this, &OpenGate::Entity::setMass, false ); - if ( !readXMLNode< std::string >( hRoot, "description_" + ResourceManager::getSingleton().languageSuffix(), this, - &OpenGate::Entity::setDescription, false ) ){ - readXMLNode< std::string >( hRoot, "description", this, &OpenGate::Entity::setDescription, false ); - } + readXMLNode< std::string >( hRoot, "description_" + ResourceManager::getSingleton().languageSuffix() + + " description_en description", this, &OpenGate::Entity::setDescription, false ); + readXMLNodes< std::string >( hRoot, "production-center", this, &OpenGate::Entity::addProductionCenter ); readXMLNode< float >( hRoot, "baseyaw", this, &OpenGate::Entity::setBaseYaw, false ); readXMLNode< float >( hRoot, "basepitch", this, &OpenGate::Entity::setBasePitch, false ); readXMLNode< float >( hRoot, "baseroll", this, &OpenGate::Entity::setBaseRoll, false ); + + TiXmlElement * pElem; -// Ogre::Real length = 0; -// pElem = hRoot.ChildElement( "length", 0 ).Element(); -// if ( pElem ) length = toDouble( pElem->FirstChild()->Value() ); -// -// Ogre::Real width = 0; -// pElem = hRoot.ChildElement( "width", 0 ).Element(); -// if ( pElem ) width = toDouble( pElem->FirstChild()->Value() ); -// -// Ogre::Real height = 0; -// pElem = hRoot.ChildElement( "height", 0 ).Element(); -// if ( pElem ) height = toDouble( pElem->FirstChild()->Value() ); -// if ( length > 0 && width > 0 && height > 0 ) vessel->setBaseSize( width, height, length ); + Ogre::Real length = 0; + pElem = hRoot.ChildElement( "size", 0 ).Element(); + if ( pElem ) { + length = toDouble( pElem->FirstChild()->Value() ); + this->setBaseSize( length ); + } + pElem = hRoot.ChildElement( "length", 0 ).Element(); + if ( pElem ) length = toDouble( pElem->FirstChild()->Value() ); + + Ogre::Real width = 0; + pElem = hRoot.ChildElement( "width", 0 ).Element(); + if ( pElem ) width = toDouble( pElem->FirstChild()->Value() ); + + Ogre::Real height = 0; + pElem = hRoot.ChildElement( "height", 0 ).Element(); + if ( pElem ) height = toDouble( pElem->FirstChild()->Value() ); + + if ( length > 0 && width > 0 && height > 0 ) this->setBaseSize( width, height, length ); return true; } Modified: trunk/src/Entity.h =================================================================== --- trunk/src/Entity.h 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Entity.h 2008-05-11 22:19:57 UTC (rev 893) @@ -93,6 +93,7 @@ /*! If size is a scalar value, the length of the entity.*/ void setBaseSize( float size ); + Ogre::Vector3 baseSize( ) const; /*! Base sizes are necessary for resizing the ogremesh */ Modified: trunk/src/EntityManager.cpp =================================================================== --- trunk/src/EntityManager.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/EntityManager.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -46,8 +46,8 @@ } EntityType EntityManager::categoryType( const std::string & category ){ - if ( category == "Commodity" || category == "Commoditys" || - category == "commodity" || category == "commoditys" ) return COMMODITY; + if ( category == "Commodity" || category == "Commodities" || + category == "commodity" || category == "commodities" ) return COMMODITY; else if ( category == "Power Plant" || category == "Power Plants" || category == "Powerplant" || category == "Powerplants" || category == "Power plant" || category == "Power plants" || @@ -71,9 +71,9 @@ category == "MODx" || category == "MODxs" || category == "modx" || category == "modxs" ) return MODX; else if ( category == "Vessel" || category == "Vessels" || - category == "vessel" || category == "Vessels" ) return VESSEL; + category == "vessel" || category == "vessels" ) return VESSEL; - LogManager::getSingleton().warn("Request entity rtti for " + category + " unknown" ); + LogManager::getSingleton().warn("Requested entity rtti for " + category + " unknown" ); return ENTITY; } @@ -92,7 +92,7 @@ case VESSEL: return "Vessel"; } - LogManager::getSingleton().warn("Request name for category " + toStr( type ) + " unknown" ); + LogManager::getSingleton().warn("Requested name for category " + toStr( type ) + " unknown" ); return "unknown"; } @@ -100,7 +100,7 @@ if ( templatesByName_.count( name ) ){ return templatesByName_[ name ]; } else { - LogManager::getSingleton().warn("Request for entity: " + name + " unknown" ); + LogManager::getSingleton().warn( "No entity named: " + name + " registered." ); return NULL; } } @@ -109,11 +109,12 @@ if ( templatesByID_.count( ID ) ){ return templatesByID_[ ID ]; } else { - LogManager::getSingleton().warn( ("Request for entity id: ") + toStr(ID) + " unknown" ); + LogManager::getSingleton().warn( "No entity with ID: " + toStr( ID ) + " registered." ); return NULL; } } +Commodity * EntityManager::commodity( const std::string & name ){ return entity_< Commodity >( name ); } PowerPlant * EntityManager::powerPlant( const std::string & name ){ return entity_< PowerPlant >( name ); } Engine * EntityManager::engine( const std::string & name ){ return entity_< Engine >( name ); } Radar * EntityManager::radar( const std::string & name ){ return entity_< Radar >( name ); } @@ -124,26 +125,40 @@ ModX * EntityManager::modx( const std::string & name ){ return entity_< ModX >( name ); } Ecm * EntityManager::ecm( const std::string & name ){ return entity_< Ecm >( name ); } Vessel * EntityManager::vessel( const std::string & name ){ return entity_< Vessel >( name ); } +Vessel * EntityManager::vessel( Uint16 ID ){ return entity_< Vessel >( ID ); } std::vector < Entity * > EntityManager::allByCategory( const std::string & category ){ - EntityType rtti = NONE; - if ( category != "All" ) rtti = categoryType( category ); - std::vector < Entity * > items; - for ( std::map < std::string, Entity * >::iterator it = templatesByName_.begin(); it != templatesByName_.end(); it ++ ){ - if ( ( category == "All" ) || ( it->second->entityType() == rtti ) ){ - items.push_back( it->second ); - } - } - return items; - } + EntityType rtti = NONE; + if ( category != "All" ) rtti = categoryType( category ); + std::vector < Entity * > items; + for ( std::map < std::string, Entity * >::iterator it = templatesByName_.begin(); it != templatesByName_.end(); it ++ ){ + if ( ( category == "All" ) || ( it->second->entityType() == rtti ) ){ + items.push_back( it->second ); + } + } + return items; +} +std::set < Vessel * > EntityManager::vesselSet( ){ + + std::set < Vessel * > items; + for ( std::map < std::string, Entity * >::iterator it = templatesByName_.begin(); it != templatesByName_.end(); it ++ ){ + if ( it->second->entityType() == VESSEL ){ + items.insert( dynamic_cast< Vessel * >(it->second) ); + } + } + return items; +} + void EntityManager::load( const std::set < std::string > & resourcePaths, const std::string & resourceName ){ Ogre::FileSystemArchive * pArch = new Ogre::FileSystemArchive( (*resourcePaths.begin()) + "/" + resourceName, "FileSystem" ); Ogre::StringVectorPtr files = pArch->find( "*.xml", true, false); for ( unsigned int i = 0; i < (*files).size(); i ++ ){ - log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); - loadAndCreate( (*resourcePaths.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); + if ( (*files)[ i ].rfind( ".mesh.xml" ) == std::string::npos ){ + log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); + loadAndCreate( (*resourcePaths.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); + } } delete pArch; @@ -172,7 +187,12 @@ return NULL; } - if ( strcmp( "equipment", pElem->Value() ) != 0 && strcmp( "container", pElem->Value() ) != 0 ) { + if ( strcmp( "equipment", pElem->Value() ) != 0 && + strcmp( "ship", pElem->Value() ) != 0 && + strcmp( "entity", pElem->Value() ) != 0 && + strcmp( "vessel", pElem->Value() ) != 0 && + strcmp( "commodity", pElem->Value() ) != 0 && + strcmp( "container", pElem->Value() ) != 0 ) { log_->fatal( fileName + " is no entity description" ); return NULL; } @@ -195,6 +215,7 @@ case 6: entity = new Engine(); break; case 7: entity = new Shield(); break; case 8: entity = new Radar(); break; + case 9: entity = new Vessel(); break; case 10: entity = new Gun(); break; case 11: entity = new Missile(); break; default: @@ -529,165 +550,165 @@ // return entity; // } -template<> CommodityManager * Ogre::Singleton< CommodityManager >::ms_Singleton = 0; +// template<> CommodityManager * Ogre::Singleton< CommodityManager >::ms_Singleton = 0; +// +// CommodityManager::CommodityManager(): EntityManager(){ +// } +// +// CommodityManager::~CommodityManager() { +// } +// +// Commodity * CommodityManager::findByName( const std::string & commodityName ){ +// if ( templatesByName_.count( commodityName ) ){ +// return static_cast<Commodity *>(templatesByName_[ commodityName ]); +// } else { +// log_->fatal( std::string( "Unknown commodity with name :" ) + commodityName ); +// return NULL; +// } +// } +// +// std::vector < Entity * > CommodityManager::allCommodities(){ +// std::vector < Entity * > items; +// for ( std::map < std::string, Entity * >::iterator it = templatesByName_.begin(); it != templatesByName_.end(); it ++ ){ +// items.push_back( it->second ); +// } +// return items; +// } +// +// Entity * CommodityManager::loadAndCreate( const std::string & fileName ){ +// +// log_->fout( "Read commodity: " + fileName ); +// +// TiXmlDocument doc( fileName ); +// bool loadOkay = doc.LoadFile(); +// +// if ( !loadOkay ) { +// log_->fatal( std::string( "Failed to load commodity file: " + fileName ) ); +// return NULL; +// } +// +// TiXmlHandle docHandle( &doc ); +// TiXmlElement * pElem; +// TiXmlHandle hRoot( 0 ); +// +// pElem = docHandle.FirstChildElement().Element(); +// hRoot = TiXmlHandle( pElem ); +// +// if ( !pElem ) { +// log_->fatal( fileName + " cannot read first node." ); +// return NULL; +// } +// +// if ( strcmp( "component", pElem->Value() ) != 0 && strcmp( "container", pElem->Value() ) != 0 ){ +// log_->fatal( fileName + " is no commodity description" ); +// return NULL; +// } +// +// Commodity *entity; +// +// //** Mandatory elements; +// pElem = hRoot.ChildElement( "category_id", 0 ).Element(); +// if ( !pElem ) { //** fallback +// pElem = hRoot.ChildElement( "categorie_id", 0 ).Element(); +// } +// if ( pElem ) { +// if ( toInt( pElem->FirstChild()->Value() ) == 1 ){ +// entity = new Commodity; +// } else { +// log_->warn( fileName + " category_id is not 1, so I set them to 1." ); +// entity = new Commodity; +// } +// } else { +// log_->fatal( fileName + " has no category_id (mandatory)." ); +// return NULL; +// } +// +// pElem = hRoot.ChildElement( "name_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); +// if ( !pElem ){ +// //** Fallback to english +// pElem = hRoot.ChildElement( "name_en", 0 ).Element(); +// } +// if ( pElem ) { +// entity->setName( pElem->FirstChild()->Value() ); +// } else { +// log_->fatal( fileName + " has no name_en (mandatory)." ); +// return NULL; +// } +// +// pElem = hRoot.ChildElement( "object_id", 0 ).Element(); +// if ( pElem ) { +// entity->setID( toInt( pElem->FirstChild()->Value() ) ); +// } else { +// log_->fatal( fileName + " has no object_id (mandatory)." ); +// return NULL; +// } +// +// +// //** Image name for the entity is derived from filename; +// std::string basename( fileName.substr( fileName.rfind( "/" ) + 1 ) ); +// entity->setImageName( basename.substr( 0, basename.find( ".xml" ) ) ); +// +// //** Generic data +// pElem = hRoot.ChildElement( "class_id", 0 ).Element(); +// if ( pElem ) entity->setClassName( ResourceManager::getSingleton().className( toInt( pElem->FirstChild()->Value() ) ) ); +// +// pElem = hRoot.ChildElement( "techlevel", 0 ).Element(); +// if ( pElem ) entity->setTechLevel( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "size", 0 ).Element(); +// if ( pElem ) entity->setSize( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "mass", 0 ).Element(); +// if ( pElem ) entity->setMass( toInt( pElem->FirstChild()->Value() ) ); +// +// pElem = hRoot.ChildElement( "faction_id", 0 ).Element(); +// if ( pElem ) entity->setFactionID( toInt( pElem->FirstChild()->Value() ) ); +// +// //** Additional Data +// pElem = hRoot.ChildElement( "description_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); +// if ( pElem ) entity->setDescription( pElem->FirstChild()->Value() ); +// +// //** Specific Data +// pElem = hRoot.ChildElement( "id", 0 ).Element(); +// if ( pElem ) entity->setCommodityID( pElem->FirstChild()->Value() ); +// pElem = hRoot.ChildElement( "melting-point", 0 ).Element(); +// if ( pElem ) entity->setMeltingPoint( toInt( pElem->FirstChild()->Value() ) ); +// pElem = hRoot.ChildElement( "gravitic-sig", 0 ).Element(); +// if ( pElem ) entity->setGraviticSig( toFloat( pElem->FirstChild()->Value() ) ); +// +// //** Production Data +// std::set < std::string > productionCenters; +// for ( pElem = hRoot.FirstChild( "production-center" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { +// productionCenters.insert( pElem->FirstChild()->Value() ); //!< \todo check return value! +// } +// // entity->setProductionCenters( productionCenters ); +// //! \todo Add required components +// +// if ( templatesByName_.count( entity->name() ) == 0 ){ +// templatesByName_[ entity->name() ] = entity; +// templatesByID_[ entity->id() ] = entity; +// +// factions_.insert( entity->factionName() ); +// // log_->info( std::string( "Loaded Commodity: " ) + entity->factionName() + "/" + entity->name() ); +// } else { +// log_->warn( std::string( "Equipment with name: " ) + entity->factionName() + "/" + entity->name() + +// " allready loaded" ); +// } +// return entity; +// } +// +// CommodityManager & CommodityManager::getSingleton( ){ +// assert( ms_Singleton ); +// return ( *ms_Singleton ); +// } +// +// CommodityManager * CommodityManager::getSingletonPtr( ){ +// if ( ms_Singleton == NULL ){ +// LogManager::getSingleton().fatal( "CommodityManager not initialized." ); +// } +// return ms_Singleton; +// } -CommodityManager::CommodityManager(): EntityManager(){ } -CommodityManager::~CommodityManager() { -} -Commodity * CommodityManager::findByName( const std::string & commodityName ){ - if ( templatesByName_.count( commodityName ) ){ - return static_cast<Commodity *>(templatesByName_[ commodityName ]); - } else { - log_->fatal( std::string( "Unknown commodity with name :" ) + commodityName ); - return NULL; - } -} - -std::vector < Entity * > CommodityManager::allCommodities(){ - std::vector < Entity * > items; - for ( std::map < std::string, Entity * >::iterator it = templatesByName_.begin(); it != templatesByName_.end(); it ++ ){ - items.push_back( it->second ); - } - return items; -} - -Entity * CommodityManager::loadAndCreate( const std::string & fileName ){ - - log_->fout( "Read commodity: " + fileName ); - - TiXmlDocument doc( fileName ); - bool loadOkay = doc.LoadFile(); - - if ( !loadOkay ) { - log_->fatal( std::string( "Failed to load commodity file: " + fileName ) ); - return NULL; - } - - TiXmlHandle docHandle( &doc ); - TiXmlElement * pElem; - TiXmlHandle hRoot( 0 ); - - pElem = docHandle.FirstChildElement().Element(); - hRoot = TiXmlHandle( pElem ); - - if ( !pElem ) { - log_->fatal( fileName + " cannot read first node." ); - return NULL; - } - - if ( strcmp( "component", pElem->Value() ) != 0 && strcmp( "container", pElem->Value() ) != 0 ){ - log_->fatal( fileName + " is no commodity description" ); - return NULL; - } - - Commodity *entity; - - //** Mandatory elements; - pElem = hRoot.ChildElement( "category_id", 0 ).Element(); - if ( !pElem ) { //** fallback - pElem = hRoot.ChildElement( "categorie_id", 0 ).Element(); - } - if ( pElem ) { - if ( toInt( pElem->FirstChild()->Value() ) == 1 ){ - entity = new Commodity; - } else { - log_->warn( fileName + " category_id is not 1, so I set them to 1." ); - entity = new Commodity; - } - } else { - log_->fatal( fileName + " has no category_id (mandatory)." ); - return NULL; - } - - pElem = hRoot.ChildElement( "name_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); - if ( !pElem ){ - //** Fallback to english - pElem = hRoot.ChildElement( "name_en", 0 ).Element(); - } - if ( pElem ) { - entity->setName( pElem->FirstChild()->Value() ); - } else { - log_->fatal( fileName + " has no name_en (mandatory)." ); - return NULL; - } - - pElem = hRoot.ChildElement( "object_id", 0 ).Element(); - if ( pElem ) { - entity->setID( toInt( pElem->FirstChild()->Value() ) ); - } else { - log_->fatal( fileName + " has no object_id (mandatory)." ); - return NULL; - } - - - //** Image name for the entity is derived from filename; - std::string basename( fileName.substr( fileName.rfind( "/" ) + 1 ) ); - entity->setImageName( basename.substr( 0, basename.find( ".xml" ) ) ); - - //** Generic data - pElem = hRoot.ChildElement( "class_id", 0 ).Element(); - if ( pElem ) entity->setClassName( ResourceManager::getSingleton().className( toInt( pElem->FirstChild()->Value() ) ) ); - - pElem = hRoot.ChildElement( "techlevel", 0 ).Element(); - if ( pElem ) entity->setTechLevel( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "size", 0 ).Element(); - if ( pElem ) entity->setSize( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "mass", 0 ).Element(); - if ( pElem ) entity->setMass( toInt( pElem->FirstChild()->Value() ) ); - - pElem = hRoot.ChildElement( "faction_id", 0 ).Element(); - if ( pElem ) entity->setFactionID( toInt( pElem->FirstChild()->Value() ) ); - - //** Additional Data - pElem = hRoot.ChildElement( "description_" + ResourceManager::getSingleton().languageSuffix(), 0 ).Element(); - if ( pElem ) entity->setDescription( pElem->FirstChild()->Value() ); - - //** Specific Data - pElem = hRoot.ChildElement( "id", 0 ).Element(); - if ( pElem ) entity->setCommodityID( pElem->FirstChild()->Value() ); - pElem = hRoot.ChildElement( "melting-point", 0 ).Element(); - if ( pElem ) entity->setMeltingPoint( toInt( pElem->FirstChild()->Value() ) ); - pElem = hRoot.ChildElement( "gravitic-sig", 0 ).Element(); - if ( pElem ) entity->setGraviticSig( toFloat( pElem->FirstChild()->Value() ) ); - - //** Production Data - std::set < std::string > productionCenters; - for ( pElem = hRoot.FirstChild( "production-center" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { - productionCenters.insert( pElem->FirstChild()->Value() ); //!< \todo check return value! - } - // entity->setProductionCenters( productionCenters ); - //! \todo Add required components - - if ( templatesByName_.count( entity->name() ) == 0 ){ - templatesByName_[ entity->name() ] = entity; - templatesByID_[ entity->id() ] = entity; - - factions_.insert( entity->factionName() ); -// log_->info( std::string( "Loaded Commodity: " ) + entity->factionName() + "/" + entity->name() ); - } else { - log_->warn( std::string( "Equipment with name: " ) + entity->factionName() + "/" + entity->name() + - " allready loaded" ); - } - return entity; -} - -CommodityManager & CommodityManager::getSingleton( ){ - assert( ms_Singleton ); - return ( *ms_Singleton ); -} - -CommodityManager * CommodityManager::getSingletonPtr( ){ - if ( ms_Singleton == NULL ){ - LogManager::getSingleton().fatal( "CommodityManager not initialized." ); - } - return ms_Singleton; -} - -} - - Modified: trunk/src/EntityManager.h =================================================================== --- trunk/src/EntityManager.h 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/EntityManager.h 2008-05-11 22:19:57 UTC (rev 893) @@ -79,6 +79,7 @@ std::vector < Entity * > allByCategory( const std::string & category ); + Commodity * commodity( const std::string & name ); PowerPlant * powerPlant( const std::string & name ); Engine * engine( const std::string & name ); Radar * radar( const std::string & name ); @@ -89,64 +90,50 @@ ModX * modx( const std::string & name ); Ecm * ecm( const std::string & name ); Vessel * vessel( const std::string & name ); - + Vessel * vessel( Uint16 ID ); + + std::set < Vessel * > vesselSet(); + protected: template < class EntityType > EntityType * entity_( const std::string & name ){ - Entity * item = entity( name ); - if ( !item ) { - LogManager::getSingleton().warn( "No entity named: " + name + " registered." ); - return NULL; - } + Entity * item = entity( name ); + if ( !item ) { + return NULL; + } EntityType tmp; //**very ugly - if ( item->entityType() == tmp.entityType() ) { - return dynamic_cast< EntityType * >(item); - } else { - LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + name + - " is a " + categoryName( item->entityType() ) ); - } - return NULL; - } + if ( item->entityType() == tmp.entityType() ) { + return dynamic_cast< EntityType * >(item); + } else { + LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + name + + " is a " + categoryName( item->entityType() ) ); + } + return NULL; + } + template < class EntityType > EntityType * entity_( Uint16 ID ){ + Entity * item = entity( ID ); + if ( !item ) { + return NULL; + } + EntityType tmp; //**very ugly + if ( item->entityType() == tmp.entityType() ) { + return dynamic_cast< EntityType * >(item); + } else { + LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + toStr( ID ) + + " is a " + categoryName( item->entityType() ) ); + } + return NULL; + } + LogManager * log_; ResourceManager * resources_; - - std::map < std::string, Entity * > templatesByName_; + std::map < std::string, Entity * > templatesByName_; std::map < Uint16, Entity * > templatesByID_; - std::set < std::string > factions_; }; -/*! - * \brief This class is able to load equipment (reactors, engines, guns, etc.) - * from XML files. - * \author Christoph Brill <eg...@us...> - */ -class CommodityManager : public Ogre::Singleton< CommodityManager >, public EntityManager{ -public: - - /*! Get the single instance of the EquipmentManager */ - static CommodityManager & getSingleton( ); - - /*! Get the pointer to single instance of the EquipmentManager */ - static CommodityManager * getSingletonPtr( ); - - /*! Constructor */ - CommodityManager(); - - /*! Destructor that free's all loaded vessels */ - virtual ~CommodityManager(); - - virtual Entity * loadAndCreate( const std::string & filename ); - - /*! This returns a commodity by it's given name \remarks The commodity needs to be loaded before \param commodityName The name of a commodity */ - Commodity * findByName( const std::string & commodityName ); - - std::vector < Entity * > allCommodities(); - -}; - } // namespace OpenGate #endif //_OPENGATE_ENTITYMANAGER_H Modified: trunk/src/GameStateManager.cpp =================================================================== --- trunk/src/GameStateManager.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/GameStateManager.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -38,7 +38,7 @@ #include "Sector.h" #include "InputManager.h" #include "AiManager.h" -#include "VesselManager.h" +#include "Vessel.h" #include "OpenALSoundManager.h" #include "OpcodeWrapper.h" #include "UnDockedState.h" @@ -56,7 +56,6 @@ GameStateManager::GameStateManager( NetworkClient & nw, bool dialog ) { resources_.network = & nw; log_ = NULL; - vesselManager_ = NULL; configDialog_ = NULL; log_ = LogManager::getSingletonPtr(); @@ -136,21 +135,11 @@ delete resources_.console; resources_.console = NULL; } - if ( commodityManager_ ){ - log_->info( "Shutdown commoditymanager." ); - delete commodityManager_; - commodityManager_ = NULL; - } if ( resources_.entityManager ){ log_->info( "Shutdown entitymanager." ); delete resources_.entityManager; resources_.entityManager = NULL; } - if ( vesselManager_ ){ - log_->info( "Shutdown vesselmanager." ); - delete vesselManager_; - vesselManager_ = NULL; - } if ( resources_.soundManager ) { log_->info( "Shutdown soundmanager." ); delete resources_.soundManager; @@ -409,15 +398,9 @@ std::string >( &GameStateManager::initialiseSoundManager, "initialise sound manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), - std::string >( &GameStateManager::initialiseVesselManager, - "initialise vessel manager" ) ); + std::string >( &GameStateManager::initialiseEntityManager, + "initialise entity manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), - std::string >( &GameStateManager::initialiseCommodityManager, - "initialise commodity manager" ) ); - loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), - std::string >( &GameStateManager::initialiseEquipmentManager, - "initialise equipment manager" ) ); - loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), std::string >( &GameStateManager::initialiseAiManager, "initialise ai manager" ) ); loadResourcesVector_.push_back( std::pair< bool (GameStateManager::*)( ), @@ -501,33 +484,30 @@ return true; } -bool GameStateManager::initialiseVesselManager(){ - vesselManager_ = new VesselManager( ); - vesselManager_->load( resources_.resourcePaths(), "ships" ); - return true; -} +// bool GameStateManager::initialiseVesselManager(){ +// vesselManager_ = new VesselManager( ); +// vesselManager_->load( resources_.resourcePaths(), "ships" ); +// return true; +// } -bool GameStateManager::initialiseCommodityManager(){ - commodityManager_ = new CommodityManager( ); - commodityManager_->load( resources_.resourcePaths(), "commodities" ); - return true; -} - -bool GameStateManager::initialiseEquipmentManager(){ +bool GameStateManager::initialiseEntityManager(){ resources_.entityManager = new EntityManager( ); + resources_.entityManager->load( resources_.resourcePaths(), "commodities" ); resources_.entityManager->load( resources_.resourcePaths(), "engines" ); resources_.entityManager->load( resources_.resourcePaths(), "capacitors" ); resources_.entityManager->load( resources_.resourcePaths(), "radars" ); resources_.entityManager->load( resources_.resourcePaths(), "shields" ); + //resources_.entityManager->load( resources_.resourcePaths(), "ecms" ); resources_.entityManager->load( resources_.resourcePaths(), "power_plants" ); resources_.entityManager->load( resources_.resourcePaths(), "guns" ); resources_.entityManager->load( resources_.resourcePaths(), "missiles" ); + resources_.entityManager->load( resources_.resourcePaths(), "ships" ); return true; } bool GameStateManager::createAvatar(){ resources_.avatar = new Avatar( resources_.network->userName(), resources_.network->userID() ); - resources_.avatar->setVessel( *VesselManager::getSingleton().vessel( "apteryx" ) ); + resources_.avatar->setVessel( *resources_.entityManager->vessel( "apteryx" ) ); resources_.avatar->vessel( )->setPowerPlant( resources_.entityManager->powerPlant( "Spud" ) ); resources_.avatar->vessel( )->setEngine( resources_.entityManager->engine( "T-E-15" ) ); resources_.avatar->vessel( )->setRadar( resources_.entityManager->radar( "Outlook" ) ); @@ -653,7 +633,7 @@ bool showHelp = false; if ( aiName != "help" ){ if ( stateStack_.back()->name() == "UnDockedState" ){ - if ( VesselManager::getSingleton().vessel( aiName ) ){ + if ( resources_.entityManager->vessel( aiName ) ){ //dynamic_cast< UnDockedState * >( stateStack_.back() )->spawnAI( aiName ); } else { showHelp = true; @@ -666,9 +646,9 @@ } if ( showHelp ){ - std::set< Vessel * > vessel( VesselManager::getSingleton().factionVessels( "All" ) ); + std::vector< Entity * > vessel( resources_.entityManager->allByCategory( "Vessel" ) ); std::string vesselNames("Vessels available: "); - for ( std::set< Vessel * >::iterator it = vessel.begin(); it!= vessel.end(); it ++ ){ + for ( std::vector< Entity * >::iterator it = vessel.begin(); it!= vessel.end(); it ++ ){ vesselNames += (*it)->name() + " "; } LogManager::getSingleton().info( vesselNames ); Modified: trunk/src/GameStateManager.h =================================================================== --- trunk/src/GameStateManager.h 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/GameStateManager.h 2008-05-11 22:19:57 UTC (rev 893) @@ -33,8 +33,6 @@ class InputManager; class VesselManager; class ConfigDialog; -class EquipmentManager; -class CommodityManager; /*! * \brief The class defines the gamestate manager. @@ -74,9 +72,7 @@ //** load id, rank matrix etc. bool initialiseMiscResources(); bool initialiseSoundManager(); - bool initialiseVesselManager(); - bool initialiseCommodityManager(); - bool initialiseEquipmentManager(); + bool initialiseEntityManager(); bool initialiseAiManager(); bool initialiseCollisionManager(); bool createAvatar(); @@ -138,9 +134,7 @@ bool initialiseOgreEngine_( bool dialog ); LogManager * log_; - VesselManager * vesselManager_; - EquipmentManager * equipmentManager_; - CommodityManager * commodityManager_; +// VesselManager * vesselManager_; std::vector< GameState * > stateStack_; std::vector< StateInfo > states_; Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Makefile.am 2008-05-11 22:19:57 UTC (rev 893) @@ -91,8 +91,6 @@ UnDockedState.h \ Vessel.h \ Vessel.cpp \ - VesselManager.h \ - VesselManager.cpp \ metaserver.h \ metaserver.cpp Modified: trunk/src/MarketDialog.cpp =================================================================== --- trunk/src/MarketDialog.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/MarketDialog.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -178,12 +178,8 @@ std::vector < Entity * > items; - if ( selectedCategory_ == "Commodities" ){ - items = CommodityManager::getSingleton().allCommodities(); - } else { - items = ResourceManager::getSingleton().entityManager->allByCategory( selectedCategory_ ); - } - + items = ResourceManager::getSingleton().entityManager->allByCategory( selectedCategory_ ); + switch ( sortBy_ ){ case Alphanumeric: if ( sortAscending_ ) sort( items.begin(), items.end(), &OpenGate::lesserName ); Modified: trunk/src/Moveable.cpp =================================================================== --- trunk/src/Moveable.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Moveable.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -40,14 +40,11 @@ readXMLNode< float >( hRoot, "pitch", this, &OpenGate::Moveable::setPitch, false ); readXMLNode< float >( hRoot, "roll", this, &OpenGate::Moveable::setRoll, false ); readXMLNode< float >( hRoot, "armor", this, &OpenGate::Moveable::setArmor, false ); - - if ( !readXMLNode< float >( hRoot, "dragfactor", this, &OpenGate::Moveable::setDragFactor, false ) ) { - readXMLNode< float >( hRoot, "drag_factor", this, &OpenGate::Moveable::setDragFactor, false ); - } - + readXMLNode< float >( hRoot, "dragfactor drag_factor", this, &OpenGate::Moveable::setDragFactor, false ); + if ( !readXMLNode< std::string >( hRoot, "mesh", this, &OpenGate::Moveable::setMesh, false ) ){ - try{ - setMesh( name_, false ); + try { + setMesh( name_, true ); } catch( Ogre::Exception & e ){ LogManager::getSingleton().warn( e.what() ); } @@ -59,8 +56,8 @@ if ( genPath ){ fileName = std::string("ships") + PATHSEPARATOR + strCopyToLowerCase( factionName_ ) + PATHSEPARATOR - + strCopyToLowerCase( name_ ) + PATHSEPARATOR - + meshName; + + strReplaceBlankWithUnderscore( strCopyToLowerCase( name_ ) ) + PATHSEPARATOR + + strReplaceBlankWithUnderscore( strCopyToLowerCase( meshName ) ); } else { fileName = meshName; } Modified: trunk/src/OpcodeWrapper.cpp =================================================================== --- trunk/src/OpcodeWrapper.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/OpcodeWrapper.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -69,7 +69,12 @@ } } -void OpcodeCollisionDetection::free( ){ +void OpcodeCollisionDetection::free( ){ + + std::vector< OgreOpcode::CollisionObject * > activeObjects( collideInSectorContext_->getAttachedObjects() ); + + std::cout << "OpcodeCollisionDetection::free( ) " << activeObjects.size() << std::endl; + if ( collisionManager_ ) delete collisionManager_; collisionManager_ = NULL; } @@ -155,10 +160,12 @@ if ( active_ ){ OgreOpcode::ICollisionShape * shape = obj->getShape(); - if ( obj && attachedSet_.find( obj ) != attachedSet_.end() ){ - collideInSectorContext_->destroyObject( obj ); - attachedSet_.erase( obj ); + if ( obj && attachedSet_.find( obj ) == attachedSet_.end() ){ + attach( obj ); } + collideInSectorContext_->destroyObject( obj ); + attachedSet_.erase( obj ); + collisionManager_->detachShape( shape ); collisionManager_->destroyShape( shape ); obj = NULL; Modified: trunk/src/OpcodeWrapper.h =================================================================== --- trunk/src/OpcodeWrapper.h 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/OpcodeWrapper.h 2008-05-11 22:19:57 UTC (rev 893) @@ -63,11 +63,7 @@ bool checkCollideRay( BaseObject * obj, const Ogre::Ray & ray, double rayLength ); void changeCollClass( OgreOpcode::CollisionObject * collObj, const std::string & collClass ); - -// static OpcodeCollisionDetection & getSingleton( ); -// -// static OpcodeCollisionDetection * getSingletonPtr( ); - + protected: OgreOpcode::CollisionContext * collideInSectorContext_; OgreOpcode::CollisionManager * collisionManager_; Modified: trunk/src/Planet.cpp =================================================================== --- trunk/src/Planet.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Planet.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -199,3 +199,40 @@ } // namespace OpenGate +// if ( !1 ) { +// planetNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( "PlanetNode" ); +// +// Ogre::ManualObject * planet = sceneMgr_->createManualObject( "Planet" ); +// // planet->setUseIdentityProjection( true ); +// // planet->setUseIdentityView( true ); +// +// planet->begin( "OpenGate/RedPlanet", Ogre::RenderOperation::OT_TRIANGLE_LIST); +// planet->position( Ogre::Vector3( -1.0, -1.0, 200.0 ) ); +// planet->textureCoord( 0, 0 ); +// planet->position( Ogre::Vector3( 1.0, -1.0, 200.0 ) ); +// planet->textureCoord( 1, 0 ); +// planet->position( Ogre::Vector3( 1.0, 1.0, 200.0 ) ); +// planet->textureCoord( 1, 1 ); +// planet->position( Ogre::Vector3( -1.0, 1.0, 200.0 ) ); +// planet->textureCoord( 0, 1 ); +// planet->quad( 0, 1, 2, 3 ); +// planet->end(); +// Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); +// planet->setBoundingBox( aabInf ); +// planetNode_->attachObject( planet ); +// planetNode_->scale( 20000, 20000, 1 ); +// planetNode_->setPosition( Ogre::Vector3( 20000.0, 10000.0, 50000 ) ); +// } +// if ( planetNode_ ){ // updateLoop +// Ogre::Vector3 src = planetNode_->getWorldOrientation() * Ogre::Vector3::UNIT_Z; +// src.normalise(); +// +// Ogre::Vector3 target( avatar_->mainNode()->getPosition() - planetNode_->getWorldPosition() ); +// target.normalise(); +// +// Ogre::Quaternion rot = src.getRotationTo( target ); +// rot.normalise(); +// +// planetNode_->setPosition( Ogre::Vector3( 20000.0, 10000.0, 50000 ) + avatar_->mainNode()->getPosition() ); +// planetNode_->rotate( rot, Ogre::Node::TS_PARENT ); +// } Modified: trunk/src/ResourceManager.cpp =================================================================== --- trunk/src/ResourceManager.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/ResourceManager.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -139,8 +139,10 @@ Ogre::StringVectorPtr files = pArch->find( "*.xml", true, false); for ( unsigned int i = 0; i < (*files).size(); i ++ ){ - log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); - loadAndCreate( (*resourcePaths_.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); + if ( (*files)[ i ].rfind( ".mesh.xml" ) == std::string::npos ){ + log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); + loadAndCreate( (*resourcePaths_.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); + } } delete pArch; Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2008-05-11 17:20:23 UTC (rev 892) +++ trunk/src/Sector.cpp 2008-05-11 22:19:57 UTC (rev 893) @@ -27,8 +27,9 @@ #include "Projectile.h" #include "Station.h" #include "Planet.h" -#include "VesselManager.h" +#include "Vessel.h" #include "Equipment.h" +#include "EntityManager.h" #include "SectorObjectMoveable.h" #include "SectorObjectAvatar.h" #include "SectorObjectVessel.h" @@ -77,7 +78,6 @@ : sceneMgr_( sceneMgr ), network_( network ) { radar_ = true; - planetNode_ = NULL; planet_ = NULL; koordAxisNode_ = NULL; starsNode_ = NULL; @@ -137,67 +137,29 @@ planet_->lighting( true ); } - if ( !1 ) { - planetNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( "PlanetNode" ); - - Ogre::ManualObject * planet = sceneMgr_->createManualObject( "Planet" ); - // planet->setUseIdentityProjection( true ); - // planet->setUseIdentityView( true ); - - planet->begin( "OpenGate/RedPlanet", Ogre::RenderOperation::OT_TRIANGLE_LIST); - planet->position( Ogre::Vector3( -1.0, -1.0, 200.0 ) ); - planet->textureCoord( 0, 0 ); - planet->position( Ogre::Vector3( 1.0, -1.0, 200.0 ) ); - planet->textureCoord( 1, 0 ); - planet->position( Ogre::Vector3( 1.0, 1.0, 200.0 ) ); - planet->textureCoord( 1, 1 ); - planet->position( Ogre::Vector3( -1.0, 1.0, 200.0 ) ); - planet->textureCoord( 0, 1 ); - planet->quad( 0, 1, 2, 3 ); - planet->end(); - Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); - planet->setBoundingBox( aabInf ); - planetNode_->attachObject( planet ); - planetNode_->scale( 20000, 20000, 1 ); - planetNode_->setPosition( Ogre::Vector3( 20000.0, 10000.0, 50000 ) ); - } - populate( "testsector.xml" ); createKoordAxis( ); } Sector::~Sector( ){ - for ( std::map< long, SectorObjectMoveable * >::iterator it = movableObjects_.begin(); it != movableObjects_.end();){ -// log_->info( "Destructing: " + it->second->name() ); - destruct_( (it++)->second ); - // log_->info( "done: " ); - } - - for ( std::set< SectorObject * >::iterator it = sectorObjects_.begin(); it != sectorObjects_.end(); ){ - // log_->info( "Destructing: " + (*it)->name() ); + for ( std::set< SectorObject * >::iterator it = sectorObjects_.begin(); it != sectorObjects_.end(); it ++){ + // log_->info( "Sector::~Sector( ) deleting sector object: " + (*it)->name() ); if ( radar_ && (*it)->isOnRadar() ){ - Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); - Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); - radarMap->removeChild( (*it)->dotA()->getName() ); - radarMap->removeChild( (*it)->dotB()->getName() ); + Ogre::Overlay * radar = Ogre::OverlayManager::getSingleton().getByName( "Radar" ); + Ogre::OverlayContainer * radarMap = radar->getChild( "Radar/Map" ); + radarMap->removeChild( (*it)->dotA()->getName() ); + radarMap->removeChild( (*it)->dotB()->getName() ); } delete *it; - sectorObjects_.erase( (*it++) ); } sceneMgr_->destroyLight("MainLight" ); if ( planet_ ) { delete planet_; } - if ( planetNode_ ){ - sceneMgr_->destroyManualObject( "Planet" ); - sceneMgr_->getRootSceneNode()->removeAndDestroyChild( planetNode_->getName() ); - } - planetNode_ = NULL; - if ( koordAxisNode_ ) { koordAxisNode_->detachObject( koordAxisMO_ ); sceneMgr_->destroyManualObject( koordAxisMO_->getName() ); @@ -207,6 +169,11 @@ for ( std::map< std::string, std::deque< SectorObject * > >::iterator it = objectHeap_.begin(); it != objectHeap_.end(); it ++ ){ for_each( (*it).second.begin(), (*it).second.end(), deletePtr() ); +// std::cout << (*it).first << std::endl; +// for ( int i = 0; i < (*it).second.size(); i ++ ){ +// std::cout << (*it).second[ i ]->name() << std::endl; +// delete (*it).second[ i ]; +// } } } @@ -251,31 +218,31 @@ sceneMgr_->setSkyBox( true, "OpenGate/SimpleSkyBox1" ); } - pElem = hRoot.ChildElement( "vesselschool", 0 ).Element(); - if ( pElem ){ - std::string schoolclass( pElem->FirstChild()->Value() ); +// pElem = hRoot.ChildElement( "vesselschool", 0 ).Element(); +// if ( pElem ){ +// std::string schoolclass( pElem->FirstChild()->Value() ); +// +// if ( schoolclass == "all" ){ +// std::set < std::string > factions = VesselManager::getSingleton().factionNames(); +// int factionCounter = 0; +// for ( std::set < std::string >::iterator factIt = factions.begin(); factIt != factions.end(); factIt ++ ){ +// std::set < Vessel * > vessels( VesselManager::getSingleton().factionVessels( (*factIt) ) ); +// int vesselCounter = 0; +// for ( std::set < Vessel * >::iterator it = vessels.begin(); it != vessels.end(); it ++ ){ +// SectorObject * obj = createStaticObject( (*it)->meshPtr().get()->getName(), +// (*it)->factionName() + "/" + (*it)->name(), +// Ogre::Vector3( -1000.0, 50 * factionCounter, +// -100.0 + 100 * vesselCounter ) ); +// +// obj->setBaseRot( (*it)->baseYaw(), (*it)->basePitch(), (*it)->baseRoll() ); +// obj->setBaseSize( (*it)->baseSize() ); +// vesselCounter++; +// } +// factionCounter++; +// } +// } +// } - if ( schoolclass == "all" ){ - std::set < std::string > factions = VesselManager::getSingleton().factionNames(); - int factionCounter = 0; - for ( std::set < std::string >::iterator factIt = factions.begin(); factIt != factions.end(); factIt ++ ){ - std::set < Vessel * > vessels( VesselManager::getSingleton().factionVessels( (*factIt) ) ); - int vesselCounter = 0; - for ( std::set < Vessel * >::iterator it = vessels.begin(); it != vessels.end(); it ++ ){ - SectorObject * obj = createStaticObject( (*it)->meshPtr().get()->getName(), - (*it)->factionName() + "/" + (*it)->name(), - Ogre::Vector3( -1000.0, 50 * factionCounter, - -100.0 + 100 * vesselCounter ) ); - - obj->setBaseRot( (*it)->baseYaw(), (*it)->basePitch(), (*it)->baseRoll() ); - obj->setBaseSize( (*it)->baseSize() ); - vesselCounter++; - } - factionCounter++; - } - } - } - //** Load stations for ( pElem = hRoot.FirstChild( "station" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement("station") ) { std::string name; @@ -399,19 +366,7 @@ if ( planet_ ){ planet_->update( elapsedTime ); } - if ( planetNode_ ){ - Ogre::Vector3 src = planetNode_->getWorldOrientation() * Ogre::Vector3::UNIT_Z; - src.normalise(); - - Ogre::Vector3 target( avatar_->mainNode()->getPosition() - planetNode_->getWorldPosition() ); - target.normalise(); - - Ogre::Quaternion rot = src.getRotationTo( target ); - rot.normalise(); - - planetNode_->setPosition( Ogre::Vector3( 20000.0, 10000.0, 50000 ) + avatar_->mainNode()->getPosition() ); - planetNode_->rotate( rot, Ogre::Node::TS_PARENT ); - } + if ( starsNode_ ) starsNode_->setPosition( avatar_->mainNode()->getPosition() ); if ( radar_ ){ @@ -556,16 +511,27 @@ SectorObjectVessel * Sector::createVessel( const Ogre::String & name, Uint32 userID, Uint8 childID, Vessel & vessel ){ - SectorObjectVessel * obj = new SectorObjectVessel( name + toStr( childIDCounter_++ ), - this, userID, childIDCounter_, new Vessel( vessel ) ); + SectorObjectVessel * obj; + if ( objectHeap_[ vessel.name() ].empty() ){ + childIDCounter_++; + obj = new SectorObjectVessel( name + "_" + toStr( childIDCounter_ ), + this, userID, childIDCounter_, new Vessel( vessel ) ); + log_->debug( "Sector::createVessel new " + obj->name() ); + } else { + obj = dynamic_cast< SectorObjectVessel * >( objectHeap_[ vessel.name() ].front() ); + objectHeap_[ vessel.name() ].pop_front(); + obj->reset(); + log_->debug( "Sector::createVessel reuse " + obj->name() ); + } + sectorObjects_.insert( obj ); if ( !movableObjects_.count( obj->globalID() ) ){ movableObjects_[ obj->globalID() ] = obj; } else { std::cout << "Sector::createVessel: globalID allready exist:" << name << std::endl; } -//** ist das notwendig ? localAiObjects_[ obj->globalID() ] = obj; + obj->setActive( true ); return obj; } @@ -576,14 +542,14 @@ //if ( objectHeap_.count( missile.name() ) == 0 ){ if ( objectHeap_[ missile.name() ].empty() ){ childIDCounter_++; - obj = new SectorObjectMissile( name + toStr( childIDCounter_ ), + obj = new SectorObjectMissile( name + "_" + toStr( childIDCounter_ ), this, userID, childIDCounter_, new Missile( missile ) ); - // log_->debug( "Sector::createMissile new " + obj->name() ); + //log_->debug( "Sector::createMissile new " + obj->name() ); } else { obj = dynamic_cast< SectorObjectMissile * >( objectHeap_[ missile.name() ].front() ); objectHeap_[ missile.name() ].pop_front(); obj->reset(); - // log_->debug( "Sector::createMissile reuse " + obj->name() ); + //log_->debug( "Sector::createMissile reuse " + obj->name() ); } sectorObjects_.insert( obj ); @@ -598,7 +564,7 @@ } void Sector::createAvatarObject( Avatar & avatar ){ - log_->info( std::string( "Create avatar: " ) + avatar.name() ); + log_->info( std::string( "Sector::createAvatarObject: " ) + avatar.name() ); avatar_ = new SectorObjectAvatar( avatar.name(), this, avatar.userID(), avatar.vessel() ); sectorObjects_.insert( avatar_ ); movableObjects_[ avatar_->userID() ] = avatar_; @@ -622,7 +588,7 @@ void Sector::destruct_( SectorObject * obj ){ if ( obj ){ - // log_->debug( "Sector::destruct_ object: " + obj->name() + " " + toStr( obj->rtti() ) ); + log_->debug( "Sector::destruct_ object: " + obj->name() + " " + toStr( obj->rtti() ) ); sectorObjects_.erase( obj ); if ( listener_->target() == obj ) selectNextTarget( ); @@ -642,7 +608,8 @@ // it->second->setTarget( NULL ); // } // } - + obj->setActive(... [truncated message content] |
From: <spo...@us...> - 2008-05-14 21:33:25
|
Revision: 897 http://opengate.svn.sourceforge.net/opengate/?rev=897&view=rev Author: spom_spom Date: 2008-05-14 14:33:27 -0700 (Wed, 14 May 2008) Log Message: ----------- Added beacon as sector object Modified Paths: -------------- trunk/data/misc/beacon.mesh trunk/data/misc/testsector.xml trunk/src/AiCommands.h trunk/src/AiManager.cpp trunk/src/AiObject.cpp trunk/src/AiObject.h trunk/src/Entity.cpp trunk/src/Entity.h trunk/src/EntityManager.cpp trunk/src/Equipment.h trunk/src/Moveable.cpp trunk/src/Moveable.h trunk/src/OpcodeWrapper.cpp trunk/src/OpcodeWrapper.h trunk/src/Projectile.h trunk/src/Sector.cpp trunk/src/Sector.h trunk/src/SectorObject.cpp trunk/src/SectorObject.h trunk/src/SectorObjectMissile.cpp trunk/src/SectorObjectMoveable.cpp trunk/src/SectorObjectMoveable.h trunk/src/SectorObjectVessel.cpp trunk/src/Station.cpp trunk/src/Station.h trunk/src/UnDockedState.cpp trunk/src/Vessel.cpp trunk/src/Vessel.h trunk/src/common.h trunk/src/metaserver.cpp trunk/src/metaserver.h trunk/src/networkProtocol.cpp trunk/src/networkProtocol.h Added Paths: ----------- trunk/data/misc/beacon.material trunk/data/misc/beacon_pad.mesh Added: trunk/data/misc/beacon.material =================================================================== --- trunk/data/misc/beacon.material (rev 0) +++ trunk/data/misc/beacon.material 2008-05-14 21:33:27 UTC (rev 897) @@ -0,0 +1,45 @@ +material beacon/pad_mount_0 +{ + receive_shadows on + technique + { + pass + { + depth_check on + depth_write off + scene_blend add + ambient 1.000000 0.00000 0.00000 1.000000 + diffuse 0.517647 0.018824 0.018824 1.000000 + specular 1.000000 0.000000 0.000000 1.000000 12.500000 + emissive 1.000000 0.000000 0.000000 1.000000 + } + } +} +material beacon/pad_mount_1 +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.517647 0.018824 0.018824 1.000000 + specular 0.500000 0.500000 0.500000 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + } + } +} +material beacon/bg +{ + receive_shadows on + technique + { + pass + { + ambient 0.500000 0.500000 0.500000 1.000000 + diffuse 0.439216 0.621176 0.533333 1.000000 + specular 0.213726 0.382353 0.290196 1.000000 12.500000 + emissive 0.000000 0.000000 0.000000 1.000000 + } + } +} Modified: trunk/data/misc/beacon.mesh =================================================================== (Binary files differ) Added: trunk/data/misc/beacon_pad.mesh =================================================================== (Binary files differ) Property changes on: trunk/data/misc/beacon_pad.mesh ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/data/misc/testsector.xml =================================================================== --- trunk/data/misc/testsector.xml 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/data/misc/testsector.xml 2008-05-14 21:33:27 UTC (rev 897) @@ -26,14 +26,23 @@ <!-- <position>position of this object</position> --> <!-- Optional --> <!-- <direction>desired front direction</direction> --> -<!-- </sectorobject> --> +<!-- </station> --> - <station> +<!-- <beacon> --> +<!-- <position>position of this object</position> --> +<!-- <direction>desired front direction</direction> --> +<!-- </beacon> --> + + <station> <name>Tauseti Wake</name> <position>0, 0, -1480</position> <direction>0.0, 0.0, 1.0 </direction> </station> - <sectorobject> + <beacon> + <position> -650, 0, 800</position> + <direction>0.0, 0.0, 1.0 </direction> + </beacon> + <sectorobject> <name>astro with bump</name> <mesh>asteroid01</mesh> <position> -250, 0, 440</position> @@ -48,13 +57,6 @@ <material>Asteroid</material> </sectorobject> <sectorobject> - <name>beacon</name> - <mesh>beacon</mesh> - <position> -650, 0, 800</position> - <scale>20, 20, 20</scale> - <material>Sta/TS/Background</material> - </sectorobject> - <sectorobject> <name>ring</name> <mesh>ring</mesh> <position> -650, 100, 800</position> Modified: trunk/src/AiCommands.h =================================================================== --- trunk/src/AiCommands.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/AiCommands.h 2008-05-14 21:33:27 UTC (rev 897) @@ -79,7 +79,7 @@ return true; } - bool abort( ) { abort_ = true; } + void abort( ) { abort_ = true; } virtual void start() { std::cout << "AiCommand start (virtual) " << std::endl; } virtual bool update( ) { return false; } Modified: trunk/src/AiManager.cpp =================================================================== --- trunk/src/AiManager.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/AiManager.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -95,7 +95,8 @@ std::copy( argv.begin(), argv.end(), std::ostream_iterator< std::string >( std::cout, " " ) ); std::cout << std::endl; - AiObject * ai = spawnAi( ); + //AiObject * ai = + spawnAi( ); } AiObject * AiManager::spawnAi( ){ Modified: trunk/src/AiObject.cpp =================================================================== --- trunk/src/AiObject.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/AiObject.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -241,7 +241,7 @@ double AiObject::speedAfterTime( double time, double thrustRate ) const { //** v[ t ] := vmax * tanh( th / m / vmax * t ) ** P - double d = vesselObject_->vessel()->dragFactor(); + // double d = vesselObject_->vessel()->dragFactor(); double m = vesselObject_->mass(); double th = vesselObject_->maxThrust() * thrustRate; double vmax = maxSpeed( thrustRate ); @@ -255,7 +255,7 @@ //** v[ t ] := vmax * tanh( th / m / vmax * t ) //** s[t]:=integrate(v[t], t) //** s = vmax^2/a * log( cosh( a / vmax * t ) ) ** P - double d = vesselObject_->vessel()->dragFactor(); + // double d = vesselObject_->vessel()->dragFactor(); double m = vesselObject_->mass(); double th = vesselObject_->maxThrust() * thrustRate; double vmax = maxSpeed( thrustRate ); @@ -269,7 +269,7 @@ double d = vesselObject_->vessel()->dragFactor(); double m = vesselObject_->mass(); double a = vesselObject_->brakingAcc(); - double th = m * a; + // double th = m * a; //std::cout << " th: " << th << "; m: " << m << "; d: " << d << "; v: " << v << "; t: " << time << std::endl; double t = ( m * atan( ( d * v ) / sqrt( a * d * m ) ) ) / sqrt( a * d * m ); //see physics.m return t; @@ -279,7 +279,7 @@ double d = vesselObject_->vessel()->dragFactor(); double m = vesselObject_->mass(); double a = vesselObject_->brakingAcc(); - double th = m * a; + // double th = m * a; double t = brakingTime( v ); double s = ( m * std::log( 1.0 / std::cos( (std::sqrt( a * d * m ) * t ) / m) ) ) / d; //see physics.m Modified: trunk/src/AiObject.h =================================================================== --- trunk/src/AiObject.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/AiObject.h 2008-05-14 21:33:27 UTC (rev 897) @@ -116,6 +116,9 @@ void copy_( const AiObject & ai ); + //! unique id + uint id_; + //! the graphical representation SectorObjectVessel * vesselObject_; @@ -137,10 +140,7 @@ //! objects name std::string name_; - - //! unique id - uint id_; - + //! reference counter for threadholder uint refCounter_; Modified: trunk/src/Entity.cpp =================================================================== --- trunk/src/Entity.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Entity.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -124,7 +124,7 @@ return !fail; } -bool Entity::readPropertiesFromXML( TiXmlHandle & hRoot ){ +void Entity::readPropertiesFromXML( TiXmlHandle & hRoot ){ readXMLNode< std::string >( hRoot, "name_"+ ResourceManager::getSingleton().languageSuffix() + " name_en name", this, &OpenGate::Entity::setName, true ); @@ -166,8 +166,7 @@ if ( pElem ) height = toDouble( pElem->FirstChild()->Value() ); if ( length > 0 && width > 0 && height > 0 ) this->setBaseSize( width, height, length ); - - return true; + } Modified: trunk/src/Entity.h =================================================================== --- trunk/src/Entity.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Entity.h 2008-05-14 21:33:27 UTC (rev 897) @@ -70,7 +70,7 @@ virtual EntityType entityType() const { return rtti_; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ); + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline std::string factionName( ) const { return factionName_; } Modified: trunk/src/EntityManager.cpp =================================================================== --- trunk/src/EntityManager.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/EntityManager.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -79,6 +79,8 @@ std::string EntityManager::categoryName( EntityType type ){ switch( type ){ + case NONE: return "None"; + case ENTITY: return "Entity"; case COMMODITY: return "Commodity"; case POWERPLANT: return "Powerplant"; case CAPACITOR: return "Capacitor"; Modified: trunk/src/Equipment.h =================================================================== --- trunk/src/Equipment.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Equipment.h 2008-05-14 21:33:27 UTC (rev 897) @@ -47,7 +47,7 @@ meltingPoint_ = 0; graviticSig_ = 0.0; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Entity::readPropertiesFromXML( hRoot ); readXMLNode< int >( hRoot, "melting-point", this, &OpenGate::Commodity::setMeltingPoint, false ); readXMLNode< double >( hRoot, "gravitic-sig", this, &OpenGate::Commodity::setGraviticSig, false ); @@ -84,7 +84,7 @@ class Equipment : public Entity{ public: - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Entity::readPropertiesFromXML( hRoot ); readXMLNode< double >( hRoot, "efficency", this, &OpenGate::Equipment::setEfficiency, false ); readXMLNode< std::string >( hRoot, "Manufacturer", this, &OpenGate::Equipment::setManufacturer, false ); @@ -138,7 +138,7 @@ rtti_ = POWERPLANT; powerOutput_ = 0; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint32 >( hRoot, "power_output", this, &OpenGate::PowerPlant::setPowerOutput, false ); } @@ -170,7 +170,7 @@ maxThrust_ = 0; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint32 >( hRoot, "maximum_thrust", this, &OpenGate::Engine::setMaxThrust, false ); } @@ -202,7 +202,7 @@ Radar() : Equipment(){ rtti_ = RADAR; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint32 >( hRoot, "maximum_range", this, &OpenGate::Radar::setMaxRange, false ); } @@ -229,7 +229,7 @@ rtti_ = ECM; sensorLevel_ = 0; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint8 >( hRoot, "sensorlevel", this, &OpenGate::Ecm::setSensorLevel, false ); } @@ -255,7 +255,7 @@ Shield() : Equipment(){ rtti_ = SHIELD; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint32 >( hRoot, "regeneration_rate", this, &OpenGate::Shield::setRegenerationRate, false ); readXMLNode< Uint32 >( hRoot, "maximum_deflection", this, &OpenGate::Shield::setMaxDeflection, false ); @@ -297,7 +297,7 @@ rtti_ = CAPACITOR; capacity_ = 0; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint32 >( hRoot, "capacity", this, &OpenGate::Capacitor::setCapacity, false ); } @@ -320,7 +320,7 @@ rtti_ = GUN; type_ = UNKNOWN; } - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ){ + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ Equipment::readPropertiesFromXML( hRoot ); readXMLNode< Uint32 >( hRoot, "damage", this, &OpenGate::Gun::setDamage, false ); readXMLNode< Uint32 >( hRoot, "velocity", this, &OpenGate::Gun::setSpeed, false ); Modified: trunk/src/Moveable.cpp =================================================================== --- trunk/src/Moveable.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Moveable.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -29,17 +29,17 @@ yaw_ = 1.0; pitch_ = 1.0; roll_ = 1.0; - armor_ = 1.0; + armor_ = 1; dragFactor_ = 1.0; } -bool Moveable::readPropertiesFromXML( TiXmlHandle & hRoot ){ +void Moveable::readPropertiesFromXML( TiXmlHandle & hRoot ){ Entity::readPropertiesFromXML( hRoot ); readXMLNode< float >( hRoot, "yaw", this, &OpenGate::Moveable::setYaw, false ); readXMLNode< float >( hRoot, "pitch", this, &OpenGate::Moveable::setPitch, false ); readXMLNode< float >( hRoot, "roll", this, &OpenGate::Moveable::setRoll, false ); - readXMLNode< float >( hRoot, "armor", this, &OpenGate::Moveable::setArmor, false ); + readXMLNode< Uint32 >( hRoot, "armor", this, &OpenGate::Moveable::setArmor, false ); readXMLNode< float >( hRoot, "dragfactor drag_factor", this, &OpenGate::Moveable::setDragFactor, false ); if ( !readXMLNode< std::string >( hRoot, "mesh", this, &OpenGate::Moveable::setMesh, false ) ){ Modified: trunk/src/Moveable.h =================================================================== --- trunk/src/Moveable.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Moveable.h 2008-05-14 21:33:27 UTC (rev 897) @@ -32,7 +32,7 @@ Moveable(); virtual ~Moveable(){} - virtual bool readPropertiesFromXML( TiXmlHandle & hRoot ); + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline void setArmor( Uint32 armor ){ armor_ = armor * 1000; } inline Uint32 armor( ) const { return armor_; } Modified: trunk/src/OpcodeWrapper.cpp =================================================================== --- trunk/src/OpcodeWrapper.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/OpcodeWrapper.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -147,13 +147,13 @@ } } -void OpcodeCollisionDetection::dettach( SectorObject * obj ){ +void OpcodeCollisionDetection::detach( BaseObject * obj ){ if ( obj && active_ ){ destroyObject( obj ); } } -void OpcodeCollisionDetection::attach( SectorObject * obj ){ +void OpcodeCollisionDetection::attach( BaseObject * obj ){ if ( obj && active_ ){ createObject( obj ); } Modified: trunk/src/OpcodeWrapper.h =================================================================== --- trunk/src/OpcodeWrapper.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/OpcodeWrapper.h 2008-05-14 21:33:27 UTC (rev 897) @@ -54,9 +54,9 @@ void destroyObject( BaseObject * obj ); - void dettach( SectorObject * obj ); + void detach( BaseObject * obj ); - void attach( SectorObject * obj ); + void attach( BaseObject * obj ); bool checkCollideRay( BaseObject * obj, const Ogre::Ray & ray, double rayLength ); Modified: trunk/src/Projectile.h =================================================================== --- trunk/src/Projectile.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Projectile.h 2008-05-14 21:33:27 UTC (rev 897) @@ -60,22 +60,23 @@ protected: - BaseObject * parent_; - Uint16 shotCount_; - Uint32 damage_; - Gun * gun_; - + BaseObject * parent_; + Uint16 shotCount_; + Gun * gun_; + + Uint32 damage_; + Ogre::Real maxLifeTime_; + Ogre::Vector3 vel_; + // Ogre::BillboardChain * chain_; Ogre::BillboardSet * bullet_; Ogre::ManualObject * beam_; Ogre::RibbonTrail * trail_; Ogre::SceneNode * trailNode_; - Ogre::Vector3 vel_; Ogre::SceneNode * shape_; - Ogre::Real maxLifeTime_; Ogre::Real oldTime_; Ogre::Real maxRange_; bool ammoHit_; Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Sector.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -77,16 +77,17 @@ Sector::Sector( Ogre::SceneManager * sceneMgr, NetworkClient * network ) : sceneMgr_( sceneMgr ), network_( network ) { - radar_ = true; - planet_ = NULL; - koordAxisNode_ = NULL; - starsNode_ = NULL; - avatar_ = NULL; - station_ = NULL; - childIDCounter_= 0; - log_ = LogManager::getSingletonPtr(); + radar_ = true; + planet_ = NULL; + koordAxisNode_ = NULL; + starsNode_ = NULL; + avatar_ = NULL; + station_ = NULL; + name_ = "unknown"; + childIDCounter_ = 0; + log_ = LogManager::getSingletonPtr(); - avatarDeathSequenceTime_ = 0.0; + avatarDeathSequenceTime_ = 0.0; //*** starfield test 1 // Ogre::ManualObject* myManualObject = sceneMgr_->createManualObject("manual1"); @@ -175,7 +176,6 @@ // delete (*it).second[ i ]; // } } - } void Sector::populate( const std::string & fileName ){ @@ -203,14 +203,9 @@ log_->fatal( fileName + " is no sector description" ); return; } + + readXMLNode< std::string >( hRoot, "name_en name", this, &OpenGate::Sector::setName, false ); - pElem = hRoot.ChildElement( "name_en", 0 ).Element(); - if ( pElem ){ - sectorname_ = pElem->FirstChild()->Value(); - } else { - sectorname_ = "Testsector"; - } - pElem = hRoot.ChildElement( "skybox", 0 ).Element(); if ( pElem ){ sceneMgr_->setSkyBox( true, pElem->FirstChild()->Value(), 10000 ); @@ -272,12 +267,31 @@ } } - //** Load passive sector objects - for ( pElem = hRoot.FirstChild( "sectorobject" ).Element(); pElem != 0; - pElem = pElem->NextSiblingElement("sectorobject") ) { - std::string name; - pSubElem = pElem->FirstChildElement( "name" ); - if ( pSubElem ){ + //** load beacon + pElem = hRoot.FirstChild( "beacon" ).Element(); + if ( pElem ){ + Ogre::Vector3 beaconPos( 0.0, 0.0, 0.0); + pSubElem = pElem->FirstChildElement( "position" ); + if ( pSubElem ){ + beaconPos = Ogre::Vector3( &toVector3( pSubElem->FirstChild()->Value(), ',' )[ 0 ] ); + } else { + log_->warn( "missing pos for beacon" ); + } + SectorObject * obj = createBeacon( beaconPos ); + Ogre::Vector3 beaconDir( 0.0, 0.0, 0.0); + pSubElem = pElem->FirstChildElement( "direction" ); + if ( pSubElem ){ + beaconDir = Ogre::Vector3( &toVector3( pSubElem->FirstChild()->Value(), ',' )[ 0 ] ); + obj->mainNode()->setDirection( beaconDir ); + } + } + + //** Load passive sector objects + for ( pElem = hRoot.FirstChild( "sectorobject" ).Element(); pElem != 0; + pElem = pElem->NextSiblingElement("sectorobject") ) { + std::string name; + pSubElem = pElem->FirstChildElement( "name" ); + if ( pSubElem ){ name = pSubElem->FirstChild()->Value(); } else { log_->warn( "missing name for sectorobject " ); @@ -291,9 +305,9 @@ Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load( mesh, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, - Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, - true, true); + Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, + Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, + true, true); unsigned short src, dest; if ( !pMesh->suggestTangentVectorBuildParams( Ogre::VES_TANGENT, src, dest) ) { pMesh->buildTangentVectors( Ogre::VES_TANGENT, src, dest); @@ -498,6 +512,14 @@ return obj; } +SectorObject * Sector::createBeacon( const Ogre::Vector3 & pos ){ + SectorObject * obj = new BeaconObject( this ); + obj->mainNode()->setPosition( pos ); + obj->scale( Ogre::Vector3( 20.0, 20.0, 20.0 ) ); + sectorObjects_.insert( obj ); + return obj; +} + SectorObjectMoveable * Sector::createMoveable( const Ogre::String & name, Uint32 userID, Uint8 childID, Moveable & moveable ){ SectorObjectMoveable * obj = new SectorObjectMoveable( name, this, userID, childID, @@ -705,15 +727,27 @@ koordAxisNode_ = sceneMgr_->getRootSceneNode()->createChildSceneNode( "axisnode" ); koordAxisMO_ = sceneMgr_->createManualObject( koordAxisNode_->getName()+ "/manualObject" ); Ogre::Real length = 20; - koordAxisMO_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); - unsigned point_index = 0; + + koordAxisMO_->begin( "singleColor", Ogre::RenderOperation::OT_LINE_LIST); + koordAxisMO_->getSection( 0 )->setCustomParameter( 0, Ogre::Vector4( 1.0, 0.0, 0.0, 1.0 ) ); koordAxisMO_->position( 0.0, 0.0, 0.0 ); koordAxisMO_->position( 1.0, 0.0, 0.0 ); koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->end(); + + koordAxisMO_->begin( "singleColor", Ogre::RenderOperation::OT_LINE_LIST); + koordAxisMO_->getSection( 1 )->setCustomParameter( 0, Ogre::Vector4( 0.0, 1.0, 0.0, 1.0 ) ); koordAxisMO_->position( 0.0, 1.0, 0.0 ); koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->end(); + + koordAxisMO_->begin( "singleColor", Ogre::RenderOperation::OT_LINE_LIST); + koordAxisMO_->getSection( 2 )->setCustomParameter( 0, Ogre::Vector4( 0.0, 0.0, 1.0, 1.0 ) ); koordAxisMO_->position( 0.0, 0.0, 1.0 ); koordAxisMO_->position( 0.0, 0.0, 0.0 ); + koordAxisMO_->end(); + + koordAxisMO_->begin( "BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST); koordAxisMO_->position( -1.0, 0.0, 0.0 ); koordAxisMO_->position( 0.0, 0.0, 0.0 ); koordAxisMO_->position( 0.0, -1.0, 0.0 ); @@ -771,11 +805,6 @@ void Sector::sendAllVesselMovements( ){ if ( avatar_ ) sendVesselMovement( avatar_ ); - -// for ( std::map< int, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); it != localAiObjects_.end(); it ++ ){ -// sendVesselMovement( it->second ); -// } - } void Sector::sendAllVesselInfos( ){ @@ -798,6 +827,7 @@ obj->velocity().ptr(), obj->mainNode()->getOrientation().ptr(), obj->thrustRate(), + obj->thrust(), obj->scaledYaw(), obj->scaledPitch(), obj->scaledRoll(), @@ -807,6 +837,62 @@ } } +void Sector::receiveVesselMovement( const std::vector < MessageBodyShipMovement * > & movements ){ + + std::map < long, const MessageBodyShipMovement * > singleMsg; + + //** we sort the movement messaged + for ( size_t i = 0; i < movements.size(); i ++ ){ +// LogManager::getSingleton().debug( std::string( "Movement: " ) + +// movableObjects_[ createGlobalID( movements[ i ]->senderID(), movements[ i ]->childID() )]->name() + " " + toStr( movements[ i ]->senderID() ) + " " + toStr( (int)movements[ i ]->childID() ) + +// " " + toStr( movements[ i ]->position() ) ); + + if ( movements[ i ]->senderID() != network_->userID() ){ + //** apply only foreign movements, and take just the actual movement + singleMsg[ createGlobalID( movements[ i ]->senderID(), movements[ i ]->childID() ) ] = movements[ i ]; + } + } + + std::map< long, SectorObjectMoveable * >::iterator it; + + for ( std::map < long, const MessageBodyShipMovement * >::iterator i = singleMsg.begin(); i != singleMsg.end(); i++ ){ + if ( ( it = movableObjects_.find( i->first ) ) != movableObjects_.end() ){ + it->second->setFlightProperties( (*i->second) ); + } else { + log_->fatal( "Requested non existant object for shipmovement: " + + toStr( network_->userName( i->second->senderID() ) ) + + " child: " + toStr( (int)i->second->childID() ) + + " this should not happen." ); + } + } + for ( size_t i = 0; i < movements.size(); i ++ ){ + delete movements[ i ]; + } + +} + +void Sector::sendVesselStatus( SectorObjectVessel * obj ){ + if ( obj ){ + MessageBodyShipStatus msg( obj->childID(), obj->shield(), obj->armor(), 0, 0, 0 ); + network_->send( msg ); + } +} + +void Sector::receiveVesselStatus( const MessageBodyShipStatus & msg ){ + if ( msg.senderID() != network_->userID() ){ + + std::map< long, SectorObjectMoveable * >::iterator it; + + if ( ( it = movableObjects_.find( createGlobalID( msg.senderID(), msg.childID() ) ) ) != movableObjects_.end() ){ + // log_->debug( "ReceiveVesselStatus for " + it->second->name( ) ); + it->second->setStatus( msg ); + } else { + log_->fatal( "Requested non existant object for shipstatus: " + + network_->userName( msg.senderID() ) + " this should not happen." ); + } + } +} + void Sector::sendVesselRegister( SectorObjectVessel * obj ){ if ( obj ) { log_->info( std::string( "Send register " ) + obj->name() + " id:" + toStr( obj->vessel()->id() ) ); @@ -826,12 +912,11 @@ *ResourceManager::getSingleton().entityManager->vessel( msg.vesselID() ) ); obj->mainNode()->setPosition( toOgreVec( msg.position() ) ); obj->setMass( msg.mass() ); - - log_->info( "FIXTHIS: void Sector::receiveVesselRegister( " ); -// obj->setMaxShield( msg.maxShield() ); -// obj->setMaxThrust( msg.maxThrust() ); + obj->setMaxShield( msg.maxShield() ); + obj->setMaxThrust( msg.maxThrust() ); + obj->setMaxSpeed( std::sqrt( msg.maxThrust() / obj->moveable()->dragFactor() ) ); + std::cout << msg << std::endl; - } else { log_->info( "Create ai object " + msg.name()+ " " + toStr( msg.senderID() ) + " " + toStr( (int)msg.childID() ) + " " + toStr( msg.vesselID() ) ); @@ -895,62 +980,6 @@ } } -void Sector::receiveVesselMovement( const std::vector < MessageBodyShipMovement * > & movements ){ - - std::map < long, const MessageBodyShipMovement * > singleMsg; - - //** we sort the movement messaged - for ( size_t i = 0; i < movements.size(); i ++ ){ -// LogManager::getSingleton().debug( std::string( "Movement: " ) + -// movableObjects_[ createGlobalID( movements[ i ]->senderID(), movements[ i ]->childID() )]->name() + " " + toStr( movements[ i ]->senderID() ) + " " + toStr( (int)movements[ i ]->childID() ) + -// " " + toStr( movements[ i ]->position() ) ); - - if ( movements[ i ]->senderID() != network_->userID() ){ - //** apply only foreign movements, and take just the actual movement - singleMsg[ createGlobalID( movements[ i ]->senderID(), movements[ i ]->childID() ) ] = movements[ i ]; - } - } - - std::map< long, SectorObjectMoveable * >::iterator it; - - for ( std::map < long, const MessageBodyShipMovement * >::iterator i = singleMsg.begin(); i != singleMsg.end(); i++ ){ - if ( ( it = movableObjects_.find( i->first ) ) != movableObjects_.end() ){ - it->second->setFlightProperties( (*i->second) ); - } else { - log_->fatal( "Requested non existant object for shipmovement: " + - toStr( network_->userName( i->second->senderID() ) ) + - " child: " + toStr( (int)i->second->childID() ) + - " this should not happen." ); - } - } - for ( size_t i = 0; i < movements.size(); i ++ ){ - delete movements[ i ]; - } - -} - -void Sector::sendVesselStatus( SectorObjectVessel * obj ){ - if ( obj ){ - MessageBodyShipStatus msg( obj->childID(), obj->shield(), obj->armor(), 0, 0, 0 ); - network_->send( msg ); - } -} - -void Sector::receiveVesselStatus( const MessageBodyShipStatus & msg ){ - if ( msg.senderID() != network_->userID() ){ - - std::map< long, SectorObjectMoveable * >::iterator it; - - if ( ( it = movableObjects_.find( createGlobalID( msg.senderID(), msg.childID() ) ) ) != movableObjects_.end() ){ - // log_->debug( "ReceiveVesselStatus for " + it->second->name( ) ); - it->second->setStatus( msg ); - } else { - log_->fatal( "Requested non existant object for shipstatus: " + - network_->userName( msg.senderID() ) + " this should not happen." ); - } - } -} - void Sector::sendVesselAmmoHit( const Projectile & projectile, BaseObject * victim ){ if ( projectile.parent().userID() == network_->userID() ){ Modified: trunk/src/Sector.h =================================================================== --- trunk/src/Sector.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Sector.h 2008-05-14 21:33:27 UTC (rev 897) @@ -56,6 +56,12 @@ void setListener( UnDockedState * listener ){ listener_ = listener; } UnDockedState * listener( ){ return listener_; } + + /*! Set the name of this sector */ + void setName( const std::string & name ) { name_ = name; } + + /*! Return the name of this sector. Set during population from xml-file */ + std::string name() const { return name_; } void update( Ogre::Real elapsedTime ); @@ -65,6 +71,8 @@ const Ogre::Vector3 & pos, const Ogre::Vector3 & targetSize, Ogre::Degree yaw ); SectorObject * createStation( const Ogre::String & stationName, Ogre::Vector3 & pos ); + + SectorObject * createBeacon( const Ogre::Vector3 & pos ); SectorObjectMoveable * createMoveable( const Ogre::String & name, Uint32 userId, Uint8 childId, Moveable & moveable ); @@ -119,38 +127,38 @@ StationObject * station() { return station_; } protected: - + //** do not destruct objects manualy, let them send false during update loop void destruct_( SectorObject * obj ); - Ogre::SceneManager * sceneMgr_; - NetworkClient * network_; - LogManager * log_; + Ogre::SceneManager * sceneMgr_; + NetworkClient * network_; + LogManager * log_; - UnDockedState * listener_; + UnDockedState * listener_; - std::string sectorname_; + std::string name_; - SectorObjectAvatar * avatar_; - Planet * planet_; + SectorObjectAvatar * avatar_; + Planet * planet_; - Ogre::SceneNode * starsNode_; - Ogre::SceneNode * koordAxisNode_; - Ogre::ManualObject * koordAxisMO_; - - std::set< SectorObject * > sectorObjects_; + Ogre::SceneNode * starsNode_; + Ogre::SceneNode * koordAxisNode_; + Ogre::ManualObject * koordAxisMO_; - std::map< long, SectorObjectMoveable * > movableObjects_; - std::map< long, SectorObjectMissile * > localAiObjects_; + std::set< SectorObject * > sectorObjects_; - float avatarDeathSequenceTime_; + std::map< long, SectorObjectMoveable * > movableObjects_; + std::map< long, SectorObjectMissile * > localAiObjects_; - bool radar_ ; + float avatarDeathSequenceTime_; - StationObject * station_; - - std::map< std::string, std::deque< SectorObject * > > objectHeap_; - uint childIDCounter_; + bool radar_ ; + + StationObject * station_; + + std::map< std::string, std::deque< SectorObject * > > objectHeap_; + uint childIDCounter_; }; } // namespace OpenGate Modified: trunk/src/SectorObject.cpp =================================================================== --- trunk/src/SectorObject.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/SectorObject.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -31,7 +31,7 @@ namespace OpenGate{ SectorObject::SectorObject( const Ogre::String & name, Sector * sector, Uint32 userID, Uint8 childID ) - : BaseObject( name, sector, userID, childID ), target_( NULL ) { __D( name ) + : BaseObject( name, sector, userID, childID ), target_( NULL ), entity_( NULL ) { __D( name ) isOnRadar_ = false; mainNodeEntityScale_ = mainNode_->createChildSceneNode( name_ + "_baseScale" ); @@ -65,8 +65,10 @@ ResourceManager::getSingleton().collisionManager->destroyObject( this ); - mainNodeEntityRot_->detachObject( entity_ ); - sceneMgr_->destroyEntity( entity_ ); + if ( entity_ ){ + mainNodeEntityRot_->detachObject( entity_ ); + sceneMgr_->destroyEntity( entity_ ); + } mainNodeEntityScale_->removeAndDestroyChild( mainNodeEntityRot_->getName() ); mainNode_->removeAndDestroyChild( mainNodeEntityScale_->getName() ); @@ -78,12 +80,23 @@ if ( target_ ){ std::cerr << WHERE_AM_I << "*************** this should not happen" << " " << target_->name() << std::endl; } else { - target_ == NULL; + target_ = NULL; } } void SectorObject::setShape( const Ogre::String & meshname ){ - entity_ = sceneMgr_->createEntity( name_ + "_shape", meshname ); + try { + entity_ = sceneMgr_->createEntity( name_ + "_shape", meshname ); + } catch( Ogre::Exception & e ){ + LogManager::getSingleton().warn( e.what() ); + entity_ = NULL; + return ; + } catch( ... ){ + LogManager::getSingleton().warn( "Unknown exception" ); + entity_ = NULL; + return ; + } + mainNodeEntityRot_->attachObject( entity_ ); ResourceManager::getSingleton().collisionManager->createObject( this ); } Modified: trunk/src/SectorObject.h =================================================================== --- trunk/src/SectorObject.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/SectorObject.h 2008-05-14 21:33:27 UTC (rev 897) @@ -51,7 +51,12 @@ virtual void collide( BaseObject * object ){ // std::cout << "SectorObject " << name_ << " collide with " << object->rtti() << " " << object->name()<< std::endl; } - + + /*! Return pointer to the active sector.*/ + Sector * sector() { return sector_; } + + Ogre::SceneNode * rotnode() { return mainNodeEntityRot_;} + virtual bool update( Ogre::Real elapsedTime ){ return true; } void setShape( const Ogre::String & meshname ); @@ -97,19 +102,21 @@ virtual void inititialize_(); - Ogre::SceneNode * mainNodeEntityScale_; // Main character node for base size - Ogre::SceneNode * mainNodeEntityRot_; // Main character node for base rotation - Ogre::Entity * entity_; + SectorObject * target_; + Ogre::Entity * entity_; + + Ogre::SceneNode * mainNodeEntityScale_; // Main character node for base size + Ogre::SceneNode * mainNodeEntityRot_; // Main character node for base rotation + + Ogre::OverlayElement * dotA_; + Ogre::OverlayElement * dotB_; - Ogre::OverlayElement * dotA_; - Ogre::OverlayElement * dotB_; - bool isOnRadar_; Ogre::Vector3 baseSize_; Ogre::Vector3 baseScale_; std::set < SectorObject * > observers_; // better listener / e.g. radar - SectorObject * target_; + }; Modified: trunk/src/SectorObjectMissile.cpp =================================================================== --- trunk/src/SectorObjectMissile.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/SectorObjectMissile.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -110,7 +110,7 @@ Ogre::Real scaledYaw = yawTo.valueDegrees() / ( elapsedTime * rotFric * moveable_->yaw() ); Ogre::Real scaledPitch = pitchTo.valueDegrees() / ( elapsedTime * rotFric * moveable_->pitch() ); - Ogre::Real scaledRoll = rollTo.valueDegrees() / ( elapsedTime * rotFric * moveable_->yaw() ); + // Ogre::Real scaledRoll = rollTo.valueDegrees() / ( elapsedTime * rotFric * moveable_->yaw() ); yaw_ = max( -1.0f, scaledYaw ); yaw_ = min( yaw_, 1.0f ); pitch_ = max( -1.0f, scaledPitch ); pitch_ = min( pitch_, 1.0f ); @@ -149,7 +149,7 @@ thrustTrail_->setMaterialName( "BeamGreen" ); thrustTrail_->setTrailLength( 1000 ); thrustTrail_->setColourChange( 0, Ogre::ColourValue( 0.0, 0.0, 0.0, 0.3 ) ); - thrustTrail_->setWidthChange( 0, 0.5 ); + thrustTrail_->setWidthChange( 0, 0.3 ); thrustTrail_->setMaxChainElements( 100 ); thrustTrail_->setInitialWidth( 0, 1.0 ); thrustTrail_->addNode( mainNode_ ); Modified: trunk/src/SectorObjectMoveable.cpp =================================================================== --- trunk/src/SectorObjectMoveable.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/SectorObjectMoveable.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -97,7 +97,7 @@ void SectorObjectMoveable::inititialize_(){ - if ( moveable_ ) maxArmor_ = moveable_->armor(); else maxArmor_ = 1.0; + if ( moveable_ ) maxArmor_ = moveable_->armor(); else maxArmor_ = 1; if ( moveable_ ) maxSpeed_ = moveable_->maxSpeed(); else maxSpeed_ = 0.0; mass_ = 1; @@ -130,7 +130,7 @@ netSequence_ = 0; lifeTime_ = 0.0; lastLifeTime_ = 0.0; - forceMovement_ = false; + forceMovement_ = true; statusChanged_ = false; selectable_ = true; @@ -150,7 +150,7 @@ } if ( destroyRequest_ || destroyWithExplosion_ ){ - ResourceManager::getSingleton().collisionManager->dettach( this ); + ResourceManager::getSingleton().collisionManager->detach( this ); this->unsubscribeToObservers(); @@ -220,7 +220,7 @@ if ( speed > maxSpeed() ){ vel_ *= maxSpeed() / speed; - } else if ( speed < 0.1 ){ + } else if ( speed < 0.01 ){ vel_ *= 0.0; } @@ -231,9 +231,6 @@ Ogre::Ray rayNoNextPos( mainNode_->getWorldPosition(), vel_.normalisedCopy() ); ResourceManager::getSingleton().collisionManager->checkCollideRay( this, rayNoNextPos, (vel_ * elapsedTime).length() ); } - - - // //** snap quaternion // Ogre::Quaternion rnd( mainNode_->getOrientation() ); @@ -246,15 +243,20 @@ void SectorObjectMoveable::setFlightProperties( const MessageBodyShipMovement & msg ){ setThrustRate( msg.thrustRate() ); + thrust_ = msg.thrust(); + + updateThruster(); + + std::cout << name_ << " " << msg << std::endl; if ( forceMovement_ ){ - mainNode_->setPosition( toOgreVec( msg.position() ) ); - mainNode_->setOrientation( toOgreQuat( msg.orientation() ) ); - vel_ = toOgreVec( msg.velocity() ); - setScaledYaw( msg.yaw() ); - setScaledPitch( msg.pitch() ); - setScaledRoll( msg.roll() ); - forceMovement_ = false; - } else { + mainNode_->setPosition( toOgreVec( msg.position() ) ); + mainNode_->setOrientation( toOgreQuat( msg.orientation() ) ); + vel_ = toOgreVec( msg.velocity() ); + setScaledYaw( msg.yaw() ); + setScaledPitch( msg.pitch() ); + setScaledRoll( msg.roll() ); + forceMovement_ = false; + } else { // if ( ( fabs( msg.yaw() ) -1.0f ) < 1e-4 ) { // setScaledYaw( msg.yaw() ); @@ -272,36 +274,36 @@ // setScaledRoll( 0.0 ); // } - setScaledYaw( msg.yaw() ); - setScaledRoll( msg.roll() ); - setScaledPitch( msg.pitch() ); + setScaledYaw( msg.yaw() ); + setScaledRoll( msg.roll() ); + setScaledPitch( msg.pitch() ); - vel_ = toOgreVec( msg.velocity() ); + vel_ = toOgreVec( msg.velocity() ); - Ogre::Vector3 srcP( mainNode_->getPosition( ) ); - Ogre::Quaternion srcQ( mainNode_->getOrientation( ) ); - Ogre::Vector3 destP( toOgreVec( msg.position( ) ) ); + Ogre::Vector3 srcP( mainNode_->getPosition( ) ); + Ogre::Quaternion srcQ( mainNode_->getOrientation( ) ); + Ogre::Vector3 destP( toOgreVec( msg.position( ) ) ); - //** try Slerp - Ogre::Quaternion diff = Ogre::Quaternion::nlerp( 1, srcQ, toOgreQuat( msg.orientation() ) ); - interpolateRot_ = diff * srcQ.Inverse(); + //** try Slerp + Ogre::Quaternion diff = Ogre::Quaternion::nlerp( 1, srcQ, toOgreQuat( msg.orientation() ) ); + interpolateRot_ = diff * srcQ.Inverse(); // if ( msg.childID() > 0 ){ - if ( !1 ){ + if ( !1 ){ - std::cout << std::endl; - std::cout << msg.sequenceNr() << "LastFrameCount: " << lastFrameCount_ - << " life: " << lifeTime_ << " last: " << lastLifeTime_ - << " diff: "<< lifeTime_ - lastLifeTime_ << std::endl; + std::cout << std::endl; + std::cout << msg.sequenceNr() << "LastFrameCount: " << lastFrameCount_ + << " life: " << lifeTime_ << " last: " << lastLifeTime_ + << " diff: "<< lifeTime_ - lastLifeTime_ << std::endl; // std::cout << "Ist: " << mainNode_->getOrientation( ) // << " " << mainNode_->getOrientation( ).getYaw().valueDegrees() << std::endl; // std::cout << "Soll: " << msg.orientation() << " " << msg.orientation().getYaw().valueDegrees() << std::endl; - std::cout << "Diff: send: " << msg.yaw() << " " << msg.pitch() << " " << msg.roll() << std::endl; + std::cout << "Diff: send: " << msg.yaw() << " " << msg.pitch() << " " << msg.roll() << std::endl; - std::cout << "Diff: Pos: " << (srcP-destP).length() + std::cout << "Diff: Pos: " << (srcP-destP).length() << " Y:" << interpolateRot_.getYaw().valueDegrees() << " P:" << interpolateRot_.getPitch().valueDegrees() << " R:" << interpolateRot_.getRoll().valueDegrees() << std::endl; Modified: trunk/src/SectorObjectMoveable.h =================================================================== --- trunk/src/SectorObjectMoveable.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/SectorObjectMoveable.h 2008-05-14 21:33:27 UTC (rev 897) @@ -100,6 +100,8 @@ /*! Return the maximum thrust */ inline Uint32 maxThrust() const { return maxThrust_; } + inline Uint32 thrust() const { return thrust_; } + /*! Update visual feedback for thrusters */ void updateThruster(); @@ -113,6 +115,9 @@ inline Ogre::Real speed() const { return vel_.length(); } /*! Returns the maximum speed depend on vessel and mounted engine */ + inline void setMaxSpeed( Ogre::Real speed ) { maxSpeed_ = speed; } + + /*! Returns the maximum speed depend on vessel and mounted engine */ inline Ogre::Real maxSpeed() const { return maxSpeed_; } /*! Returns the relative speed */ Modified: trunk/src/SectorObjectVessel.cpp =================================================================== --- trunk/src/SectorObjectVessel.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/SectorObjectVessel.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -101,12 +101,12 @@ if ( this->vessel()->engine() ){ maxThrust_ = this->vessel()->engine()->maxThrust(); } else { - maxThrust_ = 0.0; + maxThrust_ = 0; } if ( this->vessel()->shield() ) { maxShield_ = this->vessel()->shield()->maxDeflection(); } else { - maxShield_ = 0.0; + maxShield_ = 0; } controler_ = NULL; Modified: trunk/src/Station.cpp =================================================================== --- trunk/src/Station.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Station.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -76,12 +76,12 @@ ibuf->unlock(); } -StationPad::StationPad( const std::string & name, StationObject * station, Ogre::SubEntity * padSubEntity, bool docking ) - : BaseObject( name, station->sector() ), station_( station ), docking_( docking ){ +Pad::Pad( const std::string & name, SectorObject * parent, Ogre::SubEntity * padSubEntity ) + : BaseObject( name, parent->sector() ), parent_( parent ){ //** hier gibt es eine mainNode die nicht genutzt wird. C. //** mach das sauber!! ersetzt getPosition, getDirection, padNode - padNode_ = station_->rotnode()->createChildSceneNode( station_->name() + "/" + name_ ); + padNode_ = parent_->rotnode()->createChildSceneNode( parent_->name() + "/" + name_ ); padManualObject_ = sceneMgr_->createManualObject( padNode_->getName() + "/ManualObject" ); std::vector < Ogre::Vector3 > verts; @@ -122,24 +122,33 @@ padEntity_ = sceneMgr_->createEntity( padMesh_->getName() + "/Entity", padMesh_->getName() ); padNode_->attachObject( padEntity_ ); padNode_->translate( direction_.normalisedCopy() * 0.1 ); - if ( docking_ ){ - ResourceManager::getSingleton().collisionManager->createObject( this ); - } } - -StationPad::~StationPad( ){ - ResourceManager::getSingleton().collisionManager->destroyObject( this ); + +Pad::~Pad( ){ padNode_->detachObject( padEntity_ ); sceneMgr_->destroyEntity( padEntity_ ); Ogre::MeshManager::getSingleton().remove( padMesh_->getName() ); sceneMgr_->destroyManualObject( padManualObject_ ); - station_->rotnode()->removeAndDestroyChild( padNode_->getName() ); + parent_->rotnode()->removeAndDestroyChild( padNode_->getName() ); } +StationPad::StationPad( const std::string & name, StationObject * station, Ogre::SubEntity * padSubEntity, + bool docking ) + : Pad( name, station, padSubEntity), docking_( docking ){ + + if ( docking_ ){ + ResourceManager::getSingleton().collisionManager->createObject( this ); + } +} + +StationPad::~StationPad( ){ + ResourceManager::getSingleton().collisionManager->destroyObject( this ); +} + void StationPad::collide( BaseObject * object ){ - if ( docking_ ) { if ( object->rtti() == AVATAR_RTTI ){ + std::cout << "StationPad::collide() docking request for " << object->name() << std::endl; sector_->listener()->changeToDockedState(); } else if ( object->rtti() == SECTOROBJECTVESSEL_RTTI ){ std::cout << "StationPad::collide() docking request for " << object->name() << std::endl; @@ -190,7 +199,7 @@ dockPad_ = new StationPad( name_ + "DockPad", this, entity()->getSubEntity( i ), true ); } if ( entity()->getSubEntity( i )->getMaterialName() == "Station/LaunchPad.001" ){ - launchPad_ = new StationPad( name_ + "LaunchPad", this, entity()->getSubEntity( i ) ); + launchPad_ = new StationPad( name_ + "LaunchPad", this, entity()->getSubEntity( i ), false ); } } @@ -346,4 +355,98 @@ ringNode_->attachObject( ringEntity_ ); } +BeaconPad::BeaconPad( const std::string & name, BeaconObject * beacon, Ogre::SubEntity * padSubEntity ) + : Pad( name, beacon, padSubEntity){ + + ResourceManager::getSingleton().collisionManager->createObject( this ); +} + +BeaconPad::~BeaconPad( ){ + ResourceManager::getSingleton().collisionManager->destroyObject( this ); +} + +void BeaconPad::collide( BaseObject * object ){ + if ( object->rtti() == AVATAR_RTTI ){ + std::cout << "BeaconPad::collide() bcu for " << object->name() << std::endl; + } else if ( object->rtti() == SECTOROBJECTVESSEL_RTTI ){ + std::cout << "BeaconPad::collide() bcu for " << object->name() << std::endl; + } +} + +void BeaconPad::changeEntity( const std::string & meshname ){ + ResourceManager::getSingleton().collisionManager->detach( this ); + padNode_->detachObject( padEntity_ ); + sceneMgr_->destroyEntity( padEntity_ ); + padEntity_ = sceneMgr_->createEntity( name_ + "/Entity", meshname ); + padNode_->attachObject( padEntity_ ); + padNode_->translate( position_ ); + ResourceManager::getSingleton().collisionManager->attach( this ); +} + + +BeaconObject::BeaconObject( Sector * sector ) + : SectorObject ( sector->name() + "/Beacon ", sector ), entryPad_( NULL ), exitPad_( NULL ) { + + Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load( "beacon.mesh", + Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, + Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, + true, true); + + unsigned short src = 0, dest = 0; + if ( !pMesh->suggestTangentVectorBuildParams( Ogre::VES_TANGENT, src, dest) ) { + pMesh->buildTangentVectors( Ogre::VES_TANGENT, src, dest); + } + setShape( "beacon.mesh" ); + //entity_->setMaterialName( "Sta/TS/Background" ); + + for ( uint i = 0; i < entity()->getNumSubEntities(); i ++ ){ + std::cout << entity()->getSubEntity( i )->getMaterialName() << " Techniques: " + << entity()->getSubEntity( i )->getMaterial()->getNumTechniques() << " used: " + << entity()->getSubEntity( i )->getTechnique()->getName() << std::endl; + + if ( entity()->getSubEntity( i )->getMaterialName() == "beacon/bg" ){ + entity()->getSubEntity( i )->setMaterialName( "Sta/TS/Background" ); + } + + if ( entity()->getSubEntity( i )->getMaterialName() == "beacon/pad_mount_0" ){ + entity()->getSubEntity( i )->setMaterialName( "singleColor" ); + entity()->getSubEntity( i )->setCustomParameter( 0, Ogre::Vector4( 0.5, 0.5, 0.5, 1.0 ) ); + entryPad_ = new BeaconPad( "EntryPad", this, entity()->getSubEntity( i ) ); + entryPad_->changeEntity( "beacon_pad.mesh" ); + entryPad_->entity()->setMaterialName( "singleColor" ); + entryPad_->entity()->getSubEntity( 0 )->setCustomParameter( 0, Ogre::Vector4( 0.8, 0.0, 0.0, 0.2 ) ); + } + if ( entity()->getSubEntity( i )->getMaterialName() == "beacon/pad_mount_1" ){ + entity()->getSubEntity( i )->setMaterialName( "singleColor" ); + entity()->getSubEntity( i )->setCustomParameter( 0, Ogre::Vector4( 0.5, 0.5, 0.5, 1.0 ) ); + exitPad_ = new BeaconPad( "ExitPad", this, entity()->getSubEntity( i ) ); + exitPad_->changeEntity( "beacon_pad.mesh" ); + exitPad_->entity()->setMaterialName( "singleColor" ); + exitPad_->entity()->getSubEntity( 0 )->setCustomParameter( 0, Ogre::Vector4( 0.8, 0.0, 0.0, 0.2 ) ); + } + } + + +// std::vector < Ogre::Vector3 > verts; +// std::vector < Triangle > tris; +// readSubEntity( entity_, verts, tris ); + + + +} + +BeaconObject::~BeaconObject( ){ + if ( entryPad_ ) delete entryPad_; + if ( exitPad_ ) delete exitPad_; +} + +Ogre::Vector3 BeaconObject::entrancePosition() const { + return Ogre::Vector3::ZERO; +} + +Ogre::Vector3 BeaconObject::exitPosition() const { + return Ogre::Vector3::ZERO; +} + } // namespace OpenGate Modified: trunk/src/Station.h =================================================================== --- trunk/src/Station.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Station.h 2008-05-14 21:33:27 UTC (rev 897) @@ -31,8 +31,11 @@ namespace OpenGate{ class Station; +class Pad; class StationPad; +class BeaconPad; class StationObject; +class BeaconObject; struct Triangle{ int a, b, c; @@ -52,14 +55,12 @@ protected: }; -/*! A station pad is a plain area where vessel dock or launch */ -class StationPad : public BaseObject{ +class Pad : public BaseObject { public: /*! Constructor, with a name, */ - StationPad( const std::string & name, StationObject * station, Ogre::SubEntity * padSubEntity, - bool docking = false ); + Pad( const std::string & name, SectorObject * parent, Ogre::SubEntity * padSubEntity ); /*! Destructor */ - virtual ~StationPad( ); + virtual ~Pad( ); /*! Return runtime type information */ virtual long rtti() const { return STATIONPAD_RTTI; } @@ -67,7 +68,7 @@ virtual std::string collisionClass() const { return "DockPad"; } /*! What happen on collision */ - void collide( BaseObject * object ); + virtual void collide( BaseObject * object ){} /*! Update the pad in each frame */ virtual bool update( Ogre::Real elapsedTime ){ return true; } @@ -80,16 +81,13 @@ /*! Radius of the pad */ Ogre::Real radius() const { return radius_; } - - bool isDocking( ) const { return docking_; } Ogre::SceneNode * padNode(){ return padNode_; } virtual Ogre::Entity * entity( ) { return padEntity_; } protected: - StationObject * station_; - bool docking_; + SectorObject * parent_; Ogre::SceneNode * padNode_; Ogre::ManualObject * padManualObject_; Ogre::MeshPtr padMesh_; @@ -99,6 +97,22 @@ Ogre::Vector3 direction_; Ogre::Real radius_; }; + +/*! A station pad is a plain area where vessel dock or launch */ +class StationPad : public Pad { +public: + /*! Constructor, with a name, */ + StationPad( const std::string & name, StationObject * station, Ogre::SubEntity * padSubEntity, + bool docking = false ); + /*! Destructor */ + virtual ~StationPad( ); + + /*! What to do on collision */ + void collide( BaseObject * object ); + +protected: + bool docking_; +}; //** derive from dockable so sector can handle set of dockables class StationObject : public SectorObject{ @@ -142,11 +156,6 @@ /*! Docking rings end position respectively outer position of the dockingtube*/ Ogre::Vector3 dockingRingEnd( ) const ; - /*! Return pointer to the active sector.*/ - Sector * sector() { return sector_; } - - Ogre::SceneNode * rotnode() { return mainNodeEntityRot_;} - protected: Station * station_; Ogre::SceneNode * ringNode_; @@ -159,9 +168,43 @@ StationPad * dockPad_; StationPad * launchPad_; //StationDockPad * dockPad_; +}; + +/*! A station pad is a plain area where vessel dock or launch */ +class BeaconPad : public Pad{ +public: + /*! Constructor, with a name, */ + BeaconPad( const std::string & name, BeaconObject * station, Ogre::SubEntity * padSubEntity ); + + /*! Destructor */ + virtual ~BeaconPad( ); + + /*! What happen on collision */ + void collide( BaseObject * object ); + + void changeEntity( const std::string & meshname ); + +protected: }; +class BeaconObject : public SectorObject { +public: + BeaconObject( Sector * sector ); + + virtual ~BeaconObject( ); + + /*! Return entrance position in world coordinates */ + Ogre::Vector3 entrancePosition() const; + + /*! Return exit position in world coordinates */ + Ogre::Vector3 exitPosition() const; + +protected: + BeaconPad * entryPad_; + BeaconPad * exitPad_; +}; + } // namespace OpenGate #endif //_OPENGATE_STATION__H Modified: trunk/src/UnDockedState.cpp =================================================================== --- trunk/src/UnDockedState.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/UnDockedState.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -771,7 +771,7 @@ } void UnDockedState::setTarget( SectorObject * target ) { - SectorObject * oldTarget = target_; + // SectorObject * oldTarget = target_; target_ = target; if ( target_ != NULL ){ Modified: trunk/src/Vessel.cpp =================================================================== --- trunk/src/Vessel.cpp 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Vessel.cpp 2008-05-14 21:33:27 UTC (rev 897) @@ -25,28 +25,29 @@ #include <OgreMeshManager.h> namespace OpenGate{ - + Vessel::Vessel( ) : Moveable() { - rtti_ = VESSEL; - fixEquipment_ = false; + rtti_ = VESSEL; + fixEquipment_ = false; - amountModX_ = 0; + amountModX_ = 0; amountMissiles_ = 0; - - shieldSize_ = 0; - radarSize_ = 0; - engineSize_ = 0; - capacitorSize_ = 0; + + shieldSize_ = 0; + radarSize_ = 0; + engineSize_ = 0; + capacitorSize_ = 0; powerPlantSize_ = 0; - cargoSize_ = 0; - ecmSize_ = 0; - missileSize_ = 0; - powerPlant_ = NULL; - engine_ = NULL; - radar_ = NULL; - ecm_ = NULL; - shield_ = NULL; - capacitor_ = NULL; + cargoSize_ = 0; + ecmSize_ = 0; + missileSize_ = 0; + + powerPlant_ = NULL; + engine_ = NULL; + radar_ = NULL; + ecm_ = NULL; + shield_ = NULL; + capacitor_ = NULL; } std::vector < Ogre::Vector3 > findMountPoints( TiXmlHandle * hRoot, const std::string & key ){ @@ -60,7 +61,7 @@ return mountPoints; } -bool Vessel::readPropertiesFromXML( TiXmlHandle & hRoot ){ +void Vessel::readPropertiesFromXML( TiXmlHandle & hRoot ){ Moveable::readPropertiesFromXML( hRoot ); readXMLNode< int >( hRoot, "modx", this, &OpenGate::Vessel::setAmountModX, false ); @@ -262,7 +263,7 @@ } Ogre::Real Vessel::maxSpeed() const { - if ( engine_ ) return sqrt( engine_->maxThrust() / dragFactor() ); + if ( engine_ ) return std::sqrt( engine_->maxThrust() / dragFactor() ); return 0.0; } @@ -273,7 +274,7 @@ lifetime_ = 1; } -bool Missile::readPropertiesFromXML( TiXmlHandle & hRoot ){ +void Missile::readPropertiesFromXML( TiXmlHandle & hRoot ){ Moveable::readPropertiesFromXML( hRoot ); readXMLNode< int >( hRoot, "damage", this, &OpenGate::Missile::setDamage, false ); Modified: trunk/src/Vessel.h =================================================================== --- trunk/src/Vessel.h 2008-05-12 16:19:10 UTC (rev 896) +++ trunk/src/Vessel.h 2008-05-14 21:33:27 UTC (rev 897) @@ -67,94 +67,93 @@ /*! Desctructor */ virtual ~Vessel(){} - bool readPropertiesFromXML( TiXmlHandle & hRoot ); + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline void setFixEquipment( bool fix ) { fixEquipment_ = fix; } - inline bool fixEquipment( ) const { return fixEquipment_ ; } + inline bool fixEquipment( ) const { return fixEquipment_ ; } - inline void setPowerPlantSize( int size ){ powerPlantSize_ = size; } - inline int powerPlantSize( ) const { return powerPlantSize_; } - bool setPowerPlant( PowerPlant * item ); - inline PowerPlant * powerPlant( ){ return powerPlant_; } + inline void setPowerPlantSize( int size ){ powerPlantSize_ = size; } + inline int powerPlantSize( ) const { return powerPlantSize_; } + bool setPowerPlant( PowerPlant * item ); + inline PowerPlant * powerPlant( ){ return powerPlant_; } - inline void setEngineSize( int size ){ engineSize_ = size; } - inline int engineSize( ) const { return engineSize_; } - bool setEngine( Engine * item ); - inline Engine * engine( ){ return engine_; } + inline void setEngineSize( int size ){ engineSize_ = size; } + inline int engineSize( ) const { return engineSize_; } + bool setEngine( Engine * item ); + inline Engine * engine( ){ return engine_; } - inline void setRadarSize( int size ){ radarSize_ = size; } - inline int radarSize( ) const { return radarSize_; } - bool setRadar( Radar * item ); - inline Radar * radar( ){ return radar_; } + inline void setRadarSize( int size ){ radarSize_ = size; } + inline int radarSize( ) const { return radarSize_; } + bool setRadar( Radar * item ); + inline Radar * radar( ){ return radar_; } - inline void setEcmSize( int size ){ ecmSize_ = size; } - inline int ecmSize( ) const { return ecmSize_; } - bool setEcm( Ecm *... [truncated message content] |
From: <spo...@us...> - 2008-05-18 19:34:01
|
Revision: 900 http://opengate.svn.sourceforge.net/opengate/?rev=900&view=rev Author: spom_spom Date: 2008-05-18 12:30:59 -0700 (Sun, 18 May 2008) Log Message: ----------- Add opengate python bindings for the opengate editor Modified Paths: -------------- templates/stations/tauseti_wake_2.blend trunk/ToDo trunk/configure.ac trunk/src/AiObject.h trunk/src/BaseDialog.cpp trunk/src/BaseDialog.h trunk/src/BaseObject.cpp trunk/src/BaseObject.h trunk/src/ConfigDialog.h trunk/src/Console.cpp trunk/src/Console.h trunk/src/DockedState.cpp trunk/src/DockedState.h trunk/src/Entity.cpp trunk/src/Entity.h trunk/src/EntityManager.cpp trunk/src/EntityManager.h trunk/src/Equipment.cpp trunk/src/Equipment.h trunk/src/GameStateManager.cpp trunk/src/GameStateManager.h trunk/src/InputManager.h trunk/src/KeyMap.cpp trunk/src/KeyMap.h trunk/src/Makefile.am trunk/src/MarketDialog.h trunk/src/Moveable.cpp trunk/src/OpcodeWrapper.h trunk/src/OpenALSoundManager.h trunk/src/ResourceManager.cpp trunk/src/ResourceManager.h trunk/src/Sector.cpp trunk/src/SectorObject.h trunk/src/SectorObjectMissile.cpp trunk/src/SectorObjectMoveable.cpp trunk/src/ShipConfigDialog.cpp trunk/src/ShipConfigDialog.h trunk/src/UnDockedState.cpp trunk/src/Vessel.h trunk/src/commonWithOgre.cpp trunk/src/commonWithOgre.h Added Paths: ----------- templates/missiles/ templates/missiles/firefly.blend Removed Paths: ------------- trunk/data/menus/ Added: templates/missiles/firefly.blend =================================================================== (Binary files differ) Property changes on: templates/missiles/firefly.blend ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: templates/stations/tauseti_wake_2.blend =================================================================== (Binary files differ) Modified: trunk/ToDo =================================================================== --- trunk/ToDo 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/ToDo 2008-05-18 19:30:59 UTC (rev 900) @@ -210,3 +210,10 @@ -Guns: Dazzler -Missiles: Firefly, Dragonfly, Mosquito, Bee, Hummel, Hornet + + +Possible Refaktor: (Hier steht Kram den man vielleicht mal aufr\xE4umen kann oder sollte, das ist entweder: alter schief gewachsener code, unsicherheiten, +als ich das machte konnte ichs nicht besser, einfach nur Mist, etc... ) + + /*! Returns the set of known resource paths, maybee this this can be saver by using ogre resource Manager directly instead of holding our own set. */ + std::set < std::string > & ResourceManager::resourcePaths(); Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/configure.ac 2008-05-18 19:30:59 UTC (rev 900) @@ -26,6 +26,8 @@ AC_TYPE_SIGNAL AC_TYPE_SIZE_T +AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -Wall -fPIC"]) + # Check for header files AC_CHECK_HEADERS([float.h stddef.h sys/timeb.h]) Modified: trunk/src/AiObject.h =================================================================== --- trunk/src/AiObject.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/AiObject.h 2008-05-18 19:30:59 UTC (rev 900) @@ -83,9 +83,10 @@ /*! Idle and look every second for new orders */ //bool cmdIdle( ); /*! Wait and do nothing */ - bool cmdWait( double time ); + bool cmdWait( double time ){return true;} + /*! Accelerate a given time with a given thrustRate */ - bool cmdAccelerate( double time, double thrustRate ); + bool cmdAccelerate( double time, double thrustRate ){ return true; } /*! Calculate maximum speed from a given thrustRate [0..1]*/ double maxSpeed( double thrustRate = 1.0 ) const; Modified: trunk/src/BaseDialog.cpp =================================================================== --- trunk/src/BaseDialog.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/BaseDialog.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -24,6 +24,8 @@ #include <OgreRenderWindow.h> #include <CEGUIWindowManager.h> +#include <CEGUIWindow.h> +#include <CEGUIImageset.h> namespace OpenGate{ Modified: trunk/src/BaseDialog.h =================================================================== --- trunk/src/BaseDialog.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/BaseDialog.h 2008-05-18 19:30:59 UTC (rev 900) @@ -21,7 +21,7 @@ #ifndef _OPENGATE_BASEDIALOG__H #define _OPENGATE_BASEDIALOG__H -#include "GameState.h" +//#include "GameState.h" #include <string> @@ -32,6 +32,8 @@ namespace OpenGate{ +class ResourceManager; + void renameClonedWindows( const CEGUI::Window * parent, const CEGUI::String & namePrefix ); void fitWindowToImage( const std::string & name, CEGUI::Window * win ); float windowHeight( const CEGUI::Window * child ); Modified: trunk/src/BaseObject.cpp =================================================================== --- trunk/src/BaseObject.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/BaseObject.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -63,6 +63,10 @@ } } +void BaseObject::setVisible( bool visible ) { + mainNode_->setVisible( visible ); +} + void BaseObject::destroy(){ destroyRequest_ = true; } Modified: trunk/src/BaseObject.h =================================================================== --- trunk/src/BaseObject.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/BaseObject.h 2008-05-18 19:30:59 UTC (rev 900) @@ -21,16 +21,17 @@ #ifndef _OPENGATE_BASEOBJECT__H #define _OPENGATE_BASEOBJECT__H -//#include <OgrePrerequisites.h> - #include "common.h" -#include <OgreSceneNode.h> +#include <OgrePrerequisites.h> +#include <OgreVector3.h> +//#include <OgreSceneNode.h> +//#include <OgreEntity.h> namespace OgreOpcode{ class CollisionObject; } - + namespace OpenGate{ #define PROJECTILE_RTTI 100001 @@ -73,7 +74,7 @@ inline Ogre::SceneNode * mainNode() { return mainNode_; } - inline Ogre::SceneNode mainNode() const { return *mainNode_; } + inline Ogre::SceneNode * mainNode() const { return mainNode_; } virtual bool update( Ogre::Real elapsedTime ) = 0; @@ -86,8 +87,6 @@ bool selectable() const { return selectable_ ;} void setSelectable( bool selectable ) { selectable_ = selectable; } - - Ogre::Vector3 position() const; /*! Mark the object for destruction To keep destruction thread safe, we just notify and let the update cycle do the job */ @@ -95,7 +94,7 @@ bool isSetDestroyRequest() const { return destroyRequest_; } - virtual void setVisible( bool visible ) { mainNode_->setVisible( visible ); } + virtual void setVisible( bool visible ); virtual void setActive( bool active ); Modified: trunk/src/ConfigDialog.h =================================================================== --- trunk/src/ConfigDialog.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/ConfigDialog.h 2008-05-18 19:30:59 UTC (rev 900) @@ -25,6 +25,7 @@ namespace CEGUI{ class Listbox; + class EventArgs; } namespace OpenGate{ Modified: trunk/src/Console.cpp =================================================================== --- trunk/src/Console.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Console.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -18,9 +18,14 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "Console.h" + #include "common.h" + #include "ResourceManager.h" -#include "Console.h" +// #include "GameState.h" +#include "GameStateManager.h" + #include "LogManager.h" #include "networkClient.h" #include "KeyMap.h" Modified: trunk/src/Console.h =================================================================== --- trunk/src/Console.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Console.h 2008-05-18 19:30:59 UTC (rev 900) @@ -18,24 +18,34 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef CONSOLE__H -#define CONSOLE__H +#ifndef _OPENGATE_CONSOLE__H +#define _OPENGATE_CONSOLE__H -#include <OgrePrerequisites.h> +#include "InputManager.h" + +// #include <OgrePrerequisites.h> +#include <OgreFrameListener.h> + #include <list> -#include <vector> -#include "GameState.h" -#include "GameStateManager.h" +#include <vector> +namespace CEGUI{ + class EventArgs; + class Window; + class Editbox; + class Listbox; +} + namespace OpenGate{ - + +class GameStateManager; +class ResourceManager; + class Console : public Ogre::FrameListener, public OIS::KeyListener { public: Console(); ~Console(); - - void setVisible( bool visible ); void start( ); void stop( ); @@ -50,9 +60,8 @@ virtual bool keyPressed( const OIS::KeyEvent & e ); virtual bool keyReleased( const OIS::KeyEvent & e ); - - void addCommand( const std::string & command, - void (GameStateManager::*ptr) ( const std::vector< std::string > & ), const std::string & help ); + void addCommand( const std::string & command, void (GameStateManager::*ptr) ( const std::vector< std::string > & ), const std::string & help ); + void removeCommand( const std::string & command ); virtual void write( const std::string & name, const std::string & message, bool maskDebug = false ){ Modified: trunk/src/DockedState.cpp =================================================================== --- trunk/src/DockedState.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/DockedState.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -20,9 +20,12 @@ #include "DockedState.h" #include "Console.h" +#include "GameStateManager.h" #include "Avatar.h" #include "Vessel.h" #include "OpenALSoundManager.h" +#include "ShipConfigDialog.h" +#include "MarketDialog.h" #include <OgreRoot.h> #include <OgreRenderWindow.h> Modified: trunk/src/DockedState.h =================================================================== --- trunk/src/DockedState.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/DockedState.h 2008-05-18 19:30:59 UTC (rev 900) @@ -21,17 +21,19 @@ #ifndef _OPENGATE_DOCKEDSTATELISTENER__H #define _OPENGATE_DOCKEDSTATELISTENER__H -#include <OgrePrerequisites.h> +// #include <OgrePrerequisites.h> #include "LogManager.h" #include "GameState.h" -#include "ShipConfigDialog.h" -#include "MarketDialog.h" +// #include "ShipConfigDialog.h" +// #include "MarketDialog.h" namespace OpenGate{ class OpenALSoundSource; - +class ShipConfigDialog; +class MarketDialog; + /*! * \brief This class defines the gamestate the gamestate when the user is docked * Modified: trunk/src/Entity.cpp =================================================================== --- trunk/src/Entity.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Entity.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -20,18 +20,22 @@ #include "Entity.h" +#include "common.h" +#include <string> + +#include "ResourceManager.h" +#include "LogManager.h" + #include <OgreException.h> #include <OgreCEGUITexture.h> #include <CEGUIImageset.h> #include <CEGUIExceptions.h> #include <CEGUIBase.h> -#include "ResourceManager.h" - namespace OpenGate{ Entity::Entity() - : name_( "unknown" ), className_( "unknown" ), + : name_( "unknown" ), category_( "unknown Entity" ), description_("Please fill in description"), imageFileName_("unknown"), ceguiImageName_( "unknownEntityImageset") { //** just an idea // addProperty< float >( "baseYaw", this, setBaseYaw, baseYaw, mandatory, default, description ) @@ -55,8 +59,8 @@ } void Entity::setFactionID( int id ){ - factionID_ = id; - setFactionName_( ResourceManager::getSingleton().factionName( factionID_ ) ); + factionID_ = id; + setFactionName_( ResourceManager::getSingleton().factionName( factionID_ ) ); } void Entity::setBaseSize( float length, float width, float height ){ @@ -131,7 +135,8 @@ readXMLNode< Uint16 >( hRoot, "object_id", this, &OpenGate::Entity::setID, true ); readXMLNode< Uint8 >( hRoot, "faction_id", this, &OpenGate::Entity::setFactionID, true ); - readXMLNode< Uint8 >( hRoot, "class_id", this, &OpenGate::Entity::setClassID, false ); + // what is that for + //readXMLNode< Uint8 >( hRoot, "class_id", this, &OpenGate::Entity::setClassID, false ); readXMLNode< Uint8 >( hRoot, "techlevel required_rank", this, &OpenGate::Entity::setTechLevel, false ); readXMLNode< int >( hRoot, "size", this, &OpenGate::Entity::setSize, false ); Modified: trunk/src/Entity.h =================================================================== --- trunk/src/Entity.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Entity.h 2008-05-18 19:30:59 UTC (rev 900) @@ -24,16 +24,22 @@ #include <set> #include <string> -#include "LogManager.h" -#include "ResourceManager.h" +#include "common.h" #include <OgreVector3.h> +// namespace Ogre{ +// class Vector3; +// class Real; +// } + namespace OpenGate{ enum EntityType{NONE,ENTITY,VESSEL,COMMODITY,POWERPLANT,ENGINE,RADAR,ECM,CAPACITOR,SHIELD,GUN,MISSILE,MODX}; - +enum GunType{UNKNOWN,LASER,MININGLASER,BULLET}; + class Commodity; +class ResourceManager; // class Property { // public: @@ -79,12 +85,10 @@ inline void setName( const std::string & name ) { name_ = name; } inline std::string name( ) const { return name_; } - - inline void setClassID( Uint8 id ) { className_ = ResourceManager::getSingleton().className( id ); } - - inline void setClassName( const std::string & name ) { className_ = name; } - inline std::string className( ) const { return className_; } + inline void setCategoryName( const std::string & category ) { category_ = category; } + inline std::string categoryName( ) const { return category_; } + inline void setID( int id ){ id_ = id; } inline int id( ) const { return id_; } @@ -141,7 +145,7 @@ void loadImages_( ); std::string name_; - std::string className_; + std::string category_; /*! A rather long description of this component */ std::string description_; Modified: trunk/src/EntityManager.cpp =================================================================== --- trunk/src/EntityManager.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/EntityManager.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -19,6 +19,7 @@ ***************************************************************************/ #include "EntityManager.h" +#include "LogManager.h" #include "ResourceManager.h" #include "tinyxml/tinyxml.h" #include "Vessel.h" @@ -228,7 +229,9 @@ log_->fatal( fileName + " has no category_id (mandatory)." ); return NULL; } - //** Image name for the entity is derived from filename; + entity->setCategoryName( categoryName( entity->entityType() ) ); + + //** Image name for the entity is derived from filename; std::string basename( fileName.substr( fileName.rfind( "/" ) + 1 ) ); entity->setImageName( basename.substr( 0, basename.find( ".xml" ) ) ); @@ -236,6 +239,7 @@ entity->readPropertiesFromXML( hRoot ); } catch ( std::invalid_argument e ){ log_->warn( e.what() ); + delete entity; return NULL; } @@ -247,7 +251,7 @@ log_->warn( std::string( "Equipment with name: " ) + entity->factionName() + "/" + entity->name() + " already loaded" ); } - + categories_.insert( entity->categoryName() ); return entity; } Modified: trunk/src/EntityManager.h =================================================================== --- trunk/src/EntityManager.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/EntityManager.h 2008-05-18 19:30:59 UTC (rev 900) @@ -21,11 +21,12 @@ #ifndef _OPENGATE_ENTITYMANAGER_H #define _OPENGATE_ENTITYMANAGER_H -#include "LogManager.h" #include "Entity.h" namespace OpenGate { +class LogManager; + class PowerPlant; class Engine; class Radar; @@ -68,7 +69,9 @@ void load( const std::set < std::string > & resourcePaths, const std::string & resourceName ); inline std::set < std::string > factionNames( ) const { return factions_; } - + + inline std::set < std::string > categories( ) const { return categories_; } + EntityType categoryType( const std::string & category ); std::string categoryName( EntityType type ); @@ -105,8 +108,8 @@ if ( item->entityType() == tmp.entityType() ) { return dynamic_cast< EntityType * >(item); } else { - LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + name + - " is a " + categoryName( item->entityType() ) ); +// LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + name + +// " is a " + categoryName( item->entityType() ) ); } return NULL; } @@ -120,8 +123,8 @@ if ( item->entityType() == tmp.entityType() ) { return dynamic_cast< EntityType * >(item); } else { - LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + toStr( ID ) + - " is a " + categoryName( item->entityType() ) ); +// LogManager::getSingleton().warn( "Requested " + categoryName( tmp.entityType() ) + ": " + toStr( ID ) + +// " is a " + categoryName( item->entityType() ) ); } return NULL; } @@ -132,6 +135,7 @@ std::map < std::string, Entity * > templatesByName_; std::map < Uint16, Entity * > templatesByID_; std::set < std::string > factions_; + std::set < std::string > categories_; }; } // namespace OpenGate Modified: trunk/src/Equipment.cpp =================================================================== --- trunk/src/Equipment.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Equipment.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -22,7 +22,62 @@ #include "common.h" namespace OpenGate{ + +void Commodity::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Entity::readPropertiesFromXML( hRoot ); + readXMLNode< int >( hRoot, "melting-point", this, &OpenGate::Commodity::setMeltingPoint, false ); + readXMLNode< double >( hRoot, "gravitic-sig", this, &OpenGate::Commodity::setGraviticSig, false ); +} +void Equipment::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Entity::readPropertiesFromXML( hRoot ); + readXMLNode< double >( hRoot, "efficency", this, &OpenGate::Equipment::setEfficiency, false ); + readXMLNode< std::string >( hRoot, "Manufacturer", this, &OpenGate::Equipment::setManufacturer, false ); + readXMLNode< Uint32 >( hRoot, "power_input", this, &OpenGate::Equipment::setPowerConsumption, false ); +} + +void PowerPlant::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint32 >( hRoot, "power_output", this, &OpenGate::PowerPlant::setPowerOutput, false ); + } + +void Engine::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint32 >( hRoot, "maximum_thrust", this, &OpenGate::Engine::setMaxThrust, false ); + } + +void Radar::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint32 >( hRoot, "maximum_range", this, &OpenGate::Radar::setMaxRange, false ); + } + +void Ecm::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint8 >( hRoot, "sensorlevel", this, &OpenGate::Ecm::setSensorLevel, false ); + } + +void Shield::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint32 >( hRoot, "regeneration_rate", this, &OpenGate::Shield::setRegenerationRate, false ); + readXMLNode< Uint32 >( hRoot, "maximum_deflection", this, &OpenGate::Shield::setMaxDeflection, false ); + } + +void Capacitor::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint32 >( hRoot, "capacity", this, &OpenGate::Capacitor::setCapacity, false ); +} + +void Gun::readPropertiesFromXML( TiXmlHandle & hRoot ){ + Equipment::readPropertiesFromXML( hRoot ); + readXMLNode< Uint32 >( hRoot, "damage", this, &OpenGate::Gun::setDamage, false ); + readXMLNode< Uint32 >( hRoot, "velocity", this, &OpenGate::Gun::setSpeed, false ); + readXMLNode< std::string >( hRoot, "type", this, &OpenGate::Gun::setType, false ); + readXMLNode< double >( hRoot, "life_time", this, &OpenGate::Gun::setLifeTime, false ); + readXMLNode< double >( hRoot, "fire_delay", this, &OpenGate::Gun::setFireDelay, false ); + readXMLNode< Uint32 >( hRoot, "power_per_shot", this, &OpenGate::Gun::setEnergy, false ); +} + + } // namespace OpenGate Modified: trunk/src/Equipment.h =================================================================== --- trunk/src/Equipment.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Equipment.h 2008-05-18 19:30:59 UTC (rev 900) @@ -24,9 +24,10 @@ #include <set> #include <string> -#include "LogManager.h" #include "Entity.h" +#include "common.h" + #include <OgreVector3.h> namespace OpenGate{ @@ -47,11 +48,8 @@ meltingPoint_ = 0; graviticSig_ = 0.0; } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Entity::readPropertiesFromXML( hRoot ); - readXMLNode< int >( hRoot, "melting-point", this, &OpenGate::Commodity::setMeltingPoint, false ); - readXMLNode< double >( hRoot, "gravitic-sig", this, &OpenGate::Commodity::setGraviticSig, false ); - } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); + inline void setMeltingPoint( int meltingPoint ){ meltingPoint_ = meltingPoint; } inline int meltingPoint( ) const { return meltingPoint_; } @@ -84,13 +82,8 @@ class Equipment : public Entity{ public: - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Entity::readPropertiesFromXML( hRoot ); - readXMLNode< double >( hRoot, "efficency", this, &OpenGate::Equipment::setEfficiency, false ); - readXMLNode< std::string >( hRoot, "Manufacturer", this, &OpenGate::Equipment::setManufacturer, false ); - readXMLNode< Uint32 >( hRoot, "power_input", this, &OpenGate::Equipment::setPowerConsumption, false ); - } - + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); + inline void setManufacturer( const std::string & manufacturer ) { manufacturer_ = manufacturer; } inline std::string manufacturer( ) const { return manufacturer_; } @@ -134,15 +127,12 @@ */ class PowerPlant : public Equipment { public: - PowerPlant() : Equipment(){ - rtti_ = POWERPLANT; - powerOutput_ = 0; - } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint32 >( hRoot, "power_output", this, &OpenGate::PowerPlant::setPowerOutput, false ); - } - + PowerPlant() : Equipment(){ + rtti_ = POWERPLANT; + powerOutput_ = 0; + } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); + inline void setPowerOutput( Uint32 power ) { powerOutput_ = power; //** if input power is < 100kW, then input is scaled in kW @@ -165,16 +155,13 @@ class Engine : public Equipment { public: - Engine() : Equipment() { - rtti_ = ENGINE; - maxThrust_ = 0; - } + Engine() : Equipment() { + rtti_ = ENGINE; + maxThrust_ = 0; + } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint32 >( hRoot, "maximum_thrust", this, &OpenGate::Engine::setMaxThrust, false ); - } - + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); + inline void setMaxThrust( Uint32 maxThrust ) { maxThrust_ = maxThrust; //** if input thrust is < 100kN, then input is scaled in kN @@ -202,10 +189,7 @@ Radar() : Equipment(){ rtti_ = RADAR; } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint32 >( hRoot, "maximum_range", this, &OpenGate::Radar::setMaxRange, false ); - } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline void setMaxRange( Uint32 range ){ range_ = range; } inline Uint32 maxRange() const{ return range_; } @@ -229,10 +213,7 @@ rtti_ = ECM; sensorLevel_ = 0; } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint8 >( hRoot, "sensorlevel", this, &OpenGate::Ecm::setSensorLevel, false ); - } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline void setSensorLevel( short sensorLevel ) { sensorLevel_ = sensorLevel; } inline Uint8 sensorLevel( ) { return sensorLevel_; } @@ -255,11 +236,7 @@ Shield() : Equipment(){ rtti_ = SHIELD; } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint32 >( hRoot, "regeneration_rate", this, &OpenGate::Shield::setRegenerationRate, false ); - readXMLNode< Uint32 >( hRoot, "maximum_deflection", this, &OpenGate::Shield::setMaxDeflection, false ); - } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline void setMaxDeflection( Uint32 deflection ){ setMaximumDeflection_ = deflection; @@ -297,10 +274,7 @@ rtti_ = CAPACITOR; capacity_ = 0; } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint32 >( hRoot, "capacity", this, &OpenGate::Capacitor::setCapacity, false ); - } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); inline void setCapacity( Uint32 capacity ) { capacity_ = capacity; @@ -316,20 +290,13 @@ class Gun : public Equipment{ public: - Gun(): Equipment(){ - rtti_ = GUN; - type_ = UNKNOWN; - } - virtual void readPropertiesFromXML( TiXmlHandle & hRoot ){ - Equipment::readPropertiesFromXML( hRoot ); - readXMLNode< Uint32 >( hRoot, "damage", this, &OpenGate::Gun::setDamage, false ); - readXMLNode< Uint32 >( hRoot, "velocity", this, &OpenGate::Gun::setSpeed, false ); - readXMLNode< std::string >( hRoot, "type", this, &OpenGate::Gun::setType, false ); - readXMLNode< double >( hRoot, "life_time", this, &OpenGate::Gun::setLifeTime, false ); - readXMLNode< double >( hRoot, "fire_delay", this, &OpenGate::Gun::setFireDelay, false ); - readXMLNode< Uint32 >( hRoot, "power_per_shot", this, &OpenGate::Gun::setEnergy, false ); + Gun(): Equipment(){ + rtti_ = GUN; + type_ = UNKNOWN; } + virtual void readPropertiesFromXML( TiXmlHandle & hRoot ); + void setType( const std::string & type ) { if ( type == "laser" ){ type_ = LASER; Modified: trunk/src/GameStateManager.cpp =================================================================== --- trunk/src/GameStateManager.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/GameStateManager.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -61,54 +61,6 @@ //** without any gamestate, shutdown immediately; shutdownRequest_ = initialiseBootstrap( dialog ); - - //** start for test purposes; -// const Ogre::RenderSystemCapabilities * caps = Ogre::Root::getSingleton().getRenderSystem()->getCapabilities(); -// if ( !caps->hasCapability( Ogre::RSC_VERTEX_PROGRAM ) ) { -// OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Your card does not support vertex programs.", -// "GameStateManager::GameStateManager"); -// } -// if ( !( caps->hasCapability( Ogre::RSC_FRAGMENT_PROGRAM ) || caps->hasCapability( Ogre::RSC_DOT3 ) ) ) { -// OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Your card does not support dot3 blending or fragment programs.", -// "GameStateManager::GameStateManager" ); -// } - -// Ogre::SceneManager* sceneMgr = devices_.ogreRoot->createSceneManager(Ogre::ST_GENERIC); -// Ogre::Camera* camera = sceneMgr->createCamera("SimpleCamera"); -// resources_.ogreRoot->addFrameListener(&frameListener); -// camera->setPosition( Ogre::Vector3( 0, 0, 200 ) ); -// camera->lookAt( Ogre::Vector3( 0, 0, -300 ) ); -// camera->setNearClipDistance( 1 ); -// sceneMgr->setAmbientLight( Ogre::ColourValue(0.1, 0.1, 0.1) ); -// Ogre::SceneNode * mainNode = static_cast< Ogre::SceneNode * >( sceneMgr->getRootSceneNode()->createChild("test") ); - -// Ogre::SceneNode * light = sceneMgr->getRootSceneNode()->createChildSceneNode("baseLight"); -// Ogre::Light * l = sceneMgr->createLight("Light" ); -// l->setDiffuseColour( Ogre::ColourValue(1, 1, 1) ); -// l->setSpecularColour( Ogre::ColourValue(1, 1, 1) ); -// l->setVisible( true ); -// light->setPosition( 0, 0, 500); -// light->attachObject( l ); - -// Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load( "ogrehead.mesh", -// Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, -// Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, -// Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, -// true, true); -// unsigned short src, dest; -// if ( !pMesh->suggestTangentVectorBuildParams( Ogre::VES_TANGENT, src, dest) ) { -// pMesh->buildTangentVectors( Ogre::VES_TANGENT, src, dest); -// } - -// Ogre::Entity * shape = sceneMgr->createEntity( "ogrehead", "ogrehead.mesh" ); -// shape->setMaterialName("Examples/BumpMapping/MultiLight"); - -// mainNode->attachObject( shape ); -// devices_.ogreRoot->startRendering(); -// while( 1 ){ -// resources_.ogreRoot->renderOneFrame( ); -// } - //** end just for test purposes } GameStateManager::~GameStateManager( ){ @@ -158,181 +110,6 @@ // if ( resources_.ogreRoot ) delete resources_.ogreRoot; } -void GameStateManager::switchConfigDialog( ){ - if ( configDialog_->isVisible() ) { - configDialog_->hide(); - } else{ - configDialog_->show(); - } -} - -void GameStateManager::manageGameState( const std::string & stateName, GameState * state ){ - StateInfo newStateInfo; - newStateInfo.name = stateName; - newStateInfo.state = state; - newStateInfo.state->init( ); - states_.push_back( newStateInfo ); -} - -void GameStateManager::start( GameState * state ){ - if ( state ){ - shutdownRequest_ = false; - changeGameState( state ); - } - - while ( !shutdownRequest_ ){ - if ( resources_.inputManager ) resources_.inputManager->capture(); - - captureNetwork(); - - Ogre::WindowEventUtilities::messagePump(); - -#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - { - MSG msg; - while ( PeekMessage( & msg, NULL, 0, 0, PM_REMOVE ) ) { - if ( msg.message == WM_QUIT ){ - shutdown(); - } else { - // TranslateMessage(&msg); - // DispatchMessage(&msg); - } - } - } -#endif - resources_.ogreRoot->renderOneFrame( ); - } -} - -bool GameStateManager::captureNetwork(){ - //** start capture network; - std::vector < std::vector < char > > msgs; - std::vector < MessageBodyShipMovement * > movements; - resources_.network->pull( msgs ); - - Sector * sector = NULL; - if ( stateStack_.back()->name() == "UnDockedState" ){ - sector = dynamic_cast < UnDockedState * >(stateStack_.back())->sector(); - } - - if ( msgs.size() > 0 ) { - // LogManager::getSingleton().debug( std::string( "Pullcount: " ) + toStr( msgs.size() ) ); - for ( size_t i = 0; i < msgs.size(); i ++ ){ - - // LogManager::getSingleton().debug( std::string( "Pull: " ) + toStr( (int)msgs[ i ][ 0 ] ) ); - // if ( msgs[ i ][ 0 ] == PROTO_SHIPMOVEMENT ) { - // MessageBodyShipMovement m( &msgs[ i ][ 0 ] ); - // std::cout << m << std::endl; - // } - - switch ( msgs[ i ][ 0 ] ){ - case PROTO_CHAT:{ - resources_.network->ping(); - MessageBodyChat msg( &msgs[ i ][ 0 ] ); - log_->chat( resources_.network->userName( msg.senderID() ), msg.message() ); - } break; - case PROTO_SHIP_REGISTER: - if ( sector ) sector->receiveVesselRegister( &msgs[ i ][ 0 ] ); break; - case PROTO_SHIP_DEREGISTER: - if ( sector ) sector->receiveVesselDeRegister( &msgs[ i ][ 0 ] ); break; - case PROTO_SHIP_DIED: - if ( sector ) sector->receiveVesselDied( &msgs[ i ][ 0 ] ); break; - case PROTO_SHIP_STATUS: - if ( sector ) sector->receiveVesselStatus( &msgs[ i ][ 0 ] ); break; - case PROTO_SHIP_MOVEMENT:{ - //** we handle that in sum, so we can ignore dups because of packet loss - MessageBodyShipMovement *msg = new MessageBodyShipMovement( &msgs[ i ][ 0 ] ); - movements.push_back( msg ); - } break; - case PROTO_SHIP_PROJECTILEFIRED: - if ( sector ) sector->receiveProjectile( &msgs[ i ][ 0 ] ); break; - case PROTO_SHIP_AMMOHIT: - if ( sector ) sector->receiveVesselAmmoHit( &msgs[ i ][ 0 ] ); break; - default: - std::cerr << "PROTO type unknown: " << msgs[ i ][ 0 ] << " " << msgs[ i ].size() << std::endl; - break; - } - } - if ( movements.size() > 0 && sector ) sector->receiveVesselMovement( movements ); - } - return true; -} - -GameState * GameStateManager::findByName( const std::string & stateName ) { - for ( std::vector< StateInfo >::iterator itr = states_.begin(); itr != states_.end(); itr++ ) { - if ( itr->name == stateName ) - return itr->state; - } - log_->fatal( std::string( "Cannot find gamestate: " ) + stateName ); - log_->fatal( "Available states: " ); - for ( std::vector< StateInfo >::iterator itr = states_.begin(); itr != states_.end(); itr++ ) { - log_->fatal( std::string( "\t" ) + itr->name ) ; - } - return NULL; -} - -void GameStateManager::changeGameState( GameState * state ){ - // cleanup the current game state - if ( !stateStack_.empty() ) { - cleanup_( stateStack_.back() ); - if ( stateStack_.back()->rootWindow() ) stateStack_.back()->rootWindow()->removeChildWindow( configDialog_->rootWindow() ); - stateStack_.back()->exit(); - stateStack_.pop_back(); - } - - // store and init the new state - stateStack_.push_back( state ); - stateStack_.back()->enter(); - if ( stateStack_.back()->rootWindow() ) stateStack_.back()->rootWindow()->addChildWindow( configDialog_->rootWindow() ); - init_( state ); -} - -bool GameStateManager::pushGameState( GameState * state ){ - // pause current game state - if ( !stateStack_.empty() ) { - if ( !stateStack_.back()->pause() ){ - return false; - } - cleanup_( stateStack_.back() ); - } - - // store and init the new state - stateStack_.push_back( state ); - init_( state ); - stateStack_.back()->enter(); - - return true; -} - -void GameStateManager::popGameState( ) { - // cleanup the current game state - if ( !stateStack_.empty() ) { - cleanup_( stateStack_.back() ); - stateStack_.back()->exit(); - stateStack_.pop_back(); - } - - // resume previous game state or quit if there isn't one - if ( !stateStack_.empty() ) { - init_( stateStack_.back() ); - stateStack_.back()->resume(); - } else { - shutdown(); - } -} - -void GameStateManager::shutdown( ){ - shutdownRequest_ = true; -} - -void GameStateManager::init_( GameState * state ) { - resources_.ogreRoot->addFrameListener( state ); -} - -void GameStateManager::cleanup_( GameState * state ){ - resources_.ogreRoot->removeFrameListener( state ); -} - bool GameStateManager::initialiseBootstrap( bool dialog ){ resources_.ogreRoot = new Ogre::Root; resources_.gameStateRoot = this; @@ -366,7 +143,7 @@ typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName ); - resources_.resourcePaths().insert( archName ); + resources_.addResourceLocation( archName, secName ); } } } @@ -492,16 +269,16 @@ bool GameStateManager::initialiseEntityManager(){ resources_.entityManager = new EntityManager( ); - resources_.entityManager->load( resources_.resourcePaths(), "commodities" ); - resources_.entityManager->load( resources_.resourcePaths(), "engines" ); - resources_.entityManager->load( resources_.resourcePaths(), "capacitors" ); - resources_.entityManager->load( resources_.resourcePaths(), "radars" ); - resources_.entityManager->load( resources_.resourcePaths(), "shields" ); - //resources_.entityManager->load( resources_.resourcePaths(), "ecms" ); - resources_.entityManager->load( resources_.resourcePaths(), "power_plants" ); - resources_.entityManager->load( resources_.resourcePaths(), "guns" ); - resources_.entityManager->load( resources_.resourcePaths(), "missiles" ); - resources_.entityManager->load( resources_.resourcePaths(), "ships" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "commodities" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "engines" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "capacitors" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "radars" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "shields" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "ecms" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "power_plants" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "guns" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "missiles" ); + resources_.entityManager->load( resources_.resourceLocations( "General" ), "ships" ); return true; } @@ -570,12 +347,19 @@ typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName ); - resources_.resourcePaths().insert( archName ); + resources_.addResourceLocation( archName, secName ); } } } Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup( "General" ); + std::cout << "Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup( General ); " << std::endl; + Ogre::ResourceGroupManager::ResourceDeclarationList li = Ogre::ResourceGroupManager::getSingleton().getResourceDeclarationList( "General" ); + std::cout << li.size() << std::endl; + for ( std::list<Ogre::ResourceGroupManager::ResourceDeclaration>::iterator it = li.begin(); it != li.end(); it ++ ){ + std::cout << (*it).resourceName << std::endl; + } + return true; } @@ -606,6 +390,181 @@ return true; } +void GameStateManager::switchConfigDialog( ){ + if ( configDialog_->isVisible() ) { + configDialog_->hide(); + } else{ + configDialog_->show(); + } +} + +void GameStateManager::manageGameState( const std::string & stateName, GameState * state ){ + StateInfo newStateInfo; + newStateInfo.name = stateName; + newStateInfo.state = state; + newStateInfo.state->init( ); + states_.push_back( newStateInfo ); +} + +void GameStateManager::start( GameState * state ){ + if ( state ){ + shutdownRequest_ = false; + changeGameState( state ); + } + + while ( !shutdownRequest_ ){ + if ( resources_.inputManager ) resources_.inputManager->capture(); + + captureNetwork(); + + Ogre::WindowEventUtilities::messagePump(); + +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + { + MSG msg; + while ( PeekMessage( & msg, NULL, 0, 0, PM_REMOVE ) ) { + if ( msg.message == WM_QUIT ){ + shutdown(); + } else { + // TranslateMessage(&msg); + // DispatchMessage(&msg); + } + } + } +#endif + resources_.ogreRoot->renderOneFrame( ); + } +} + +bool GameStateManager::captureNetwork(){ + //** start capture network; + std::vector < std::vector < char > > msgs; + std::vector < MessageBodyShipMovement * > movements; + resources_.network->pull( msgs ); + + Sector * sector = NULL; + if ( stateStack_.back()->name() == "UnDockedState" ){ + sector = dynamic_cast < UnDockedState * >(stateStack_.back())->sector(); + } + + if ( msgs.size() > 0 ) { + // LogManager::getSingleton().debug( std::string( "Pullcount: " ) + toStr( msgs.size() ) ); + for ( size_t i = 0; i < msgs.size(); i ++ ){ + + // LogManager::getSingleton().debug( std::string( "Pull: " ) + toStr( (int)msgs[ i ][ 0 ] ) ); + // if ( msgs[ i ][ 0 ] == PROTO_SHIPMOVEMENT ) { + // MessageBodyShipMovement m( &msgs[ i ][ 0 ] ); + // std::cout << m << std::endl; + // } + + switch ( msgs[ i ][ 0 ] ){ + case PROTO_CHAT:{ + resources_.network->ping(); + MessageBodyChat msg( &msgs[ i ][ 0 ] ); + log_->chat( resources_.network->userName( msg.senderID() ), msg.message() ); + } break; + case PROTO_SHIP_REGISTER: + if ( sector ) sector->receiveVesselRegister( &msgs[ i ][ 0 ] ); break; + case PROTO_SHIP_DEREGISTER: + if ( sector ) sector->receiveVesselDeRegister( &msgs[ i ][ 0 ] ); break; + case PROTO_SHIP_DIED: + if ( sector ) sector->receiveVesselDied( &msgs[ i ][ 0 ] ); break; + case PROTO_SHIP_STATUS: + if ( sector ) sector->receiveVesselStatus( &msgs[ i ][ 0 ] ); break; + case PROTO_SHIP_MOVEMENT:{ + //** we handle that in sum, so we can ignore dups because of packet loss + MessageBodyShipMovement *msg = new MessageBodyShipMovement( &msgs[ i ][ 0 ] ); + movements.push_back( msg ); + } break; + case PROTO_SHIP_PROJECTILEFIRED: + if ( sector ) sector->receiveProjectile( &msgs[ i ][ 0 ] ); break; + case PROTO_SHIP_AMMOHIT: + if ( sector ) sector->receiveVesselAmmoHit( &msgs[ i ][ 0 ] ); break; + default: + std::cerr << "PROTO type unknown: " << msgs[ i ][ 0 ] << " " << msgs[ i ].size() << std::endl; + break; + } + } + if ( movements.size() > 0 && sector ) sector->receiveVesselMovement( movements ); + } + return true; +} + +GameState * GameStateManager::findByName( const std::string & stateName ) { + for ( std::vector< StateInfo >::iterator itr = states_.begin(); itr != states_.end(); itr++ ) { + if ( itr->name == stateName ) + return itr->state; + } + log_->fatal( std::string( "Cannot find gamestate: " ) + stateName ); + log_->fatal( "Available states: " ); + for ( std::vector< StateInfo >::iterator itr = states_.begin(); itr != states_.end(); itr++ ) { + log_->fatal( std::string( "\t" ) + itr->name ) ; + } + return NULL; +} + +void GameStateManager::changeGameState( GameState * state ){ + // cleanup the current game state + if ( !stateStack_.empty() ) { + cleanup_( stateStack_.back() ); + if ( stateStack_.back()->rootWindow() ) stateStack_.back()->rootWindow()->removeChildWindow( configDialog_->rootWindow() ); + stateStack_.back()->exit(); + stateStack_.pop_back(); + } + + // store and init the new state + stateStack_.push_back( state ); + stateStack_.back()->enter(); + if ( stateStack_.back()->rootWindow() ) stateStack_.back()->rootWindow()->addChildWindow( configDialog_->rootWindow() ); + init_( state ); +} + +bool GameStateManager::pushGameState( GameState * state ){ + // pause current game state + if ( !stateStack_.empty() ) { + if ( !stateStack_.back()->pause() ){ + return false; + } + cleanup_( stateStack_.back() ); + } + + // store and init the new state + stateStack_.push_back( state ); + init_( state ); + stateStack_.back()->enter(); + + return true; +} + +void GameStateManager::popGameState( ) { + // cleanup the current game state + if ( !stateStack_.empty() ) { + cleanup_( stateStack_.back() ); + stateStack_.back()->exit(); + stateStack_.pop_back(); + } + + // resume previous game state or quit if there isn't one + if ( !stateStack_.empty() ) { + init_( stateStack_.back() ); + stateStack_.back()->resume(); + } else { + shutdown(); + } +} + +void GameStateManager::shutdown( ){ + shutdownRequest_ = true; +} + +void GameStateManager::init_( GameState * state ) { + resources_.ogreRoot->addFrameListener( state ); +} + +void GameStateManager::cleanup_( GameState * state ){ + resources_.ogreRoot->removeFrameListener( state ); +} + void GameStateManager::CMD_shutdown( const std::vector < std::string > & argv ){ shutdown(); } Modified: trunk/src/GameStateManager.h =================================================================== --- trunk/src/GameStateManager.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/GameStateManager.h 2008-05-18 19:30:59 UTC (rev 900) @@ -57,10 +57,15 @@ /*! Destructor that cleans up the states before the instance dies. */ ~GameStateManager(); + /*! Init ogre root and call initialiseOgreEngine_. */ + bool initialiseBootstrap( bool dialog ); + + /*! Init ogre bootstrap resoucees for the init state. */ + bool initialiseBootstrapResources( ); + + /*! Init the callback list for loading the game resouces. */ void initLoadingVector(); - bool initialiseBootstrap( bool dialog ); - bool initialiseBootstrapResources( ); bool initialiseAllResources(); bool checkRenderSystemCapabilities( ); bool initialiseOgreResources( ); @@ -131,6 +136,7 @@ /*! This removes event handling from a previous state. */ void cleanup_( GameState * state ); + /*! Read ogre ogre.cfg and configure the engine e.g. screen resoulution. If there is no ogre.cfg it will create. */ bool initialiseOgreEngine_( bool dialog ); LogManager * log_; Modified: trunk/src/InputManager.h =================================================================== --- trunk/src/InputManager.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/InputManager.h 2008-05-18 19:30:59 UTC (rev 900) @@ -49,6 +49,7 @@ * * \author Carsten <spo...@us...> */ + class InputManager : public Ogre::Singleton< InputManager >, public OIS::KeyListener, public OIS::MouseListener, Modified: trunk/src/KeyMap.cpp =================================================================== --- trunk/src/KeyMap.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/KeyMap.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -18,9 +18,9 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "UnDockedState.h" #include "KeyMap.h" #include "InputManager.h" +#include "UnDockedState.h" #include "Console.h" namespace OpenGate{ Modified: trunk/src/KeyMap.h =================================================================== --- trunk/src/KeyMap.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/KeyMap.h 2008-05-18 19:30:59 UTC (rev 900) @@ -22,18 +22,17 @@ #define _OPENGATE_KEYMAP__H #include <map> -// #include "InputManager.h" - #include "UnDockedState.h" +//#include "InputManager.h" +namespace OIS{ + class KeyEvent; +} + namespace OpenGate{ class UnDockedState; class Console; -// namespace OIS{ -// class KeyEvent; -// } - template < class Object, typename returnT, typename Args > class memberBind { public: typedef returnT( Object::*F )( Args ); Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Makefile.am 2008-05-18 19:30:59 UTC (rev 900) @@ -104,9 +104,9 @@ $(ogreopcode_LIBS) opengateclient_CXXFLAGS = \ - $(OGRE_CFLAGS) \ - $(CEGUI_CFLAGS) \ - $(ogreopcode_CFLAGS) + $(OGRE_CFLAGS) \ + $(CEGUI_CFLAGS) \ + $(ogreopcode_CFLAGS) opengateserver_SOURCES = \ opengateserver.cpp \ @@ -126,8 +126,8 @@ opengateserver_LDFLAGS = \ $(ogreopcode_LIBS) -opengateserver_CXXFLAGS = \ - $(ogreopcode_CFLAGS) +# opengateserver_CXXFLAGS = \ +# $(ogreopcode_CFLAGS) # testaimanager_SOURCES = \ # testaimanager.cpp \ Modified: trunk/src/MarketDialog.h =================================================================== --- trunk/src/MarketDialog.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/MarketDialog.h 2008-05-18 19:30:59 UTC (rev 900) @@ -21,10 +21,16 @@ #ifndef _OPENGATE_MARKETDIALOG__H #define _OPENGATE_MARKETDIALOG__H -#include <vector> #include "BaseDialog.h" #include "EntityManager.h" +namespace CEGUI{ + class Listbox; + class EventArgs; +} + +#include <vector> + namespace OpenGate{ /*! Modified: trunk/src/Moveable.cpp =================================================================== --- trunk/src/Moveable.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Moveable.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -20,6 +20,7 @@ #include "Moveable.h" #include "common.h" +#include "LogManager.h" #include <OgreMeshManager.h> Modified: trunk/src/OpcodeWrapper.h =================================================================== --- trunk/src/OpcodeWrapper.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/OpcodeWrapper.h 2008-05-18 19:30:59 UTC (rev 900) @@ -23,6 +23,7 @@ #include <OgreSingleton.h> #include <OgrePrerequisites.h> +// #include <OgreOpcode.h> namespace OgreOpcode{ class CollisionContext; Modified: trunk/src/OpenALSoundManager.h =================================================================== --- trunk/src/OpenALSoundManager.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/OpenALSoundManager.h 2008-05-18 19:30:59 UTC (rev 900) @@ -31,9 +31,6 @@ #include <ogg/ogg.h> #include <vorbis/codec.h> -//#include <vorbis/vorbisenc.h> -//#endif - #include <vorbis/vorbisfile.h> namespace OpenGate { Modified: trunk/src/ResourceManager.cpp =================================================================== --- trunk/src/ResourceManager.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/ResourceManager.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -62,6 +62,20 @@ delete keymap_; } +void ResourceManager::addResourceLocation( const std::string & path, const std::string & group ){ + resourceLocations_[ group ].insert( path ); +} + +std::set < std::string > & ResourceManager::resourceLocations( const std::string & group ) { + if ( resourceLocations_.count( group ) == 0 ){ + throw std::length_error( "ResourceManager::resourceLocations( group ) no group: " + group ); + } + if ( resourceLocations_[ group ].empty() ){ + throw std::length_error( "ResourceManager::resourceLocations( group ) will return an empty set for group " + group ); + } + return resourceLocations_[ group ]; +} + std::string ResourceManager::factionName( int id ) { if ( factionIDs_.count( id ) ){ return factionIDs_[ id ]; @@ -120,11 +134,11 @@ std::string ResourceManager::findFullFileName( const std::string & fileName ){ - Ogre::FileSystemArchive pArch = Ogre::FileSystemArchive( (*resourcePaths_.begin()), "FileSystem" ); + Ogre::FileSystemArchive pArch = Ogre::FileSystemArchive( (*resourceLocations_["General"].begin()), "FileSystem" ); Ogre::StringVectorPtr file = pArch.find( fileName, true, false); if ( (*file).size() > 0 ){ - return (*resourcePaths_.begin() ) + "/" + (*file)[ 0 ] ; + return (*resourceLocations_["General"].begin() ) + "/" + (*file)[ 0 ] ; } // for ( unsigned int i = 0; i < (*file).size(); i ++ ){ @@ -135,13 +149,13 @@ void ResourceManager::load( const std::string & resourceName ){ - Ogre::FileSystemArchive * pArch = new Ogre::FileSystemArchive( (*resourcePaths_.begin()) + "/" + resourceName, "FileSystem" ); + Ogre::FileSystemArchive * pArch = new Ogre::FileSystemArchive( (*resourceLocations_["General"].begin()) + "/" + resourceName, "FileSystem" ); Ogre::StringVectorPtr files = pArch->find( "*.xml", true, false); for ( unsigned int i = 0; i < (*files).size(); i ++ ){ if ( (*files)[ i ].rfind( ".mesh.xml" ) == std::string::npos ){ log_->fout( std::string( "Found ressource: " ) + (*files)[ i ] ); - loadAndCreate( (*resourcePaths_.begin()) + "/" + resourceName + "/" + (*files)[ i ] ); + loadAndCreate( (*resourceLocations_["General"].begin()) + "/" + resourceName + "/" + (*files)[ i ] ); } } Modified: trunk/src/ResourceManager.h =================================================================== --- trunk/src/ResourceManager.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/ResourceManager.h 2008-05-18 19:30:59 UTC (rev 900) @@ -30,8 +30,6 @@ namespace OpenGate{ -enum GunType{UNKNOWN,LASER,MININGLASER,BULLET}; - /*! * \brief This is a global storage for all and everything; * @@ -89,8 +87,12 @@ /*! Find file in resources and returns full name */ std::string findFullFileName( const std::string & fileName ); - std::set < std::string > & resourcePaths() { return resourcePaths_; } - + /*! Return the set of known resource paths, maybee this this can be saver by using ogre resource Manager directly instead of holding our own set. Maybee deprecated.*/ + std::set < std::string > & resourceLocations( const std::string & group ); + + /*! Add path to the opengate resources. Usually set by ogre resource initialisation. Maybee deprecated. */ + void addResourceLocation( const std::string & path, const std::string & group ); + void setMappingCapability( bool mapping ) { mapping_ = mapping; } bool mappingCapability() const { return mapping_; } @@ -112,7 +114,7 @@ std::string languageSuffix_; std::map< int, std::string > factionIDs_; - std::set< std::string > resourcePaths_; + std::map< std::string, std::set< std::string > > resourceLocations_; std::map< std::string, Entity * > stations_; Modified: trunk/src/Sector.cpp =================================================================== --- trunk/src/Sector.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Sector.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -1018,7 +1018,7 @@ void Sector::sendProjectile( const Projectile & projectile ){ MessageBodyShipProjectileFired msg( projectile.parent().childID(), projectile.shotCount(), - projectile.mainNode().getWorldPosition().ptr(), + Ogre::Vector3( projectile.mainNode()->getWorldPosition() ).ptr(), projectile.velocity().ptr(), projectile.gun()->id(), projectile.damage(), projectile.lifeTime() ); network_->send( msg ); Modified: trunk/src/SectorObject.h =================================================================== --- trunk/src/SectorObject.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/SectorObject.h 2008-05-18 19:30:59 UTC (rev 900) @@ -60,7 +60,7 @@ virtual bool update( Ogre::Real elapsedTime ){ return true; } void setShape( const Ogre::String & meshname ); - void setShape( Ogre::MeshPtr & mesh ); + virtual Ogre::Entity * entity(){ return entity_; } void scale( const Ogre::Vector3 & scale ); Modified: trunk/src/SectorObjectMissile.cpp =================================================================== --- trunk/src/SectorObjectMissile.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/SectorObjectMissile.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -21,6 +21,7 @@ #include "SectorObjectMissile.h" #include "OpcodeWrapper.h" #include "Vessel.h" +#include "ResourceManager.h" #include <OgreParticleSystem.h> #include <OgreParticleEmitter.h> Modified: trunk/src/SectorObjectMoveable.cpp =================================================================== --- trunk/src/SectorObjectMoveable.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/SectorObjectMoveable.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -113,7 +113,7 @@ armor_ = maxArmor_; thrust_ = 0; maxThrust_ = 0; - thrustRate_ = 0; + thrustRate_ = 0.0; shieldGlowActive_ = false; shieldGlowTime_ = 0.0; @@ -344,8 +344,9 @@ if ( breakStatus != breakPressed_ ) statusChanged_ = true; if ( breakStatus == true ){ - thrust_ = 0; updateThruster(); - thrustRate_ = 0; + thrust_ = 0; + thrustRate_ = 0.0; + updateThruster(); } breakPressed_ = breakStatus; } @@ -394,7 +395,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/ShipConfigDialog.cpp =================================================================== --- trunk/src/ShipConfigDialog.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/ShipConfigDialog.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -38,6 +38,8 @@ #include <OgreCEGUITexture.h> #include <CEGUIWindow.h> +#include <CEGUIWindowManager.h> +#include <CEGUIImageset.h> #include <CEGUI/elements/CEGUIPushButton.h> Modified: trunk/src/ShipConfigDialog.h =================================================================== --- trunk/src/ShipConfigDialog.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/ShipConfigDialog.h 2008-05-18 19:30:59 UTC (rev 900) @@ -24,9 +24,16 @@ #include "BaseDialog.h" #include "Entity.h" -#include <OgrePrerequisites.h> +// #include <OgrePrerequisites.h> #include <OgreRenderTargetListener.h> +namespace CEGUI{ + class Listbox; + class PushButton; + class EventArgs; + class OgreCEGUITexture; +} + namespace OpenGate{ class Entity; Modified: trunk/src/UnDockedState.cpp =================================================================== --- trunk/src/UnDockedState.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/UnDockedState.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -23,6 +23,7 @@ #include "AiManager.h" #include "AiObject.h" #include "Avatar.h" +#include "GameStateManager.h" #include "Sector.h" #include "networkProtocol.h" #include "networkClient.h" Modified: trunk/src/Vessel.h =================================================================== --- trunk/src/Vessel.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/Vessel.h 2008-05-18 19:30:59 UTC (rev 900) @@ -22,7 +22,6 @@ #define _OPENGATE_VESSEL__H #include "Moveable.h" -#include <OgreMesh.h> #include <map> #include <vector> Modified: trunk/src/commonWithOgre.cpp =================================================================== --- trunk/src/commonWithOgre.cpp 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/commonWithOgre.cpp 2008-05-18 19:30:59 UTC (rev 900) @@ -24,6 +24,8 @@ #include <OgreVector3.h> #include <OgreMovableObject.h> +namespace OpenGate{ + void dumpSceneNodes( std::stringstream & ss, Ogre::Node * n, int level ) { for ( int i = 0; i < level; i++ ) { ss << " "; @@ -52,3 +54,5 @@ dumpSceneNodes( ss, n, 0 ); return ss.str(); } + +} // namespace OpenGate Modified: trunk/src/commonWithOgre.h =================================================================== --- trunk/src/commonWithOgre.h 2008-05-18 19:29:16 UTC (rev 899) +++ trunk/src/commonWithOgre.h 2008-05-18 19:30:59 UTC (rev 900) @@ -52,7 +52,7 @@ /*! For debugging purposes dump scene node tree to a string */ void dumpSceneNodes( std::stringstream & ss, Ogre::Node * n, int level ); -// /*! For debugging purposes dump scene node tr... [truncated message content] |
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. |