i dont know if those both codes are clean enough. or maybe bad documented, but maybe you could use them as test samples? if you want take them, just say me, the points which needs to be improved. like better documented or so on… or overwork the code completly…
the first is about parallel processing:
// PARALLEL PROCESSING -> parallel processing of two distances, this should just display how to parallel processing, of course there is no need to do this twice! ;)
// this processing idea was just coming along to improve the performance at the raster particles for smashBALL, now im able to split my particle calculation up!
// it should improve the performance up to 30 % or more! :D :D :D i hope! but im sure it does :D
// dirk-r. hochegger 2010
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "graphicsEngine.h"
#include "process.h"
#include "windows.h"
PandaFramework framework;
WindowFramework *window;
GraphicsEngine *engine;
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
PT(ClockObject) globalClock = ClockObject::get_global_clock();
NodePath camera,model[2];
//init the start position
LVecBase3f pos1 (0.8,0.0,0.0),pos2 (-0.8,0.0,0.0);
//parallel processing related
// declare the parallel processing vars
float dis,dis1;
int isACTIVE = 1;
void parallelDISTANCEcalc1 (void *);
void parallelDISTANCEcalc2 (void *);
//window open
void windowOPEN() {
WindowProperties *props = new WindowProperties();
props->set_size(500,500);
props->set_origin(500,10);
props->set_undecorated(true);
window = framework.open_window(*props,0);
window->get_graphics_window()->get_active_display_region(0)->set_clear_color(Colorf(0,0,0,1));
}
// stor camera
void getCAMERA() {
camera = window->get_camera_group();
}
// load model
void loadMODEL() {
for (int i=0;i<2;i++) {
model[i] = window->load_model(framework.get_models(),"smiley");
model[i].set_scale(.1);
model[i].reparent_to(window->get_aspect_2d());
}
}
//parallel processing
void parallelDISTANCEcalc1 (void *) {
while (isACTIVE) {
LVecBase3f disX = (pos1-pos2);
dis = disX.length();
if (dis < .1) {
pos1.set_x(pos1.get_x());
}
else {
pos1.set_x(pos1.get_x()-.005);
}
Sleep(10);
}
}
void parallelDISTANCEcalc2 (void *) {
while (isACTIVE) {
LVecBase3f disX = (pos1-pos2);
dis1 = disX.length();
if (dis1 < .1) {
pos2.set_x(pos2.get_x());
}
else {
pos2.set_x(pos2.get_x()+.005);
}
Sleep(10);
}
}
// using a task for picking the values
AsyncTask::DoneStatus mainTASK(GenericAsyncTask* task, void* data) {
model[0].set_x(pos1.get_x());
model[1].set_x(pos2.get_x());
return AsyncTask::DS_cont;
}
int main(int argc, char *argv[]) {
framework.open_framework(argc, argv);
windowOPEN();
getCAMERA();
loadMODEL();
_beginthread(parallelDISTANCEcalc1, 0, NULL);
_beginthread(parallelDISTANCEcalc2, 0, NULL);
taskMgr->add(new GenericAsyncTask("main task", &mainTASK, (void*) NULL));
framework.main_loop();
framework.close_framework();
return (0);
}
the second is about the rigidbodycombiner:
//test rigidBODY node removing (not working)
//dirk-r. hochegger 2010 kind supported by drwr
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "texturePool.h"
#include "PGButton.h"
#include "mouseButton.h"
#include "transparencyAttrib.h"
#include "rigidBodyCombiner.h"
//init vars
PandaFramework framework;
WindowFramework *window;
GraphicsEngine *engine;
PT(ClockObject) globalClock = ClockObject::get_global_clock();
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
PT(RigidBodyCombiner) rbc = new RigidBodyCombiner("rbc");
PT(Texture) texturePARTICLE;
PT(PGButton) newINSTANCES;
NodePath camera,rigNode[10000],obj[100000],buttonINS;
int rigNODEid = 0,partCOUNT=100,timerX;
float PARTposY = .5;
/*
opens a window, setting some things, like size, origin on the screen...
*/
void windowOPEN() {
framework.set_window_title("rigTEST");
WindowProperties *props = new WindowProperties();
props->set_size(500,500);
props->set_origin(500,10);
props->set_undecorated(true);
window = framework.open_window(*props,0);
window->get_graphics_window()->get_active_display_region(0)->set_clear_color(Colorf(1,1,1,1));
}
// get the camera and stored in var camera
void getCAMERA() {
camera = window->get_camera_group();
}
/*
paints the geometry and assign it on a rigid body
*/
void paintGEO() {
rigNode[rigNODEid] = NodePath(rbc);
rigNode[rigNODEid].reparent_to(window->get_aspect_2d());
float PARTposX = -.5;
int count = 0;
for (int i=0;i<partCOUNT;i++){
obj[i] = window->load_model(framework.get_models(),"box");
obj[i].set_scale(.04);
obj[i].set_pos(PARTposX,0,PARTposY);
obj[i].set_p(90);
obj[i].reparent_to(rigNode[rigNODEid]);
PARTposX += .04;
count++;
if (count > 24) {
PARTposY -=.04;
PARTposX = -.5;
count = 0;
}
}
rbc->collect();
}
/*
detach the not needed nodes out of the rigid body and detach the rigid body completly and removes the nodes
(just to be sure that everything is deleted, its not really important, to do this thing twice)
setting some things, like add 100 new objects , getting back to the start position...
loop over all objects and set a new scale for it
*/
static void NEWINSTANCES(const Event *ev, void *data){
PGButton* CurrentButton=(PGButton *)data;
for (int i=0;i<partCOUNT;i++) {
obj[i].detach_node();
obj[i].remove_node();
}
rbc->collect();
// rigNode[rigNODEid].detach_node();
// rigNode[rigNODEid].remove_node();
PARTposY = .5;
partCOUNT += 100;
paintGEO();
for (int i=0;i<partCOUNT;i++) {
obj[i].set_scale(.02);
}
rigNODEid++;
}
// get a button
void button() {
newINSTANCES = new PGButton("newINSTANCES");
newINSTANCES->setup("newINSTANCES",0.2);
buttonINS = window->get_aspect_2d().attach_new_node(newINSTANCES);
buttonINS.set_scale(.05);
buttonINS.set_pos(0,0,-.5);
framework.define_key(newINSTANCES->get_click_event(MouseButton::one() ), "button press", &NEWINSTANCES, newINSTANCES);
}
// init the main program
int main(int argc, char *argv[]) {
framework.open_framework(argc, argv);
windowOPEN();
getCAMERA();
paintGEO();
button();
framework.main_loop();
framework.close_framework();
return (0);
}