From 9a6c2dfcb9a6ae9ec464cd67a5951de1b3df4623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabri=C3=ABl=20Konat?= Date: Thu, 15 Sep 2011 14:29:28 +0200 Subject: [PATCH] Running the client from the DSL transform menu now works again. --- DSL/DiversiaScript/syntax/data/enum.sdf | 3 ++ DSL/DiversiaScript/syntax/data/type-func.sdf | 2 ++ .../trans/codegen/lua/generate.str | 2 +- .../trans/codegen/lua/normalise.str | 3 +- DSL/DiversiaScript/trans/data/enum.str | 11 ++++++- DSL/DiversiaScript/trans/data/type-func.str | 5 ++- DSL/DiversiaScript/trans/diversiascript.str | 4 +-- DSL/DiversiaScript/trans/rename.str | 2 +- .../DefaultClient/ClientApplication.cpp | 27 +++++++++------- Framework/OgreClient/Camp/CampBindings.cpp | 3 +- Framework/OgreClient/GlobalsBase.cpp | 1 + Framework/OgreClient/GlobalsBase.h | 1 + .../OgreClient/Graphics/GraphicsManager.cpp | 31 ++++++++++++------- .../OgreClient/Graphics/GraphicsManager.h | 3 +- Framework/OgreClient/Level/LevelManager.cpp | 18 +++++++++++ Framework/Shared/Lua/LuaManager.cpp | 2 +- .../Serialization/XMLSerializationFile.cpp | 2 +- QtOgreEditor/source/EditorApplication.cpp | 1 + 18 files changed, 86 insertions(+), 35 deletions(-) diff --git a/DSL/DiversiaScript/syntax/data/enum.sdf b/DSL/DiversiaScript/syntax/data/enum.sdf index 98d6919..d182d36 100644 --- a/DSL/DiversiaScript/syntax/data/enum.sdf +++ b/DSL/DiversiaScript/syntax/data/enum.sdf @@ -280,6 +280,9 @@ exports "MousePressed" -> ObjectScriptEventValue {cons("MousePressed")} "MouseReleased" -> ObjectScriptEventValue {cons("MouseReleased")} "MouseMoved" -> ObjectScriptEventValue {cons("MouseMoved")} + "Hovered" -> ObjectScriptEventValue {cons("Hovered")} + "Clicked" -> ObjectScriptEventValue {cons("Clicked")} + "Dragged" -> ObjectScriptEventValue {cons("Dragged")} "MouseButton" -> MouseButtonEnumType {cons("MouseButton")} MouseButtonEnumType -> EnumType diff --git a/DSL/DiversiaScript/syntax/data/type-func.sdf b/DSL/DiversiaScript/syntax/data/type-func.sdf index 31eb00b..b76962c 100644 --- a/DSL/DiversiaScript/syntax/data/type-func.sdf +++ b/DSL/DiversiaScript/syntax/data/type-func.sdf @@ -87,6 +87,8 @@ exports "IsButtonDown" -> BuiltinFunction {cons("IsButtonDown")} "Clear" -> BuiltinFunction {cons("Clear")} + "LoadLevel" -> BuiltinFunction {cons("LoadLevel")} + "Reload_script" -> BuiltinFunction {cons("Reload_script")} "Destroy_script" -> BuiltinFunction {cons("Destroy_script")} "Create_script" -> BuiltinFunction {cons("Create_script")} diff --git a/DSL/DiversiaScript/trans/codegen/lua/generate.str b/DSL/DiversiaScript/trans/codegen/lua/generate.str index 087376e..8d37691 100644 --- a/DSL/DiversiaScript/trans/codegen/lua/generate.str +++ b/DSL/DiversiaScript/trans/codegen/lua/generate.str @@ -258,7 +258,7 @@ rules // Expressions // References to-lua: VarRef(_{name}) -> VarRef(name) to-lua: ComponentRef(name) -> VarRef(name) - to-lua: PluginRef(_{name}) -> VarRef(name) + to-lua: PluginRef(name{_}) -> VarRef(name) to-lua: ObjectRef(_) -> VarRef("Object") to-lua: PropRef(prop, objectName) -> Access(VarRef("Object"), prop) where objectName diff --git a/DSL/DiversiaScript/trans/codegen/lua/normalise.str b/DSL/DiversiaScript/trans/codegen/lua/normalise.str index 630c777..da4f6f7 100644 --- a/DSL/DiversiaScript/trans/codegen/lua/normalise.str +++ b/DSL/DiversiaScript/trans/codegen/lua/normalise.str @@ -19,8 +19,7 @@ rules // Normalisation rules that add plugins and components to objects to make PluginDef("ResourceManager", ResourceManager(), [ PluginProp(ResourceManager(), Type(), EnumValueRef(ResourceLocationType(), FileSystem())), PluginProp(ResourceManager(), ResourceLocation(), StrConst(mediaDir)) - ]), - PluginDef("LevelManager", LevelManager(), []) + ]) ] ] diff --git a/DSL/DiversiaScript/trans/data/enum.str b/DSL/DiversiaScript/trans/data/enum.str index 01e9225..ebd1dd2 100644 --- a/DSL/DiversiaScript/trans/data/enum.str +++ b/DSL/DiversiaScript/trans/data/enum.str @@ -723,7 +723,16 @@ rules has-builtin-enum-valueName(|param0) = ?MouseMoved(); param0 builtin-enum-value(|param0) = ?MouseMoved(); param0; !12 builtin-enum-name(|param0) = ?12; param0; !MouseMoved() - builtin-enum-values: ObjectScriptEvent() -> [(EarlyUpdate(), 0), (Update(), 1), (LateUpdate(), 2), (EarlyFrame(), 3), (Frame(), 4), (LateFrame(), 5), (ComponentChange(), 6), (TransformChange(), 7), (AreaChange(), 8), (CollisionWith(), 9), (KeyPressed(), 13), (KeyReleased(), 14), (MousePressed(), 10), (MouseReleased(), 11), (MouseMoved(), 12)] + has-builtin-enum-valueName(|param0) = ?Hovered(); param0 + builtin-enum-value(|param0) = ?Hovered(); param0; !15 + builtin-enum-name(|param0) = ?15; param0; !Hovered() + has-builtin-enum-valueName(|param0) = ?Clicked(); param0 + builtin-enum-value(|param0) = ?Clicked(); param0; !16 + builtin-enum-name(|param0) = ?16; param0; !Clicked() + has-builtin-enum-valueName(|param0) = ?Dragged(); param0 + builtin-enum-value(|param0) = ?Dragged(); param0; !17 + builtin-enum-name(|param0) = ?17; param0; !Dragged() + builtin-enum-values: ObjectScriptEvent() -> [(EarlyUpdate(), 0), (Update(), 1), (LateUpdate(), 2), (EarlyFrame(), 3), (Frame(), 4), (LateFrame(), 5), (ComponentChange(), 6), (TransformChange(), 7), (AreaChange(), 8), (CollisionWith(), 9), (KeyPressed(), 13), (KeyReleased(), 14), (MousePressed(), 10), (MouseReleased(), 11), (MouseMoved(), 12), (Hovered(), 15), (Clicked(), 16), (Dragged(), 17)] is-builtin-enum = ?MouseButton() has-builtin-enum-valueName(|param0) = ?Left(); param0 diff --git a/DSL/DiversiaScript/trans/data/type-func.str b/DSL/DiversiaScript/trans/data/type-func.str index 4488249..eaee94f 100644 --- a/DSL/DiversiaScript/trans/data/type-func.str +++ b/DSL/DiversiaScript/trans/data/type-func.str @@ -270,7 +270,10 @@ rules builtin-type-func-params: (KeyboardState(), Clear()) -> [] builtin-type-funcs: KeyboardState() -> [Function(IsButtonDown(), BoolType(), [KeyboardButton()]), Function(Clear(), VoidType(), [])] - builtin-type-funcs: LevelManager() -> [] + has-builtin-type-func = ?(LevelManager(), LoadLevel()) + builtin-type-func-return: (LevelManager(), LoadLevel()) -> VoidType() + builtin-type-func-params: (LevelManager(), LoadLevel()) -> [StringType()] + builtin-type-funcs: LevelManager() -> [Function(LoadLevel(), VoidType(), [StringType()])] builtin-type-funcs: Light() -> [] diff --git a/DSL/DiversiaScript/trans/diversiascript.str b/DSL/DiversiaScript/trans/diversiascript.str index c5f4ad6..c8adc85 100644 --- a/DSL/DiversiaScript/trans/diversiascript.str +++ b/DSL/DiversiaScript/trans/diversiascript.str @@ -56,13 +56,13 @@ rules // Main editor interface (defined by editor/DiversiaScript-Builders and -R // Runs the DefaultClient with lua scripts generated from current AST. run: (selected, position, ast, path, project-path) -> None() - where dir := path + where dir := path where clientDir := $[[]/client/] where editor-init; ( ast <+ fatal-err(|$[Lua code generation failed.])); ( clientDir <+ fatal-err(|$[Could not cd into [clientDir].])); - ( ($[[clientDir]Diversia-DefaultClient-DbgInfo.exe], ["-o", "-m", $["[dir]"], "-s", "gen/GameMode.lua"]) <+ + ( ($[[clientDir]Diversia-DefaultClient-DbgInfo.exe], ["-o", "-m", $["[dir]"], "-f", "Game.xml"]) <+ fatal-err(|$[Could not start the client or the cliented terminated abnormally.])) // Transforms analysed AST to Lua. diff --git a/DSL/DiversiaScript/trans/rename.str b/DSL/DiversiaScript/trans/rename.str index f2da78d..853adb4 100644 --- a/DSL/DiversiaScript/trans/rename.str +++ b/DSL/DiversiaScript/trans/rename.str @@ -17,7 +17,7 @@ strategies rules // Definitions rename-def : - Start(imports, pluginDefs, objectDefs, eventDefs) -> Start(imports, pluginDefs', objectDefs', eventDefs'') + Start(imports, pluginDefs, objectDefs, eventDefs) -> Start(imports, pluginDefs, objectDefs', eventDefs'') where new-scope( pluginDefs => pluginDefs'; diff --git a/DefaultClient/source/DefaultClient/ClientApplication.cpp b/DefaultClient/source/DefaultClient/ClientApplication.cpp index 10c5b38..454a36f 100644 --- a/DefaultClient/source/DefaultClient/ClientApplication.cpp +++ b/DefaultClient/source/DefaultClient/ClientApplication.cpp @@ -22,7 +22,6 @@ You may contact the author of Diversia by e-mail at: equabyte@sonologic.nl #include "DefaultClient/Platform/StableHeaders.h" -#include "Client/Plugin/ClientPluginManager.h" #include "Client/Communication/GridManager.h" #include "Client/Communication/Server.h" #include "Client/Communication/ServerAbstract.h" @@ -32,6 +31,7 @@ You may contact the author of Diversia by e-mail at: equabyte@sonologic.nl #include "Client/Object/ClientObjectManager.h" #include "Client/Object/ClientObjectTemplateManager.h" #include "Client/Permission/PermissionManager.h" +#include "Client/Plugin/ClientPluginManager.h" #include "DefaultClient/ClientApplication.h" #include "DefaultClient/GUI/GUIManager.h" #include "DefaultClient/GUI/LoginGUI.h" @@ -46,6 +46,7 @@ You may contact the author of Diversia by e-mail at: equabyte@sonologic.nl #include "OgreClient/Graphics/SceneManagerPlugin.h" #include "OgreClient/Graphics/SkyPlugin.h" #include "OgreClient/Graphics/Terrain.h" +#include "OgreClient/Level/LevelManager.h" #include "OgreClient/Object/Animation.h" #include "OgreClient/Object/AreaTrigger.h" #include "OgreClient/Object/Audio.h" @@ -62,13 +63,13 @@ You may contact the author of Diversia by e-mail at: equabyte@sonologic.nl #include "OgreClient/Object/Text.h" #include "OgreClient/Physics/PhysicsManager.h" #include "OgreClient/Resource/ResourceManager.h" -#include "Shared/Plugin/PluginManager.h" -#include "Shared/Plugin/Factories/ObjectManagerFactory.h" -#include "Shared/Plugin/Factories/TemplatePluginFactory.h" #include "Shared/Communication/GridPosition.h" #include "Shared/Communication/ServerInfo.h" #include "Shared/Crash/CrashReporter.h" #include "Shared/Object/TemplateComponentFactory.h" +#include "Shared/Plugin/Factories/ObjectManagerFactory.h" +#include "Shared/Plugin/Factories/TemplatePluginFactory.h" +#include "Shared/Plugin/PluginManager.h" #include "State/LoadingState.h" #include "Util/Config/ConfigManager.h" #include "Util/Serialization/XMLSerializationFile.h" @@ -195,12 +196,16 @@ void ClientApplication::init( int argc, char* argv[] ) // Add plugin factories, get camp class to ensure that the class is registered. TemplatePluginFactory::registerFactory(); camp::classByType(); + PluginManager::addAutoCreatePlugin(); TemplatePluginFactory::registerFactory(); camp::classByType(); + PluginManager::addAutoCreatePlugin(); TemplatePluginFactory::registerFactory(); camp::classByType(); + PluginManager::addAutoCreatePlugin(); ObjectManagerFactory::registerFactory( mUpdateSignal, mLateUpdateSignal ); camp::classByType(); + PluginManager::addAutoCreatePlugin(); TemplatePluginFactory::registerFactory(); camp::classByType(); TemplatePluginFactory::registerFactory(); @@ -212,10 +217,13 @@ void ClientApplication::init( int argc, char* argv[] ) TemplatePluginFactory::registerFactory(); camp::classByType(); PluginManager::addAutoCreatePlugin(); + TemplatePluginFactory::registerFactory(); + camp::classByType(); // Override the default game mode. TemplatePluginFactory::registerFactory(); GameModePlugin::setDefaultSlot( sigc::ptr_fun( &DefaultGameMode::createGameMode ) ); + PluginManager::addAutoCreatePlugin(); // Initialize graphics mGraphicsManager.reset( new GraphicsManager() ); @@ -263,13 +271,10 @@ void ClientApplication::init( int argc, char* argv[] ) mGridManager->createOfflineServer(); mStateMachine->pushState( new LoadingState() ); ClientPluginManager& pluginManager = mGridManager->getActiveServer().getPluginManager(); - pluginManager.createPlugin(); - pluginManager.createPlugin(); - pluginManager.createPlugin(); if( vm.count( "media" ) ) { - ResourceManager& resourceManager = pluginManager.createPlugin(); + ResourceManager& resourceManager = pluginManager.getPlugin(); resourceManager.setGroup( mAddMedia.leaf() ); resourceManager.setResourceLocation( mAddMedia.string() ); } @@ -277,7 +282,7 @@ void ClientApplication::init( int argc, char* argv[] ) if( vm.count( "offline-file" ) ) { SerializationFile* file = new XMLSerializationFile( - mGraphicsManager->getRootResourceLocation() / mOfflineFile, "NoSerialization", + mAddMedia / mOfflineFile, "NoSerialization", false ); file->load(); file->deserialize( pluginManager, false ); @@ -300,12 +305,12 @@ void ClientApplication::init( int argc, char* argv[] ) } } } - catch( const Exception& e ) + /*catch( const Exception& e ) { LOGC << e.what(); ClientApplication::exit(); throw e; - } + }*/ catch( const Ogre::Exception& e ) { LOGC << e.what(); diff --git a/Framework/OgreClient/Camp/CampBindings.cpp b/Framework/OgreClient/Camp/CampBindings.cpp index 7ca8673..c6a1878 100644 --- a/Framework/OgreClient/Camp/CampBindings.cpp +++ b/Framework/OgreClient/Camp/CampBindings.cpp @@ -1351,8 +1351,9 @@ void CampBindings::bindLevelManager() // Properties (read-only) // Properties (read/write) .property( "DefaultLevel", &LevelManager::mDefaultLevel ) - .property( "LoadedPlugins", &LevelManager::mLoadedPlugins ); + .property( "LoadedPlugins", &LevelManager::mLoadedPlugins ) // Functions + .function( "LoadLevel", &LevelManager::loadLevel ); // Static functions // Operators } diff --git a/Framework/OgreClient/GlobalsBase.cpp b/Framework/OgreClient/GlobalsBase.cpp index 4d11448..21ffc59 100644 --- a/Framework/OgreClient/GlobalsBase.cpp +++ b/Framework/OgreClient/GlobalsBase.cpp @@ -46,6 +46,7 @@ InputManager* GlobalsBase::mInput = 0; ObjectSelection* GlobalsBase::mSelection = 0; UndoStack* GlobalsBase::mUndoStack = 0; bool GlobalsBase::mOffline = false; +bool GlobalsBase::mEditor = false; sigc::signal* GlobalsBase::mEarlyUpdateSignal = 0; sigc::signal* GlobalsBase::mEarlyFrameSignal = 0; diff --git a/Framework/OgreClient/GlobalsBase.h b/Framework/OgreClient/GlobalsBase.h index 675010c..ddbdfbc 100644 --- a/Framework/OgreClient/GlobalsBase.h +++ b/Framework/OgreClient/GlobalsBase.h @@ -48,6 +48,7 @@ class /*DIVERSIA_OGRECLIENT_API*/ GlobalsBase /*: public boost::noncopyable*/ static ObjectSelection* mSelection; static UndoStack* mUndoStack; static bool mOffline; + static bool mEditor; static sigc::signal* mEarlyUpdateSignal; static sigc::signal* mEarlyFrameSignal; diff --git a/Framework/OgreClient/Graphics/GraphicsManager.cpp b/Framework/OgreClient/Graphics/GraphicsManager.cpp index 4de71da..e78379d 100644 --- a/Framework/OgreClient/Graphics/GraphicsManager.cpp +++ b/Framework/OgreClient/Graphics/GraphicsManager.cpp @@ -100,23 +100,30 @@ GraphicsManager::~GraphicsManager() } void GraphicsManager::init( unsigned int width /*= 0*/, unsigned int height /*= 0*/, - const String& rWidgetHandle /*= ""*/ ) + const String& rWidgetHandle /*= ""*/, const String& rRootResourceLocation /*= ""*/ ) { // Root resource location - if( boost::filesystem::exists( "media" ) ) + if( rRootResourceLocation.empty() ) { - mRootResourceLocation = "media"; - } - else if( boost::filesystem::exists( "../../media" ) ) - { - mRootResourceLocation = "../../media"; + if( boost::filesystem::exists( "media" ) ) + { + mRootResourceLocation = "media"; + } + else if( boost::filesystem::exists( "../../media" ) ) + { + mRootResourceLocation = "../../media"; + } + else + { + DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, + "Media directory cannot be found at 'media' or '../../media', please get the media \ + directory or set the correct directory in config.xml under 'RootResourceLocation'.", + "GraphicsManager::init" ); + } } - else + else { - DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, - "Media directory cannot be found at 'media' or '../../media', please get the media \ -directory or set the correct directory in config.xml under 'RootResourceLocation'.", - "GraphicsManager::init" ); + mRootResourceLocation = rRootResourceLocation; } mRoot = new Ogre::Root( "", "", "" ); diff --git a/Framework/OgreClient/Graphics/GraphicsManager.h b/Framework/OgreClient/Graphics/GraphicsManager.h index 91e4553..9d23d11 100644 --- a/Framework/OgreClient/Graphics/GraphicsManager.h +++ b/Framework/OgreClient/Graphics/GraphicsManager.h @@ -93,7 +93,8 @@ class DIVERSIA_OGRECLIENT_API GraphicsManager : public Ogre::WindowEventListener /** Initialises the graphics. **/ - void init( unsigned int width = 0, unsigned int height = 0, const String& rWidgetHandle = "" ); + void init( unsigned int width = 0, unsigned int height = 0, const String& rWidgetHandle = "", + const String& rRootResourceLocation = "" ); /** Adds a resource location to the settings. Doesn't add it to Ogre! diff --git a/Framework/OgreClient/Level/LevelManager.cpp b/Framework/OgreClient/Level/LevelManager.cpp index e927fe6..dd3d280 100644 --- a/Framework/OgreClient/Level/LevelManager.cpp +++ b/Framework/OgreClient/Level/LevelManager.cpp @@ -8,6 +8,7 @@ This file is part of Diversia engine #include "OgreClient/Platform/StableHeaders.h" +#include "Client/Lua/LuaPlugin.h" #include "Client/Plugin/ClientPluginManager.h" #include "OgreClient/Level/LevelManager.h" #include "OgreClient/Resource/ResourceManager.h" @@ -27,6 +28,16 @@ LevelManager::LevelManager( Mode mode, PluginState state, ClientPluginManager& r { PropertySynchronization::storeUserObject(); Plugin::getPluginManager().connect( sigc::mem_fun( this, &LevelManager::pluginChange ) ); + + try + { + Plugin::getPluginManager().getPlugin().get().object( + "LevelManager" ) = this; + } + catch( Exception e ) + { + LCLOGE << "Could not add LevelManager object to lua: " << e.what(); + } } LevelManager::~LevelManager() @@ -43,6 +54,11 @@ void LevelManager::load() mLoadedPlugins.insert( i->first ); } + // Load default level in the next frame. + if( !mDefaultLevel.empty() && !GlobalsBase::mEditor ) + DelayedCall::create( sigc::bind( sigc::mem_fun( this, &LevelManager::loadLevel ), + mDefaultLevel ), 0 ); + // TODO: Implement real loading completed signal? ClientPlugin::mLoadingCompletedSignal( *this ); } @@ -99,6 +115,8 @@ void LevelManager::loadLevel( const Path& rFile ) // Load all plugins again with changed configuration ClientPlugin::getClientPluginManager().loadAll(); + + if( !GlobalsBase::mEditor ) ClientPlugin::getClientPluginManager().setState( PLAY ); } Ogre::StringVectorPtr LevelManager::list() diff --git a/Framework/Shared/Lua/LuaManager.cpp b/Framework/Shared/Lua/LuaManager.cpp index 30f3350..2372397 100644 --- a/Framework/Shared/Lua/LuaManager.cpp +++ b/Framework/Shared/Lua/LuaManager.cpp @@ -62,7 +62,7 @@ LuaManager::LuaManager(): "Vector2", "Vector3", "Vector4", "Quaternion", "Matrix3", "Matrix4", "Colour", "Radian", "Degree", "Angle", - "Sky", "ObjectManager", "Application", + "Sky", "ObjectManager", "LevelManager", "Application", "pairs", "ipairs", "print", "type", "tostring" ); diff --git a/Framework/Util/Serialization/XMLSerializationFile.cpp b/Framework/Util/Serialization/XMLSerializationFile.cpp index 40870ce..cc32293 100644 --- a/Framework/Util/Serialization/XMLSerializationFile.cpp +++ b/Framework/Util/Serialization/XMLSerializationFile.cpp @@ -79,7 +79,7 @@ void XMLSerializationFile::deserialize( const camp::UserObject& rObject, const camp::Value& tag = mTags.count() ? mTags[0] : camp::Value::nothing; if( node ) camp::xml::deserialize( rObject, node, tag, mInclude, throwExceptions ); - else + else if( throwExceptions ) DIVERSIA_EXCEPT( Exception::ERR_ITEM_NOT_FOUND, "No configuration found for object " + rObject.getClass().name(), "XMLSerializationFile::deserialize" ); diff --git a/QtOgreEditor/source/EditorApplication.cpp b/QtOgreEditor/source/EditorApplication.cpp index 3eb2695..6033d41 100644 --- a/QtOgreEditor/source/EditorApplication.cpp +++ b/QtOgreEditor/source/EditorApplication.cpp @@ -72,6 +72,7 @@ EditorApplication::EditorApplication( int argc, char* argv[] ): QResource::registerResource( "MainWindow.rcc" ); } + EditorGlobals::mEditor = true; EditorGlobals::mApp = this; EditorGlobals::mEarlyUpdateSignal = &mEarlyUpdateSignal; EditorGlobals::mEarlyFrameSignal = &mEarlyFrameSignal;