Function:ds2protect

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 04:14, 10 March 2008
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)

Line 47: Line 47:
COLOUR ocol = { 1, 1, 0 }; /* Point colour = yellow*/ COLOUR ocol = { 1, 1, 0 }; /* Point colour = yellow*/
ns2vthpoint(orbit, ocol, 3); /* Draw the point */ ns2vthpoint(orbit, ocol, 3); /* Draw the point */
- 
- char string[32]; /* Write instruction label */ 
- sprintf(string,"Press 1 to protect, press 2 to unprotect"); 
- s2lab("","","",string); 
} }
Line 63: Line 59:
cs2scb(cb); /* Install dynamic geometry callback */ cs2scb(cb); /* Install dynamic geometry callback */
cs2sncb(ncb); /* Install number key press callback */ cs2sncb(ncb); /* Install number key press callback */
 +
 + char string[32]; /* Write instruction label */
 + sprintf(string,"Press 1 to protect, press 2 to unprotect");
 + s2lab("","","",string);
s2show(1); /* Open the s2plot window */ s2show(1); /* Open the s2plot window */

Current revision

ds2protect

Protect dynamic geometry.

Prototype

void ds2protect(void);

Description

Protect the dynamic geometry, in order reduce the amount of geometry to call each refresh cycle. Typically use this by setting ds2protect() at the end of your standard dynamic callback, then call ds2unprotect() if key presses / events processed by other callbacks will result in a changed geometry state. Use with caution ... incorrect use can result in TMC: total memory consumption.

See Also

ds2unprotectUnprotect the dynamic geometry.
ds2isprotectedQuery state of dynamic geometry protection.

Code Example

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "s2plot.h"

void ncb(int *N)
{
   int pstate = ds2isprotected();               /* What is current protection state? */

   if ((*N == 1) && (pstate == 0)) {            /* Key 1 was pressed */
      ds2protect();                             /* Protect dynamic geometry */
   }
   if ((*N == 2) && (pstate == 1)) {            /* Key 2 was pressed */
      ds2unprotect();                           /* Unprotect dynamic geometry */
   }
}

void cb(double *t, int *kc)
{
   static XYZ orbit;                            /* Position of point to draw */
   static float tt = 0;                         /* Current position in orbit */
   orbit.x = cos(tt);                           /* Update point position */
   orbit.y = sin(tt);
   tt += 0.05;

   COLOUR ocol = { 1, 1, 0 };                   /* Point colour = yellow*/
   ns2vthpoint(orbit, ocol,  3);                /* Draw the point */

}

int main(int argc, char *argv[])
{
   srand48((long)time(NULL));                   /* Seed random numbers */
   s2opend("/?", argc, argv);                   /* Prompt for display type */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   cs2scb(cb);                                  /* Install dynamic geometry callback */
   cs2sncb(ncb);                                /* Install number key press callback */

   char string[32];                             /* Write instruction label */
   sprintf(string,"Press 1 to protect, press 2 to unprotect");
   s2lab("","","",string);

   s2show(1);                                   /* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.


Personal tools