/***************************************************************************
* Copyright (C) 2004 by Raphael Langerhorst *
* raphael-langerhorst@gmx.at *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
* OTHER DEALINGS IN THE SOFTWARE. *
***************************************************************************/
// #include <kapplication.h>
// #include <kmainwindow.h>
// #include <kcmdlineargs.h>
#include <qapplication.h>
#include <qtimer.h>
#include <qvbox.h>
#include <qslider.h>
#include <qtoolbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qtimer.h>
#include "CreateUniverseButton.h"
#include <GElementID.h>
#include <GMoveAgent.h>
#include <GCoreXmlSerializer.h>
#include <GWorldEngineFactory.h>
using namespace GCS;
int main(int argc, char** argv)
{
// test the network capabilities of the GWE
if (argc > 3) //2 = JID, 3 = password
{
if (QString(argv[1]) == "testgwe")
{
QApplication a(argc,argv);
GWE::GWorldEngineFactory f;
GWE::GweFactoryOption* root_option = f.getRootOption();
root_option->setValue("advanced");
root_option->updateTree();
root_option->setValueOfSubOption("xmpp_jid",argv[2]);
root_option->setValueOfSubOption("xmpp_password",argv[3]);
QTimer::singleShot(100,&f,SLOT(init())); //use a timer to avoid segmentation fault (event loop must run)
return a.exec();
return 0;
}
}
if (argc > 1)
{
if (QString(argv[1]) == "testserializer")
{
QApplication a(argc,argv);
GWE::GCoreXmlSerializer s(NULL);
GObject* galaxy_object = new GObject(
new GEnergy(10,1000,3),
new GForm(GVector3(0,1,2)),
GElementID(1), //the galaxy is it's own parent ;)
GElementID(1), //own ID is 1
GElementID(1), //connect to itself (connectionID is the same as own ID)
new QDomDocument(),
NULL);
//now create the solar system element
GBE::GMoveAgent* move_agent = new GBE::GMoveAgent();
GElement* galaxy = new GElement(galaxy_object);
galaxy->addAgent(move_agent);
move_agent->initTranslationSpeed(GVector3(3.45,63,2));
// move_agent->initTranslationSpeed(GVector3(3.45,-21,2));
qDebug("element data:");
qDebug(galaxy->getObject()->getElementData()->toString());
//let's see how long it takes to serialize...
QTime t;
t.start();
for (int i=0; i<100; i++)
QDomElement e = s.serializeElement(galaxy,"GElement");
qDebug(QString::number(t.restart()));
QDomElement e = s.serializeElement(galaxy,"GElement");
qDebug("string representation of XML'd element:");
qDebug(e.ownerDocument().toString());
t.restart();
GElement* element = NULL;
for (int i=0; i<100; i++)
{
element = s.createElement(e);
// const GEnergy* e = element->getObject()->getEnergy();
// qDebug(QString::number(e->level()) + " " + QString::number(e->amount()) + " " + QString::number(e->sigma()));
}
qDebug("string representation of deserialized element:");
e = s.serializeElement(element,"GElement");
qDebug(e.ownerDocument().toString());
qDebug(QString::number(t.restart()));
return 0;
}
}
//NOTE the investigation interface has been removed, it's not the focus of the current demo!
// It is available in the 0.3.1 and 0.4 releases of the G System if you need it.
// You can get it by checking out the latest 0.4 branch:
// svn co svn://svn.g-system.at/G/branches/branch-0.4
// You have to connect a lot of signals and slots to use it! Look at the 0.3.1 release for details.
// KCmdLineArgs::init(argc,argv,"gdemo","evolution simulation","0.3",true);
// KApplication a;
QApplication a(argc,argv);
//initialise available IDs
// THIS IS NOW DONE BY THE DATA CONTROLLERS!
// GCS::GElementID::addFreeIDRange(10,1000000);
//KMainWindow mainFrame;
QObject::connect(&a,SIGNAL(lastWindowClosed()),&a,SLOT(quit()));
QVBox help(NULL);
QTextEdit text(&help);
text.setReadOnly(true);
text.append("<h1><p align=\"center\">~ G System 0.5 development release ~</p></h1>");
text.append("<p align=\"left\">How to navigate:</p>");
text.append("Use space to move forward, use arrow keys to turn. Press enter for a full stop.");
text.append("The demo represents a galaxy that is deterministically randomised. New solar systems are generated as you move into certain directions. If you move into a solar system, planets are created. Just go ahead, launch the demo and enjoy!");
text.append("Note: a network client and even server is also available. You can use guniverseclient to join an universe.");
text.append("0.5 note: the intention of the 0.5.x series is to test the network capabilities of the G System. Please help us by using the guniverseclient to connect to one of the available universes. The status of all known universes are available on our homepage. Do inform us if you plan to set up your own network with the guniverse server!");
text.append("You can find our website at http://www.g-system.at");
QHBox start_box(&help);
QSpinBox spin_box(&start_box);
spin_box.setMinValue(0);
spin_box.setMaxValue(30000);
spin_box.setValue(7471);
CreateUniverseButton start_button(&spin_box,"Create Universe",&start_box);
QPushButton exit_button("Quit",&start_box);
QObject::connect(&exit_button,SIGNAL(pressed()),qApp,SLOT(quit()));
help.resize(640,420);
help.show();
//start the event loop
return a.exec();
}
syntax highlighted by Code2HTML, v. 0.9.1