Skip to content

Commit

Permalink
Running the client from the DSL transform menu now works again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gohla committed Sep 15, 2011
1 parent 443e26c commit 9a6c2df
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 35 deletions.
3 changes: 3 additions & 0 deletions DSL/DiversiaScript/syntax/data/enum.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions DSL/DiversiaScript/syntax/data/type-func.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down
2 changes: 1 addition & 1 deletion DSL/DiversiaScript/trans/codegen/lua/generate.str
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type-has-function(|prop)> objectName
Expand Down
3 changes: 1 addition & 2 deletions DSL/DiversiaScript/trans/codegen/lua/normalise.str
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [])
])
]
]

Expand Down
11 changes: 10 additions & 1 deletion DSL/DiversiaScript/trans/data/enum.str
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,16 @@ rules
has-builtin-enum-valueName(|param0) = ?MouseMoved(); <?ObjectScriptEvent()> param0
builtin-enum-value(|param0) = ?MouseMoved(); <?ObjectScriptEvent()> param0; !12
builtin-enum-name(|param0) = ?12; <?ObjectScriptEvent()> 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(); <?ObjectScriptEvent()> param0
builtin-enum-value(|param0) = ?Hovered(); <?ObjectScriptEvent()> param0; !15
builtin-enum-name(|param0) = ?15; <?ObjectScriptEvent()> param0; !Hovered()
has-builtin-enum-valueName(|param0) = ?Clicked(); <?ObjectScriptEvent()> param0
builtin-enum-value(|param0) = ?Clicked(); <?ObjectScriptEvent()> param0; !16
builtin-enum-name(|param0) = ?16; <?ObjectScriptEvent()> param0; !Clicked()
has-builtin-enum-valueName(|param0) = ?Dragged(); <?ObjectScriptEvent()> param0
builtin-enum-value(|param0) = ?Dragged(); <?ObjectScriptEvent()> param0; !17
builtin-enum-name(|param0) = ?17; <?ObjectScriptEvent()> 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(); <?MouseButton()> param0
Expand Down
5 changes: 4 additions & 1 deletion DSL/DiversiaScript/trans/data/type-func.str
Original file line number Diff line number Diff line change
Expand Up @@ -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() -> []

Expand Down
4 changes: 2 additions & 2 deletions DSL/DiversiaScript/trans/diversiascript.str
Original file line number Diff line number Diff line change
Expand Up @@ -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 := <abspath> <dirname> path
where dir := <dirname> <abspath> <dirname> path
where clientDir := $[[<plugin-path>]/client/]
where
editor-init;
(<lua-tofiles(|path)> <to-lua> <analyse-all-merge(|path)> ast <+ fatal-err(|$[Lua code generation failed.]));
(<chdir> clientDir <+ fatal-err(|$[Could not cd into [clientDir].]));
(<call> ($[[clientDir]Diversia-DefaultClient-DbgInfo.exe], ["-o", "-m", $["[dir]"], "-s", "gen/GameMode.lua"]) <+
(<call> ($[[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.
Expand Down
2 changes: 1 addition & 1 deletion DSL/DiversiaScript/trans/rename.str
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<rename-all-defs> pluginDefs => pluginDefs';
Expand Down
27 changes: 16 additions & 11 deletions DefaultClient/source/DefaultClient/ClientApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ You may contact the author of Diversia by e-mail at: [email protected]

#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"
Expand All @@ -32,6 +31,7 @@ You may contact the author of Diversia by e-mail at: [email protected]
#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"
Expand All @@ -46,6 +46,7 @@ You may contact the author of Diversia by e-mail at: [email protected]
#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"
Expand All @@ -62,13 +63,13 @@ You may contact the author of Diversia by e-mail at: [email protected]
#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"
Expand Down Expand Up @@ -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<PermissionManager, ClientPluginManager>::registerFactory();
camp::classByType<PermissionManager>();
PluginManager::addAutoCreatePlugin<PermissionManager>();
TemplatePluginFactory<ResourceManager, ClientPluginManager>::registerFactory();
camp::classByType<ResourceManager>();
PluginManager::addAutoCreatePlugin<ResourceManager>();
TemplatePluginFactory<ClientObjectTemplateManager, ClientPluginManager>::registerFactory();
camp::classByType<ClientObjectTemplateManager>();
PluginManager::addAutoCreatePlugin<ClientObjectTemplateManager>();
ObjectManagerFactory<ClientObjectManager, ClientPluginManager>::registerFactory( mUpdateSignal, mLateUpdateSignal );
camp::classByType<ClientObjectManager>();
PluginManager::addAutoCreatePlugin<ClientObjectManager>();
TemplatePluginFactory<ServerNeighborsPlugin, ClientPluginManager>::registerFactory();
camp::classByType<ServerNeighborsPlugin>();
TemplatePluginFactory<SkyPlugin, ClientPluginManager>::registerFactory();
Expand All @@ -212,10 +217,13 @@ void ClientApplication::init( int argc, char* argv[] )
TemplatePluginFactory<LuaPlugin, ClientPluginManager>::registerFactory();
camp::classByType<LuaPlugin>();
PluginManager::addAutoCreatePlugin<LuaPlugin>();
TemplatePluginFactory<LevelManager, ClientPluginManager>::registerFactory();
camp::classByType<LevelManager>();

// Override the default game mode.
TemplatePluginFactory<GameModePlugin, ClientPluginManager>::registerFactory();
GameModePlugin::setDefaultSlot( sigc::ptr_fun( &DefaultGameMode::createGameMode ) );
PluginManager::addAutoCreatePlugin<GameModePlugin>();

// Initialize graphics
mGraphicsManager.reset( new GraphicsManager() );
Expand Down Expand Up @@ -263,21 +271,18 @@ void ClientApplication::init( int argc, char* argv[] )
mGridManager->createOfflineServer();
mStateMachine->pushState( new LoadingState() );
ClientPluginManager& pluginManager = mGridManager->getActiveServer().getPluginManager();
pluginManager.createPlugin<PermissionManager>();
pluginManager.createPlugin<ClientObjectTemplateManager>();
pluginManager.createPlugin<ClientObjectManager>();

if( vm.count( "media" ) )
{
ResourceManager& resourceManager = pluginManager.createPlugin<ResourceManager>();
ResourceManager& resourceManager = pluginManager.getPlugin<ResourceManager>();
resourceManager.setGroup( mAddMedia.leaf() );
resourceManager.setResourceLocation( mAddMedia.string() );
}

if( vm.count( "offline-file" ) )
{
SerializationFile* file = new XMLSerializationFile(
mGraphicsManager->getRootResourceLocation() / mOfflineFile, "NoSerialization",
mAddMedia / mOfflineFile, "NoSerialization",
false );
file->load();
file->deserialize( pluginManager, false );
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion Framework/OgreClient/Camp/CampBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions Framework/OgreClient/GlobalsBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>* GlobalsBase::mEarlyUpdateSignal = 0;
sigc::signal<void, Real>* GlobalsBase::mEarlyFrameSignal = 0;
Expand Down
1 change: 1 addition & 0 deletions Framework/OgreClient/GlobalsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>* mEarlyUpdateSignal;
static sigc::signal<void, Real>* mEarlyFrameSignal;
Expand Down
31 changes: 19 additions & 12 deletions Framework/OgreClient/Graphics/GraphicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( "", "", "" );
Expand Down
3 changes: 2 additions & 1 deletion Framework/OgreClient/Graphics/GraphicsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
18 changes: 18 additions & 0 deletions Framework/OgreClient/Level/LevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<LuaPlugin>().get().object(
"LevelManager" ) = this;
}
catch( Exception e )
{
LCLOGE << "Could not add LevelManager object to lua: " << e.what();
}
}

LevelManager::~LevelManager()
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Framework/Shared/Lua/LuaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand Down
2 changes: 1 addition & 1 deletion Framework/Util/Serialization/XMLSerializationFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
1 change: 1 addition & 0 deletions QtOgreEditor/source/EditorApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a6c2df

Please sign in to comment.