having a nice break/esc behavior on bake

other occasions like ALT_A needs that too
This commit is contained in:
Jens Ole Wund 2006-11-20 22:27:05 +00:00
parent c57d5bca73
commit 731e7e3915
3 changed files with 31 additions and 11 deletions

@ -49,5 +49,10 @@ extern void sbObjectStep(struct Object *ob, float framnr, float (*vertexCos)[
/* makes totally fresh start situation, resets time */
extern void sbObjectToSoftbody(struct Object *ob);
/* links the softbody module to a 'test for Interrupt' function */
/* pass NULL to unlink again */
extern void sbSetInterruptCallBack(int (*f)(void));
#endif

@ -82,6 +82,11 @@ variables on the UI for now
#include "BIF_editdeform.h"
#include "BIF_graphics.h"
#include "PIL_time.h"
/* callbacks for errors and interrupts and some goo */
static int (*SB_localInterruptCallBack)(void) = NULL;
/* ********** soft body engine ******* */
@ -3060,6 +3065,13 @@ static int object_has_edges(Object *ob)
}
}
/* SB global visible functions */
void sbSetInterruptCallBack(int (*f)(void))
{
SB_localInterruptCallBack = f;
}
/* simulates one step. framenr is in frames */
void sbObjectStep(Object *ob, float framenr, float (*vertexCos)[3], int numVerts)
{
@ -3271,6 +3283,8 @@ void sbObjectStep(Object *ob, float framenr, float (*vertexCos)[3], int numVerts
sct=PIL_check_seconds_timer();
if (sct-sst > 0.5f) printf("%3.0f%% \r",100.0f*timedone);
}
if (SB_localInterruptCallBack && SB_localInterruptCallBack()) break;
}
/* move snapped to final position */
interpolate_exciter(ob, 2, 2);

@ -1384,11 +1384,12 @@ void softbody_bake(Object *ob)
SoftBody *sb;
ScrArea *sa;
float frameleno= G.scene->r.framelen;
int cfrao= CFRA, sfra=100000, efra=0;
unsigned short event=0;
short val;
int cfrao= CFRA, sfra=100000, efra=0, didbreak =0;
G.scene->r.framelen= 1.0; // baking has to be in uncorrected time
sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
G.afbreek=0; // init global break system
if(ob) {
sb= ob->soft;
@ -1427,16 +1428,14 @@ void softbody_bake(Object *ob)
}
}
screen_swapbuffers();
while(qtest()) {
event= extern_qread(&val);
if(event==ESCKEY) break;
//blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
if (blender_test_break()){
didbreak = 1;
break;
}
if(event==ESCKEY) break;
}
if(event==ESCKEY) {
if(didbreak) {
if(ob)
sbObjectToSoftbody(ob); // free bake
else {
@ -1452,6 +1451,8 @@ void softbody_bake(Object *ob)
/* restore */
waitcursor(0);
sbSetInterruptCallBack(NULL); // softbody module won't ESC
G.afbreek=0; // reset global break system
if(ob)
ob->softflag &= ~OB_SB_BAKEDO;