|
Re: [newbie] Question on embedding/extending with boost::python: msg#00326python.c++
"Dirk Gerrits" <dirk@xxxxxxxxxxxxxxxxxx> wrote: > Brett Calcott wrote: > > > > I had previously embedded python in my c++ app so that I could > > script my agents, but the result was very slow as this effectively > > did this (vastly simplified) > > > > while (engine_running) > > { > > for (agents_container:iterator a = agents.begin(); a != > > agents.end(); ++a) > > { > > // here we call out to python for each agent > > (*a).update_yourself_via_python() > > update_visual_stuff() > > } > > } > > > > The calls to python are in the inner loop and this is slow. > > Well I suppose you could expose a visual_stuff_updating_iterator to > Python, but extending is of course a much easier and cleaner. Not sure I follow what you mean here.. > > > What I am doing now is different - I am constructng an engine in > > C++, making all the agents and world parameters accessible to > > python, BUT the update main loop remains entirely in C++: > > > > import engine # boost python module > > > > while engine_running: > > engine.cycle() > > I'm not sure I follow. Is engine.cycle() still doing a > a->update_yourself_via_python() for every agent? Then where's the > speedup compared to the embedded approach? > > No, it's not. The engine.cycle() function never calls back to python. Let me try and clarify. The big difference in what I am doing now is how I am using python -- it is serving a completely different role in my software development. Before, I wrote everything in C++ - and python was playing the role of allowing me to script the actions of my agents. I was using python because it allowed me to change the behaviour of my agents without recompiling. The degree to which I benefitted from python was the ease with which I could quickly change the behaviour of my agents -- the problem was that it slowed the simulation down. Now, I am using python to construct the entire framework, and I am writing the agents, including their "update" function, in C++. The advantage I get from this is the speed of development of all the support framework, including inspection/pickling/scripted setups, and the power and ease of the entire python library. However, the core engine that has to be quick will be in C++. Now, I don't get the advantage of being able to script my agents behaviour, that is still in C++, but I get a headstart on everything else. Of course, it is not as bad as that. I can still parameterise the agents behaviour and set those parameters interactively in python and, as before, I can still choose to use an agent that is extensible in python and really slow, but just for the purpose of testing -- then I can push the code back to C++. This is particularly easy with the boost_python stuff. To summarise -- that big change is in how I look at python. Before, I saw C++ as a serious development framework, and python as a scripting language for doing the little bits of my app that I wanted to change quickly. Now, I see python as an incredibly fast development framework, and C++ as something to make the computationally intensive bits of my app go faster. So I things have sort of been stood on their head. I still love C++, but I can make stuff happen so much more quickly in python. Cheers, Brett |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | OpenSceneGraph bindings now hosted at sourceforge.: 00326, gideon may |
|---|---|
| Next by Date: | Re: Support for Indexing and Iteration Safety: 00326, Brett Calcott |
| Previous by Thread: | Re: [newbie] Question on embedding/extending with boost::pythoni: 00326, Dirk Gerrits |
| Next by Thread: | Re: [newbie] Question on embedding/extending with boost::python: 00326, Dirk Gerrits |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |