Revision: 75618
http://sourceforge.net/p/brlcad/code/75618
Author: starseeker
Date: 2020-04-28 12:03:12 +0000 (Tue, 28 Apr 2020)
Log Message:
-----------
This slows the refresh rate, but doesn't do a 'final' update once things
stabelize. Will probably need to trigger an event in the main thread with
Tcl_ThreadQueueEvent and Tcl_ThreadAlert for that to work...
Modified Paths:
--------------
brlcad/trunk/src/libdm/tests/tcl_img.cpp
Modified: brlcad/trunk/src/libdm/tests/tcl_img.cpp
===================================================================
--- brlcad/trunk/src/libdm/tests/tcl_img.cpp 2020-04-28 11:40:51 UTC (rev
75617)
+++ brlcad/trunk/src/libdm/tests/tcl_img.cpp 2020-04-28 12:03:12 UTC (rev
75618)
@@ -36,6 +36,9 @@
const char *DM_PHOTO = ".dm0.photo";
const char *DM_CANVAS = ".dm0";
+TCL_DECLARE_MUTEX(dilock)
+
+
/* Container holding image generation information - need to be able
* to pass these to the update command */
struct img_data {
@@ -42,6 +45,7 @@
std::default_random_engine *gen;
std::uniform_int_distribution<int> *colors;
std::uniform_int_distribution<int> *vals;
+ int *dflag;
};
int
@@ -149,11 +153,27 @@
int
image_resize_view(ClientData clientData, Tcl_Interp *interp, int argc, char
**argv)
{
+ int go_flag = 0;
if (argc != 3) {
std::cerr << "Unexpected argc: " << argc << "\n";
return TCL_ERROR;
}
+ struct img_data *idata = (struct img_data *)clientData;
+
+ Tcl_MutexLock(&dilock);
+ if ((*idata->dflag) > 1) {
+ std::cout << "dflag: " << (*idata->dflag) << "\n";
+ (*idata->dflag) = 0;
+ go_flag = 1;
+ }
+ Tcl_MutexUnlock(&dilock);
+
+ if (!go_flag) {
+ std::cout << "Skipping redraw\n";
+ return TCL_OK;
+ }
+
// Unpack the coordinates (checking errno, although it may not truly be
// necessary if we trust Tk to always give us valid coordinates...)
char *p_end;
@@ -183,7 +203,6 @@
int flag; /* Identifier for this handler. */
};
-TCL_DECLARE_MUTEX(dilock)
static Tcl_ThreadCreateType
Dm_Draw(ClientData clientData)
@@ -191,7 +210,7 @@
struct draw_info *di = (struct draw_info *)clientData;
while (di->flag >= 0) {
- Tcl_Sleep(1);
+ Tcl_Sleep(1000);
Tcl_MutexLock(&dilock);
di->flag++;
Tcl_MutexUnlock(&dilock);
@@ -323,6 +342,8 @@
if (Tcl_CreateThread(&threadID, Dm_Draw, (ClientData)&di,
TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) {
std::cerr << "can't create thread\n";
}
+ // Let the update routines see the flag
+ idata.dflag = &di.flag;
// Enter the main applicatio loop - the initial image will appear, and
Button-1 mouse
@@ -329,14 +350,6 @@
// clicks on the window should generate and display new images
while (1) {
Tcl_DoOneEvent(0);
- if (di.flag) {
- std::cout << "Flag set\n";
- Tcl_MutexLock(&dilock);
- di.flag = 0;
- Tcl_MutexUnlock(&dilock);
- } else {
- std::cout << "Flag unset\n";
- }
if (!Tk_GetNumMainWindows()) {
// If we've closed the window, we're done
Tcl_MutexLock(&dilock);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits