Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 901


Ignore:
Timestamp:
Mar 19, 2008, 12:38:32 AM (16 years ago)
Author:
landauf
Message:

Namespaces are working now. I love this feature, can't stop playing with it :D

Location:
code/branches/core2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/bin/levels/sample.oxw

    r871 r901  
     1<Namespace name="test" />
     2<Namespace name="blub" />
     3<Namespace name="rofl" />
     4
     5<Namespace name="ns1">
     6  <Namespace name="ns11">
     7    <Namespace name="ns111">
     8    </Namespace>
     9    <Namespace name="ns112">
     10    </Namespace>
     11  </Namespace>
     12  <Namespace name="ns12">
     13    <Namespace name="ns121">
     14    </Namespace>
     15    <Namespace name="ns122">
     16    </Namespace>
     17  </Namespace>
     18</Namespace>
     19
     20<Namespace name="ns1::ns12::ns121">
     21  <Namespace name="ns1211">
     22  </Namespace>
     23</Namespace>
     24<Namespace name="ns1::ns12::ns122::ns1221" />
     25
    126<!--
    227 <audio>
     
    2348<NPC position="100,0,400" scale="1" mesh="razor.mesh"/>
    2449
    25 <Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
    26 <Model name="drone" position="-200,0,500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
    27   <attached>
    28     <Model name="drone2" position="200,-100,-500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
    29       <attached>
    30         <Model name="starship2" position="500,200,-500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
    31       </attached>
    32     </Model>
    33   </attached>
    34 </Model>
     50<Namespace name="starshipanddrone">
     51  <Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
     52  <Model name="drone" position="-200,0,500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
     53    <attached>
     54      <Model name="drone2" position="200,-100,-500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
     55        <attached>
     56          <Model name="starship2" position="500,200,-500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
     57        </attached>
     58      </Model>
     59    </attached>
     60  </Model>
     61</Namespace>
    3562
    3663<Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yawpitchroll="-90,-90,0" />
     
    4067<Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" />
    4168
     69<Namespace name="test" />
     70<Namespace name="blub">
     71</Namespace>
     72<Namespace name="rofl">
     73  <Namespace name="lol">
     74  </Namespace>
     75</Namespace>
     76
     77<Namespace name="ns1">
     78  <Namespace name="ns11">
     79    <Namespace name="ns111">
     80      <Namespace name="ns1111">
     81      </Namespace>
     82    </Namespace>
     83  </Namespace>
     84  <Namespace name="ns13">
     85  </Namespace>
     86</Namespace>
     87
     88<Namespace name="ns1 ns2">
     89  <Namespace name="abc" />
     90</Namespace>
     91
     92<Namespace name="ns1::ns11 ns1::ns12 ns1::ns12::ns121">
     93  <Namespace name="muhahaha" />
     94</Namespace>
     95
     96<Namespace name="test">
     97  <Namespace name="test" />
     98</Namespace>
     99
     100<Namespace name="ns1::ns13">
     101  <Namespace name="..::ns14" />
     102  <Namespace name="..::..::ns3" />
     103</Namespace>
     104
     105<Namespace name="AAA::BBB::..::CCC::..::DDD::..::BBB::BBBBBB::..::BBBBBBBBBBBBBBBBBBB::..::..::EEE" />
     106
     107<Namespace name="..::justatest" />
     108
     109<Namespace name="@file.oxw::anothertest" />
     110
     111<Namespace name="justonemoretest::@file.oxw::gagagaga" />
     112
     113<Namespace name="AAA::BBB, AAA::CCC; AAA::DDD,AAA::EEE">
     114  <Namespace name="hax" />
     115</Namespace>
     116
    42117    <Model position="-16779,42,11043" scale="95" mesh="ast2.mesh" rotationAxis="0.281711,0.152518,0" rotationRate="27" />
    43118    <Model position="12893,-1583,-17939" scale="48" mesh="ast1.mesh" rotationAxis="0.0597998,0.923364,0" rotationRate="36" />
     
    45120    <Model position="-9583,-2284,-19904" scale="33" mesh="ast5.mesh" rotationAxis="0,0.675659,0.0196445" rotationRate="44" />
    46121    <Model position="-19597,-15494,3163" scale="37" mesh="ast5.mesh" rotationAxis="0.477996,0,0.048639" rotationRate="23" />
    47     <Model position="-182,6442,-4496" scale="25" mesh="ast5.mesh" rotationAxis="0.142225,0,0.154393" rotationRate="37" />
     122    <!--Model position="-182,6442,-4496" scale="25" mesh="ast5.mesh" rotationAxis="0.142225,0,0.154393" rotationRate="37" />
    48123    <Model position="1004,-19639,-13744" scale="21" mesh="ast1.mesh" rotationAxis="0.974865,0.299775,0" rotationRate="29" />
    49124    <Model position="-13204,-10191,-1555" scale="31" mesh="ast1.mesh" rotationAxis="0.41675,0,0.385001" rotationRate="42" />
     
    266341    <Model position="1991,-11949,-15733" scale="68" mesh="ast1.mesh" rotationAxis="0,0.390655,0.623811" rotationRate="41" />
    267342    <Model position="-6787,1792,287" scale="71" mesh="ast6.mesh" rotationAxis="0.161019,0.130015,0" rotationRate="36" />
    268     <Model position="-7223,-13574,-11873" scale="24" mesh="ast4.mesh" rotationAxis="0.792203,0,0.177188" rotationRate="38" />
     343    <Model position="-7223,-13574,-11873" scale="24" mesh="ast4.mesh" rotationAxis="0.792203,0,0.177188" rotationRate="38" /-->
  • code/branches/core2/src/orxonox/core/Loader.cc

    r899 r901  
    115115            ticpp::Document xmlfile(level->getFile());
    116116            xmlfile.LoadFile();
     117
    117118            ticpp::Element rootElement;
    118119            rootElement.SetAttribute("name", "root");
     120            rootElement.SetAttribute("bAutogenerated", true);
    119121
    120122            for (ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++)
     
    126128            rootNamespace->setLevel(level);
    127129            rootNamespace->setNamespace(rootNamespace);
    128             rootNamespace->deleteNamespaceNodesAfterDestruction(true);
     130            rootNamespace->setRoot(true);
    129131            rootNamespace->XMLPort(rootElement, true);
    130132
    131133            COUT(0) << "Finished loading " << level->getFile() << "." << std::endl;
     134
     135            COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString("  ") << std::endl;
    132136
    133137            return true;
  • code/branches/core2/src/orxonox/core/Namespace.cc

    r898 r901  
    4141
    4242        this->bAutogeneratedFileRootNamespace_ = false;
    43         this->bDeleteNamespaceNodesAfterDestruction_ = false;
     43        this->bRoot_ = false;
    4444        this->operator_ = "or";
    4545    }
     
    4747    Namespace::~Namespace()
    4848    {
    49         if (this->bDeleteNamespaceNodesAfterDestruction_)
     49        if (this->bRoot_)
    5050            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
    5151                delete (*it);
     
    7373            name.replace(pos, 1, " ");
    7474        SubString tokens(name, " ", "", false, '\\', '"', '\0', '\0', '\0');
    75         for (unsigned int i = 0; i < tokens.size(); i++)
     75        if (this->bRoot_)
    7676        {
    77             for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
     77            this->representingNamespaces_.insert(new NamespaceNode(this->getName()));
     78        }
     79        else
     80        {
     81            for (unsigned int i = 0; i < tokens.size(); i++)
    7882            {
    79                 std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
    80                 this->representingNamespaces_.insert(temp.begin(), temp.end());
     83                for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
     84                {
     85                    std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
     86                    this->representingNamespaces_.insert(temp.begin(), temp.end());
     87                }
    8188            }
    8289        }
     
    138145        return false;
    139146    }
     147
     148    std::string Namespace::toString() const
     149    {
     150        std::string output;
     151
     152        int i = 0;
     153        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
     154        {
     155            if (i > 0)
     156                output += " / ";
     157
     158            output += (*it)->toString();
     159        }
     160
     161        return output;
     162    }
     163
     164    std::string Namespace::toString(const std::string& indentation) const
     165    {
     166        std::string output;
     167
     168        int i = 0;
     169        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
     170        {
     171            if (i > 0)
     172                output += "\n";
     173
     174            output += (*it)->toString(indentation);
     175        }
     176
     177        return output;
     178    }
    140179}
  • code/branches/core2/src/orxonox/core/Namespace.h

    r896 r901  
    5959                { return this->operator_; }
    6060
     61            void setRoot(bool bRoot)
     62                { this->bRoot_ = bRoot; }
     63
    6164            bool includes(const Namespace* ns) const;
    6265            bool isIncludedIn(const Namespace* ns) const { return ns->includes(this); }
    6366
    64             void deleteNamespaceNodesAfterDestruction(bool bDelete)
    65                 { this->bDeleteNamespaceNodesAfterDestruction_ = bDelete; }
     67            std::string toString() const;
     68            std::string toString(const std::string& indentation) const;
    6669
    6770        private:
    6871            std::set<NamespaceNode*> representingNamespaces_;
    6972            bool bAutogeneratedFileRootNamespace_;
    70             bool bDeleteNamespaceNodesAfterDestruction_;
     73            bool bRoot_;
    7174            std::string operator_;
    7275    };
  • code/branches/core2/src/orxonox/core/NamespaceNode.cc

    r895 r901  
    4949        std::set<NamespaceNode*> nodes;
    5050
    51         if (name == "")
     51        if ((name.size() == 0) || (name == ""))
    5252        {
    5353            nodes.insert(this);
     
    5656        {
    5757            unsigned int pos = name.find("::");
    58             std::string firstPart = name.substr(0, pos);
    59             std::string secondPart = name.substr(pos + 2, std::string::npos);
     58            std::string firstPart = name;
     59            std::string secondPart;
     60
     61            if (pos != std::string::npos)
     62            {
     63                firstPart = name.substr(0, pos);
     64                secondPart = name.substr(pos + 2, std::string::npos);
     65            }
    6066
    6167            if (firstPart == "..")
     
    6470                {
    6571                    COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", namespace is root." << std::endl;
     72                    nodes = this->getNodeRelative(secondPart);
     73                }
     74                else if (!this->parent_)
     75                {
     76                    COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", no parent namespace set." << std::endl;
    6677                    nodes = this->getNodeRelative(secondPart);
    6778                }
     
    7889
    7990                if ((*it).second->isHidden())
     91                {
    8092                    COUT(2) << "Warning: Subnamespace '" << firstPart << "' in namespace '" << this->name_ << "' is hidden and can't be accessed." << std::endl;
     93                    nodes.insert(this);
     94                }
    8195                else
     96                {
    8297                    nodes = (*it).second->getNodeRelative(secondPart);
     98                }
    8399            }
    84100            else
    85101            {
     102                bool bFoundMatchingNamespace = false;
     103
    86104                for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
    87105                {
     
    90108                        std::set<NamespaceNode*> temp2 = (*it).second->getNodeRelative(secondPart);
    91109                        nodes.insert(temp2.begin(), temp2.end());
     110                        bFoundMatchingNamespace = true;
    92111                    }
     112                }
     113
     114                if (!bFoundMatchingNamespace)
     115                {
     116                    COUT(2) << "Warning: No file included with name '" << firstPart.substr(1, std::string::npos) << "' at this part of the level file, using parent namespace instead." << std::endl;
     117                    nodes = this->getNodeRelative(secondPart);
    93118                }
    94119            }
     
    113138        return false;
    114139    }
     140
     141    std::string NamespaceNode::toString() const
     142    {
     143        std::string output = this->name_;
     144
     145        if (this->subnodes_.size() > 0)
     146        {
     147            output += " (";
     148
     149            int i = 0;
     150            for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); i++, ++it)
     151            {
     152                if (i > 0)
     153                    output += ", ";
     154
     155                output += (*it).second->toString();
     156            }
     157
     158            output += ")";
     159        }
     160
     161        return output;
     162    }
     163
     164    std::string NamespaceNode::toString(const std::string& indentation) const
     165    {
     166        std::string output = (indentation + this->name_ + "\n");
     167
     168        for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
     169            output += (*it).second->toString(indentation + "  ");
     170
     171        return output;
     172    }
    115173}
  • code/branches/core2/src/orxonox/core/NamespaceNode.h

    r895 r901  
    5353            bool includes(const NamespaceNode*) const;
    5454
     55            std::string toString() const;
     56            std::string toString(const std::string& indentation) const;
     57
    5558        private:
    5659            std::string name_;
  • code/branches/core2/src/orxonox/core/XMLPort.h

    r898 r901  
    256256                                            newObject->setNamespace(object->getNamespace());
    257257                                            if (this->bLoadBefore_)
     258                                            {
    258259                                                newObject->XMLPort(*child, true);
    259                                             COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
     260                                                COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
     261                                            }
     262                                            else
     263                                            {
     264                                                COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
     265                                            }
    260266                                            (*object.*this->loadfunction_)(newObject);
    261267                                            if (!this->bLoadBefore_)
Note: See TracChangeset for help on using the changeset viewer.