2009-11-16 03:14:53 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-11-16 03:14:53 +00:00
|
|
|
#include <Python.h>
|
2018-11-03 16:43:33 +01:00
|
|
|
#include <rules/simulation/python/CyPy_Server.h>
|
|
|
|
|
#include <rules/python/CyPy_Rules.h>
|
|
|
|
|
#include <rules/python/CyPy_Physics.h>
|
|
|
|
|
#include <rules/python/CyPy_Atlas.h>
|
|
|
|
|
#include <rules/python/CyPy_Common.h>
|
2021-06-27 17:00:34 +02:00
|
|
|
#include "pythonbase/PythonMalloc.h"
|
2009-11-16 03:14:53 +00:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../python_testers.h"
|
2009-11-20 20:18:53 +00:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../TestWorld.h"
|
2010-07-13 18:39:03 +01:00
|
|
|
|
2021-06-27 17:00:34 +02:00
|
|
|
#include "pythonbase/Python_API.h"
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/simulation/Entity.h"
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/LineProperty.h"
|
|
|
|
|
#include "rules/simulation/TerrainProperty.h"
|
|
|
|
|
#include "rules/simulation/python/CyPy_Entity.h"
|
2009-11-16 03:14:53 +00:00
|
|
|
|
2019-10-02 23:30:13 +02:00
|
|
|
#include "pycxx/CXX/Extensions.hxx"
|
2009-11-16 03:14:53 +00:00
|
|
|
|
2018-07-23 11:01:35 +02:00
|
|
|
|
|
|
|
|
class TestProp : public Py::ExtensionModule<TestProp>
|
2009-11-16 03:14:53 +00:00
|
|
|
{
|
2018-07-23 11:01:35 +02:00
|
|
|
public:
|
|
|
|
|
Py::Object add_properties(const Py::Tuple& args)
|
|
|
|
|
{
|
|
|
|
|
auto ent = CyPy_Entity::value(args.front());
|
2009-11-16 03:14:53 +00:00
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
auto p = ent->setProperty("terrain", std::make_unique<TerrainProperty>());
|
2021-05-31 00:05:25 +02:00
|
|
|
p->install(*ent, "terrain");
|
|
|
|
|
p->apply(*ent);
|
2018-07-23 11:01:35 +02:00
|
|
|
ent->propertyApplied("terrain", *p);
|
2021-05-18 22:09:57 +02:00
|
|
|
p = ent->setProperty("line", std::make_unique<LineProperty>());
|
2021-05-31 00:05:25 +02:00
|
|
|
p->install(*ent, "line");
|
|
|
|
|
p->apply(*ent);
|
2018-07-23 11:01:35 +02:00
|
|
|
ent->propertyApplied("line", *p);
|
2009-11-16 03:14:53 +00:00
|
|
|
|
2018-07-23 11:01:35 +02:00
|
|
|
return Py::None();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestProp() : ExtensionModule("testprop")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
add_varargs_method("add_properties", &TestProp::add_properties, "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialize("testprop");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
2009-11-16 03:14:53 +00:00
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
setupPythonMalloc();
|
2021-05-30 21:35:41 +02:00
|
|
|
{
|
|
|
|
|
PyImport_AppendInittab("testprop", []() {
|
|
|
|
|
static TestProp testProp;
|
|
|
|
|
return testProp.module().ptr();
|
|
|
|
|
});
|
|
|
|
|
init_python_api({&CyPy_Server::init,
|
|
|
|
|
&CyPy_Rules::init,
|
|
|
|
|
&CyPy_Atlas::init,
|
|
|
|
|
&CyPy_Physics::init,
|
|
|
|
|
&CyPy_Common::init});
|
|
|
|
|
|
|
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> wrld(new Entity(0));
|
2021-05-30 21:35:41 +02:00
|
|
|
TestWorld tw(wrld);
|
|
|
|
|
|
|
|
|
|
run_python_string("from server import *");
|
|
|
|
|
run_python_string("import testprop");
|
|
|
|
|
run_python_string("t=Thing('1')");
|
|
|
|
|
run_python_string("t.props.line == None");
|
|
|
|
|
run_python_string("t.props.statistics == None");
|
|
|
|
|
run_python_string("t.props.terrain == None");
|
|
|
|
|
run_python_string("testprop.add_properties(t)");
|
|
|
|
|
run_python_string("t.props.line");
|
|
|
|
|
run_python_string("t.props.statistics");
|
|
|
|
|
run_python_string("t.props.terrain");
|
|
|
|
|
|
|
|
|
|
}
|
2009-11-16 03:14:53 +00:00
|
|
|
shutdown_python_api();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-09-06 13:48:40 +01:00
|
|
|
|
2012-09-11 22:53:15 +01:00
|
|
|
|