Revision: 6281
http://playerstage.svn.sourceforge.net/playerstage/?rev=6281&view=rev
Author: thjc
Date: 2008-04-07 13:36:57 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
applied patch from David Olsen that allows clients to the graphics2d interface
to individually control a set of drawn objects. This allows for each client to
control the clearing of its objects reducing interference. Also clears a
clients set of renderings when it unsubscribes.
Modified Paths:
--------------
code/stage/branches/release-2-1-patches/src/p_driver.cc
code/stage/branches/release-2-1-patches/src/p_driver.h
code/stage/branches/release-2-1-patches/src/p_graphics2d.cc
Property Changed:
----------------
code/stage/branches/release-2-1-patches/worlds/
Modified: code/stage/branches/release-2-1-patches/src/p_driver.cc
===================================================================
--- code/stage/branches/release-2-1-patches/src/p_driver.cc 2008-04-07
20:19:49 UTC (rev 6280)
+++ code/stage/branches/release-2-1-patches/src/p_driver.cc 2008-04-07
20:36:57 UTC (rev 6281)
@@ -506,7 +506,7 @@
// subscribe to a device
-int StgDriver::Subscribe(player_devaddr_t addr)
+int StgDriver::Subscribe(QueuePointer &queue, player_devaddr_t addr)
{
if( addr.interf == PLAYER_SIMULATION_CODE )
return 0; // ok
@@ -516,16 +516,19 @@
if( device )
{
stg_model_subscribe( device->mod );
- return Driver::Subscribe(addr);
+ int result = Driver::Subscribe(addr);
+ if ( result != 0 )
+ return result;
+ return device->Subscribe(queue, addr);
}
puts( "failed to find a device" );
- return 1; // error
+ return -1; // error
}
// unsubscribe to a device
-int StgDriver::Unsubscribe(player_devaddr_t addr)
+int StgDriver::Unsubscribe(QueuePointer &queue, player_devaddr_t addr)
{
if( addr.interf == PLAYER_SIMULATION_CODE )
return 0; // ok
@@ -535,10 +538,13 @@
if( device )
{
stg_model_unsubscribe( device->mod );
- return Driver::Unsubscribe(addr);
+ int result = Driver::Unsubscribe(addr);
+ if ( result != 0 )
+ return result;
+ return device->Unsubscribe(queue, addr);
}
else
- return 1; // error
+ return -1; // error
}
StgDriver::~StgDriver()
Modified: code/stage/branches/release-2-1-patches/src/p_driver.h
===================================================================
--- code/stage/branches/release-2-1-patches/src/p_driver.h 2008-04-07
20:19:49 UTC (rev 6280)
+++ code/stage/branches/release-2-1-patches/src/p_driver.h 2008-04-07
20:36:57 UTC (rev 6281)
@@ -30,8 +30,8 @@
virtual int ProcessMessage(QueuePointer &resp_queue,
player_msghdr * hdr,
void * data);
- virtual int Subscribe(player_devaddr_t addr);
- virtual int Unsubscribe(player_devaddr_t addr);
+ virtual int Subscribe(QueuePointer &queue, player_devaddr_t addr);
+ virtual int Unsubscribe(QueuePointer &queue, player_devaddr_t addr);
/// The server thread calls this method frequently. We use it to
/// check for new commands and configs
@@ -76,6 +76,9 @@
player_msghdr_t* hdr,
void* data) { return(-1); } // empty implementation
virtual void Publish( void ){}; // empty implementation
+
+ virtual int Subscribe(QueuePointer &queue, player_devaddr_t addr) { return
0; }
+ virtual int Unsubscribe(QueuePointer &queue, player_devaddr_t addr) { return
0; }
};
@@ -285,6 +288,14 @@
void * data );
};
+#define INTERFACE_GRAPHICS_2D_MAX_CLIENTS 16
+
+struct Graphics2dFig
+{
+ QueuePointer queue;
+ stg_rtk_fig_t* stageFig;
+};
+
class InterfaceGraphics2d : public InterfaceModel
{
public:
@@ -294,8 +305,12 @@
virtual int ProcessMessage( QueuePointer &resp_queue,
player_msghdr * hdr,
void * data );
+
+ // Override subscribe and unsubscribe to handle each client separately.
+ virtual int Subscribe(QueuePointer &queue, player_devaddr_t addr);
+ virtual int Unsubscribe(QueuePointer &queue, player_devaddr_t addr);
private:
- stg_rtk_fig_t* fig; // a figure we can draw in
+ Graphics2dFig figs[INTERFACE_GRAPHICS_2D_MAX_CLIENTS]; // a figure we can
draw in
};
Modified: code/stage/branches/release-2-1-patches/src/p_graphics2d.cc
===================================================================
--- code/stage/branches/release-2-1-patches/src/p_graphics2d.cc 2008-04-07
20:19:49 UTC (rev 6280)
+++ code/stage/branches/release-2-1-patches/src/p_graphics2d.cc 2008-04-07
20:36:57 UTC (rev 6281)
@@ -56,18 +56,15 @@
int section )
: InterfaceModel( addr, driver, cf, section, NULL )
{
- // get or create a nice clean figure for drawing
- this->fig = stg_model_get_fig( mod, "g2d_fig" );
-
- if( ! this->fig )
- this->fig = stg_model_fig_create( mod, "g2d_fig", "top", 99 );
-
- stg_rtk_fig_clear( this->fig );
+ for (int i = 0; i < INTERFACE_GRAPHICS_2D_MAX_CLIENTS; i++)
+ figs[i].queue = QueuePointer(); // Set to NULL
}
InterfaceGraphics2d::~InterfaceGraphics2d( void )
{
- stg_rtk_fig_clear( this->fig );
+ for (int i = 0; i < INTERFACE_GRAPHICS_2D_MAX_CLIENTS; i++)
+ if ( this->figs[i].queue != NULL ) // Find the client
+ stg_rtk_fig_clear( this->figs[i].stageFig ); // Clear the figure
};
@@ -76,13 +73,24 @@
void* data)
{
// printf( "Stage graphics2d interface processing message\n" );
+
+ // Find the index of the client.
+ int index;
+ for ( index = 0; index < INTERFACE_GRAPHICS_2D_MAX_CLIENTS; index++ )
+ if ( this->figs[index].queue == resp_queue )
+ break;
+ if ( index >= INTERFACE_GRAPHICS_2D_MAX_CLIENTS )
+ {
+ PLAYER_ERROR("Graphics 2d received message from client that was not
subscribed");
+ return 0;
+ }
if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
PLAYER_GRAPHICS2D_CMD_CLEAR,
this->addr))
{
- //puts( "g2d: clearing figure" );
- stg_rtk_fig_clear( this->fig );
+ puts( "g2d: clearing figure" );
+ stg_rtk_fig_clear( this->figs[index].stageFig );
return 0; //ok
}
@@ -93,12 +101,12 @@
player_graphics2d_cmd_points_t* pcmd =
(player_graphics2d_cmd_points_t*)data;
- stg_rtk_fig_color_rgb32( this->fig, rgb32_pack( &pcmd->color) );
+ stg_rtk_fig_color_rgb32( this->figs[index].stageFig, rgb32_pack(
&pcmd->color) );
for(unsigned int p=0; p<pcmd->points_count; p++ )
{
//printf( "g2d: Drawing point %.2f %.2f\n", pcmd->points[p].px,
pcmd->points[p].py );
- stg_rtk_fig_point( this->fig,
+ stg_rtk_fig_point( this->figs[index].stageFig,
pcmd->points[p].px,
pcmd->points[p].py );
}
@@ -112,7 +120,7 @@
player_graphics2d_cmd_polyline_t* pcmd =
(player_graphics2d_cmd_polyline_t*)data;
- stg_rtk_fig_color_rgb32( this->fig, rgb32_pack( &pcmd->color) );
+ stg_rtk_fig_color_rgb32( this->figs[index].stageFig, rgb32_pack(
&pcmd->color) );
if( pcmd->points_count > 1 )
for(unsigned int p=0; p<pcmd->points_count-1; p++ )
@@ -121,7 +129,7 @@
// pcmd->points[p].px, pcmd->points[p].py,
// pcmd->points[p+1].px, pcmd->points[p+1].py );
- stg_rtk_fig_line( this->fig,
+ stg_rtk_fig_line( this->figs[index].stageFig,
pcmd->points[p].px,
pcmd->points[p].py,
pcmd->points[p+1].px,
@@ -153,16 +161,16 @@
if( pcmd->filled )
{
- stg_rtk_fig_color_rgb32( this->fig, rgb32_pack( &pcmd->fill_color));
- stg_rtk_fig_polygon( this->fig,
+ stg_rtk_fig_color_rgb32( this->figs[index].stageFig, rgb32_pack(
&pcmd->fill_color));
+ stg_rtk_fig_polygon( this->figs[index].stageFig,
0,0,0,
pcmd->points_count,
pts,
TRUE );
}
- stg_rtk_fig_color_rgb32( this->fig, rgb32_pack( &pcmd->color) );
- stg_rtk_fig_polygon( this->fig,
+ stg_rtk_fig_color_rgb32( this->figs[index].stageFig, rgb32_pack(
&pcmd->color) );
+ stg_rtk_fig_polygon( this->figs[index].stageFig,
0,0,0,
pcmd->points_count,
pts,
@@ -175,3 +183,68 @@
hdr->type, hdr->subtype );
return -1;
}
+
+int InterfaceGraphics2d::Subscribe(QueuePointer &queue, player_devaddr_t addr)
+{
+ int result = InterfaceModel::Subscribe(queue, addr);
+ if (result != 0)
+ return result;
+
+ if (queue == NULL) // Always on subscription.
+ return 0;
+
+ // Find an index for the new client.
+ int index;
+ for (index = 0; index < INTERFACE_GRAPHICS_2D_MAX_CLIENTS; index++)
+ {
+ if (figs[index].queue == queue)
+ {
+ PLAYER_ERROR("Client subscribed to graphics2d twice");
+ return -1;
+ }
+ if (figs[index].queue == NULL) // Found an empty position.
+ break;
+ }
+
+ if (index >= INTERFACE_GRAPHICS_2D_MAX_CLIENTS)
+ {
+ PLAYER_ERROR("Too many clients subscribed to graphics 2d");
+ return -1;
+ }
+
+ // Take over position.
+ figs[index].queue = queue;
+
+ char figname[10];
+ snprintf(figname, 10, "g2d_fig%d", index); // Name the figures g2d_fig0
through g2d_fign.
+
+ // Get or create a nice clean figure for the client to draw on.
+ figs[index].stageFig = stg_model_fig_get_or_create( mod, figname,
"top", 99 );
+ stg_rtk_fig_clear( figs[index].stageFig );
+
+ return 0;
+}
+
+int InterfaceGraphics2d::Unsubscribe(QueuePointer &queue, player_devaddr_t
addr)
+{
+ if (queue == NULL)
+ return InterfaceModel::Unsubscribe(queue, addr);
+
+ int index;
+ for (index = 0; index < INTERFACE_GRAPHICS_2D_MAX_CLIENTS; index++)
+ {
+ if (figs[index].queue == queue)
+ break;
+ }
+
+ if (index >= INTERFACE_GRAPHICS_2D_MAX_CLIENTS)
+ {
+ PLAYER_ERROR("Client unsubscribed without subscribing");
+ return -1;
+ }
+
+ stg_rtk_fig_clear( figs[index].stageFig );
+ figs[index].queue = QueuePointer(); // Set to NULL.
+
+ return InterfaceModel::Unsubscribe(queue, addr);
+}
Property changes on: code/stage/branches/release-2-1-patches/worlds
___________________________________________________________________
Name: svn:ignore
- Makefile
Makefile.in
+ Makefile
Makefile.in
.player
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit