Function:ds2protect

From S2PLOT

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

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

Line 1: Line 1:
==ds2protect== ==ds2protect==
-Protect/unprotect dynamic geometry.+Protect dynamic geometry.
==Prototype== ==Prototype==
Line 9: Line 9:
==Description== ==Description==
-Protect / unprotect 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 [[Function:ds2unprotect | 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.+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 [[Function:ds2unprotect | 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 == == See Also ==
<table> <table>
-<tr><td>[[Function:s2open | s2open]]</td><td>. </td></tr>+<tr><td>[[Function:ds2unprotect | ds2unprotect]]</td><td>Unprotect the dynamic geometry.</td></tr>
 +<tr><td>[[Function:ds2isprotected | ds2isprotected]]</td><td>Query state of dynamic geometry protection. </td></tr>
</table> </table>
==Code Example== ==Code Example==
<code><pre> <code><pre>
 +#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;
 +}
 +
</pre></code> </pre></code>
[[S2PLOT:Function List | Back]] to S2PLOT function list. [[S2PLOT:Function List | Back]] to S2PLOT function list.
__NOTOC__ __NOTOC__
__NOEDITSECTION__ __NOEDITSECTION__

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