Skip to content

Commit

Permalink
Changed lua code generation so that it gets a child object instead of…
Browse files Browse the repository at this point in the history
… creating one, since this is now done by the engine using the XML code generation.
  • Loading branch information
Gohla committed Jul 20, 2011
1 parent dc6694e commit 87e1123
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 21 deletions.
9 changes: 8 additions & 1 deletion DSL/DiversiaScript/trans/codegen/lua/generate.str
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,14 @@ rules // Statements
to-lua: Expression(n@ObjectNew(ObjectRef(name), _)) -> <new-object-to-lua(|$[__[<newname> name]])> n
to-lua: VarDef(_, _{varName}, _, n@ObjectNew(_, _)) -> <new-object-to-lua(|varName)> n
to-lua: PropDef(_, varName, _, n@ObjectNew(_, _)) -> <new-object-to-lua(|varName)> n
to-lua: Assign(VarRef(_{varName}), n@ObjectNew(_, _)) -> <new-object-to-lua(|varName)> n
to-lua: Assign(VarRef(_{varName}), n@ObjectNew(_, _)) -> <new-object-to-lua(|varName)> n
to-lua: PropDef(_, objectName, _, ObjectGet(ObjectRef(name))) -> [
Assignment([VarRef(objectName)], [Call(VarRef("Object"), "ChildObjectByDisplayName", Args([String(name)]))]),
Assignment([VarRef(luaScriptName)], [Call(VarRef(name), "GetComponent", Args([String("LuaObjectScript")]))]),
Call(VarRef(luaScriptName), "CreateEnv", Args([])),
Call(VarRef(luaScriptName), "ReplaceVarWithThisEnv", Args([Access(VarRef("Script"), "ClientEnvironmentName"), String(objectName)]))
]
where luaScriptName := $[[objectName]__LuaObjectScript]
to-lua: StateChange(StateRef(name)) -> [exitCall, change, enterCall]
where exitCall := Call(TableVarRef(VarRef("_G"), Concat(String("StateExit_"), <lua-stateref>)), Args([]))
where change := Assignment([<lua-stateref>], [String(name)])
Expand Down
4 changes: 2 additions & 2 deletions DSL/DiversiaScript/trans/desugar.str
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ rules // Child object
where
<conc> (<map(object-to-var)> objectDefs, varDefs) => varDefs'
object-to-var: ObjectDef(name, propAssigns, propDefs, componentDefs, objectDefs , varDefs, defaultStateDef, stateDefs, eventDefs) ->
PropDef(name, CustomType(name), ObjectNew(ObjectRef(name), [BuiltinObjectProp(Parent(), This())]))
PropDef(name, CustomType(name), ObjectGet(ObjectRef(name)))

object-to-var: ExternalObjectDef(name) ->
PropDef(name, CustomType(name), ObjectNew(ObjectRef(name), [BuiltinObjectProp(Parent(), This())]))
PropDef(name, CustomType(name), ObjectGet(ObjectRef(name)))

/*
// TODO need to following type rules to do type inf.
Expand Down
1 change: 1 addition & 0 deletions DSL/DiversiaScript/trans/projection/type.str
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ rules // Expressions
type-of: ObjectBuiltinCall(objectProp, func, _) -> <get-function-type(|func)> type
where type := <get-property-type(|objectProp)> ClientObject()
type-of: ObjectNew(objectRef, _) -> <type-of> objectRef
type-of: ObjectGet(objectRef) -> <type-of> objectRef
type-of: ObjectRef(name) -> <type-of> <get-object> name
type-of: ComponentRef(name) -> <type-of> <get-component> name
type-of: PluginRef(name) -> <type-of> <get-plugin> name
Expand Down
7 changes: 5 additions & 2 deletions DSL/DiversiaScript/trans/signatures.str
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ signature constructors // Structure

StateDef: Id * List(ObjectProp) * List(ComponentDef) * List(VarDef) * List(EventDef) -> StateDef
DefaultStateDef: Id * List(ObjectProp) * List(ComponentDef) * List(VarDef) * List(EventDef) -> StateDef

signature constructors // Object get instruction

ObjectGet: ObjectRef -> ObjectGet

signature constructors // Types

//EnumType: Id -> Type

NullType: Type

signature constructors // Variables & properties
Expand Down
4 changes: 3 additions & 1 deletion Framework/Client/Camp/CampBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ void CampBindings::bindClientObjectTemplateManager()
camp::Class::declare<ClientObjectTemplateManager>( "ClientObjectTemplateManager" )
.tag( "NoLevelSerialization", true )
.base<ObjectTemplateManager>()
.base<ClientPlugin>();
.base<ClientPlugin>()
// Constructors
// Properties (read-only)
// Properties (read/write)
// Functions
.function( "CreateLocalObject", boost::function<Object&(ClientObjectTemplateManager&, const String&, const String&)>( boost::bind( &ClientObjectTemplateManager::createObject, _1, _2, _3, LOCAL ) ) )
.function( "CreateRemoteObject", boost::function<Object&(ClientObjectTemplateManager&, const String&, const String&)>( boost::bind( &ClientObjectTemplateManager::createObject, _1, _2, _3, REMOTE ) ) );
// Static functions
// Operators
}
Expand Down
8 changes: 8 additions & 0 deletions Framework/Client/Object/ClientObjectTemplateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ THE SOFTWARE.

#include "Client/Plugin/ClientPluginManager.h"
#include "Client/Lua/LuaPlugin.h"
#include "Client/Object/ClientObjectManager.h"
#include "Client/Object/ClientObjectTemplate.h"
#include "Client/Object/ClientObjectTemplateManager.h"
#include "Client/Permission/PermissionManager.h"
Expand Down Expand Up @@ -64,6 +65,13 @@ ClientObjectTemplateManager::~ClientObjectTemplateManager()

}

Object& ClientObjectTemplateManager::createObject( const String& rTemplateName,
const String& rObjectName, NetworkingType type )
{
return ObjectTemplateManager::getObjectTemplate( rTemplateName ).createObject(
Plugin::getPluginManager().getPlugin<ClientObjectManager>(), rObjectName, type );
}

void ClientObjectTemplateManager::load()
{
// TODO: Implement real loading completed signal
Expand Down
12 changes: 12 additions & 0 deletions Framework/Client/Object/ClientObjectTemplateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class DIVERSIA_CLIENT_API ClientObjectTemplateManager : public ObjectTemplateMan
**/
inline String getTypeName() const { return PLUGINNAME_OBJECTTEMPLATEMANAGER; }
static inline String getTypeNameStatic() { return PLUGINNAME_OBJECTTEMPLATEMANAGER; }

/**
Creates an object with the parameters and component templates from given object template name.
@param rTemplateName The name of the object template to instantiate.
@param rObjectName The name of the object.
@param type If the object should be a remote or local object.
@return The created object.
**/
Object& createObject( const String& rTemplateName, const String& rObjectName,
NetworkingType type );

private:
friend class TemplatePluginFactory<ClientObjectTemplateManager, ClientPluginManager>;
Expand Down
1 change: 1 addition & 0 deletions Framework/Object/Camp/CampBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void CampBindings::bindObject()
.function( "IsCreatedBy", &Object::isCreatedBy )
.function( "IsCreatedBySource", &Object::isCreatedBySource )
.function( "CreateChildObject", &Object::createChildObject )
.function( "ChildObjectByDisplayName", &Object::childObjectByDisplayName )
.function( "CreateComponent", boost::function<Component&(Object&, ComponentType, const String&, bool)>( boost::bind( &Object::createComponent, _1, _2, _3, _4, RakNet::RakNetGUID( 0 ) ) ) )
.function( "CreateComponentByHandle", (Component&(Object::*)(const ComponentHandle&))&Object::createComponent )
.function( "GetComponent", (Component&(Object::*)(const String&) const)&Object::getComponent )
Expand Down
26 changes: 20 additions & 6 deletions Framework/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ void Object::setNetworkingType( NetworkingType type, bool redirectToChilds /*=fa
// type for all childs.
if( !Node::hasParent() || redirectToChilds )
{
ObjectChilds childs = Object::getChildObjects();
for( ObjectChilds::iterator i = childs.begin(); i != childs.end(); ++i )
ObjectHashMap childs = Object::getChildObjects();
for( ObjectHashMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
// Set redirectToChilds to true so that the networking type will be set across the
// whole tree of objects.
Expand Down Expand Up @@ -212,8 +212,8 @@ void Object::querySetNetworkingType( NetworkingType type, bool redirectToChilds
// type can be changed for all childs.
if( !Node::hasParent() || redirectToChilds )
{
ObjectChilds childs = Object::getChildObjects();
for( ObjectChilds::iterator j = childs.begin(); j != childs.end(); ++j )
ObjectHashMap childs = Object::getChildObjects();
for( ObjectHashMap::iterator j = childs.begin(); j != childs.end(); ++j )
{
// Set redirectToChilds to true so that the networking type will be set across the
// whole tree of objects.
Expand Down Expand Up @@ -260,8 +260,8 @@ Object& Object::duplicate( const String& rName /*= ""*/ )
object.setScale( Node::getScale() );

// Duplicate child objects
ObjectChilds childs = Object::getChildObjects();
for( ObjectChilds::iterator i = childs.begin(); i != childs.end(); ++i )
ObjectHashMap childs = Object::getChildObjects();
for( ObjectHashMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
i->second->duplicate().parent( &object );
}
Expand Down Expand Up @@ -532,6 +532,20 @@ String Object::getParentName() const
return String();
}

Object& Object::childObjectByDisplayName( const String& rDisplayName )
{
ChildNodeMap childs = Node::getChildren();
for( ChildNodeMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
Object* object = static_cast<Object*>( i->second );
if( object->getDisplayName() == rDisplayName ) return *object;
}

DIVERSIA_EXCEPT( Exception::ERR_ITEM_NOT_FOUND,
"Child object with display name " + rDisplayName + " does not exist in object " + mName,
"Object::childObjectByDisplayName" );
}

void Object::setTemplate( ObjectTemplate* pTemplate )
{
mTemplate = pTemplate;
Expand Down
13 changes: 10 additions & 3 deletions Framework/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ObjectSystem
{
//------------------------------------------------------------------------------

typedef DiversiaHashMap<String, Object*> ObjectChilds;
typedef DiversiaHashMap<String, Object*> ObjectHashMap;
typedef std::multimap<ComponentType, Component*> ComponentsByType;
typedef std::map<String, Component*> ComponentsByName;

Expand Down Expand Up @@ -456,17 +456,24 @@ class DIVERSIA_OBJECT_API Object : public RakNet::Replica3, public Node, public
/**
Gets a copy of the childs map.
**/
inline ObjectChilds getChildObjects() const
inline ObjectHashMap getChildObjects() const
{
ChildNodeMap childs = Node::getChildren();
ObjectChilds objectChilds;
ObjectHashMap objectChilds;
for( ChildNodeMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
objectChilds.insert( std::make_pair( i->first, static_cast<Object*>( i->second ) ) );
}
return objectChilds;
}
/**
Gets a child object with given display name. If multiple childs have the same display name the
first one is returned.
@param rDisplayName Display name of the object to get.
**/
Object& childObjectByDisplayName( const String& rDisplayName );
/**
Sets the parent object for this object using a pointer to the parent object.
@param pObject The new parent object, or 0 to unparent.
Expand Down
8 changes: 4 additions & 4 deletions Framework/Object/ObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ void ObjectManager::destroyObjectTree( Object& rObject,
// Destroy all childs.
if( !rObject.hasParent() || redirectToChilds )
{
ObjectChilds childs = rObject.getChildObjects();
for( ObjectChilds::iterator i = childs.begin(); i != childs.end(); ++i )
ObjectHashMap childs = rObject.getChildObjects();
for( ObjectHashMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
// Set redirectToChilds to true so that the call is forwarded to all childs.
ObjectManager::destroyWholeObjectTree( *i->second, source, true );
Expand All @@ -160,8 +160,8 @@ void ObjectManager::destroyWholeObjectTree( Object& rObject,
// Destroy all childs.
if( !rObject.hasParent() || redirectToChilds )
{
ObjectChilds childs = rObject.getChildObjects();
for( ObjectChilds::iterator i = childs.begin(); i != childs.end(); ++i )
ObjectHashMap childs = rObject.getChildObjects();
for( ObjectHashMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
// Set redirectToChilds to true so that the call is forwarded to all childs.
ObjectManager::destroyWholeObjectTree( *i->second, source, true );
Expand Down
4 changes: 2 additions & 2 deletions Framework/Object/ObjectTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ void ObjectTemplate::createComponentTemplates( const Object& rObject )
Node::setScale( rObject.getScale() );

// Recursively go trough all child objects.
ObjectChilds childs = rObject.getChildObjects();
for( ObjectChilds::iterator i = childs.begin(); i != childs.end(); ++i )
ObjectHashMap childs = rObject.getChildObjects();
for( ObjectHashMap::iterator i = childs.begin(); i != childs.end(); ++i )
{
mObjectTemplateManager.createObjectTemplate( *i->second,
mObjectTemplateManager.generateName(), mType ).parent( this );
Expand Down

0 comments on commit 87e1123

Please sign in to comment.