Update of /cvsroot/playerstage/code/stage/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26052
Modified Files:
Makefile.am gui.h model.c model_load.c p_driver.cc p_driver.h
p_simulation.cc rtk.h rtk_fig.c rtkprivate.h stage.h
stage_internal.h typetable.c
Added Files:
dijkstra.c dijkstra.h model_audio.c p_audio.cc
Log Message:
added audio model and its player driver
Index: rtkprivate.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/rtkprivate.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rtkprivate.h 11 Mar 2005 21:56:57 -0000 1.3
--- rtkprivate.h 27 Jul 2006 02:33:02 -0000 1.4
***************
*** 77,80 ****
--- 77,81 ----
extern void stg_rtk_fig_dirty(stg_rtk_fig_t *fig);
extern void stg_rtk_fig_calc(stg_rtk_fig_t *fig);
+ extern void stg_rtk_fig_calc_selection(stg_rtk_fig_t *fig);
extern void stg_rtk_fig_render(stg_rtk_fig_t *fig);
extern void stg_rtk_fig_render_xfig(stg_rtk_fig_t *fig);
--- NEW FILE: dijkstra.h ---
#ifndef _DIJKSTRA_H_
#define _DIJKSTRA_H_
#include <glib.h>
//void initialize_dijkstra_d (int u, GList *vs, GHashTable *d);
//void find_shortest_paths (GHashTable* adjacency, GHashTable* d, GHashTable*
previous);
void dijkstra_init();
void dijkstra_destroy();
//void dijkstra_set_graph_size(int n);
//void dijkstra_remove_edges_from(int u);
//void dijkstra_remove_edges_to(int u);
//void dijkstra_remove_edges_gte(int u);
//void dijkstra_insert_edge(int u, int v, double w);
void dijkstra_insert_edge(int u, int v, double w, gboolean temp_edge);
//void dijkstra_insert_tmp_edge(int u, int v, double w);
void dijkstra_remove_temp_edges();
void dijkstra_run();
GHashTable *dijkstra_adjacency;
GHashTable *dijkstra_previous;
GHashTable *dijkstra_d;
#endif
--- NEW FILE: p_audio.cc ---
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2004, 2005 Richard Vaughan
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* Desc: Audio player driver
* Author: Pooya Karimian
* Date: 24 April 2006
* CVS: $Id $
*/
#include "p_driver.h"
typedef struct {
char string[256];
} test_t;
/** @addtogroup player
@par Audio interface
- PLAYER_OPAQUE_CMD
- PLAYER_OPAQUE_DATA_STATE
*/
extern "C" {
int audio_init(stg_model_t * mod);
} InterfaceAudio::InterfaceAudio(player_devaddr_t addr,
StgDriver * driver,
ConfigFile * cf, int section)
:InterfaceModel(addr, driver, cf, section, audio_init)
{
// TODO: alwayson?
// driver->alwayson = TRUE;
}
void InterfaceAudio::Publish(void)
{
stg_audio_data_t *sdata = (stg_audio_data_t *) mod->data;
assert(sdata);
player_opaque_data_t pdata;
memset(&pdata, 0, sizeof(pdata));
// Translate the Stage-formatted sdata into the Player-formatted pdata
// sprintf((char *)pdata.data,"Hello\n");
test_t *mTestStruct;
pdata.data_count = sizeof(test_t);
mTestStruct = reinterpret_cast < test_t * >(pdata.data);
sprintf(mTestStruct->string, "%s", sdata->recv);
// uint size = sizeof(pdata) - sizeof(pdata.data) + pdata.data_count;
// Publish it
this->driver->Publish(this->addr, NULL,
PLAYER_MSGTYPE_DATA,
PLAYER_OPAQUE_DATA_STATE,
(void *) &pdata, sizeof(pdata), NULL);
}
int InterfaceAudio::ProcessMessage(MessageQueue * resp_queue,
player_msghdr_t * hdr, void *data)
{
// PROCESS INCOMING REQUESTS HERE
// if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
if (Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
PLAYER_OPAQUE_CMD, this->addr)) {
if (hdr->size == sizeof(player_opaque_data_t)) {
player_opaque_data_t *pcmd = (player_opaque_data_t *) data;
// Pass it to stage:
stg_audio_cmd_t cmd;
// cmd.cmd = STG_SPEECH_CMD_NOP;
// cmd.string[0] = 0;
cmd.cmd = STG_AUDIO_CMD_SAY;
// strncpy(cmd.string, pcmd->string, STG_AUDIO_MAX_STRING_LEN);
strncpy(cmd.string, (char *) pcmd->data,
STG_AUDIO_MAX_STRING_LEN);
cmd.string[STG_AUDIO_MAX_STRING_LEN - 1] = 0;
stg_model_set_cmd(this->mod, &cmd, sizeof(cmd));
} else
PRINT_ERR2("wrong size audio command packet (%d/%d bytes)",
(int) hdr->size,
(int) sizeof(player_opaque_data_t));
return 0;
}
/*
// is it a geometry request?
if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
PLAYER_GRIPPER_REQ_GET_GEOM,
this->addr))
{
// TODO: get pose in top-level model's CS instead.
stg_geom_t geom;
stg_model_get_geom( this->mod, &geom );
stg_pose_t pose;
stg_model_get_pose( this->mod, &pose);
player_gripper_geom_t pgeom;
pgeom.pose.px = pose.x;
pgeom.pose.py = pose.y;
pgeom.pose.pa = pose.a;
pgeom.size.sw = geom.size.y;
pgeom.size.sl = geom.size.x;
this->driver->Publish(this->addr, resp_queue,
PLAYER_MSGTYPE_RESP_ACK,
PLAYER_GRIPPER_REQ_GET_GEOM,
(void*)&pgeom, sizeof(pgeom), NULL);
return(0);
}
*/
PRINT_WARN2("stage audio doesn't support message id:%d/%d",
hdr->type, hdr->subtype);
return -1;
}
--- NEW FILE: model_audio.c ---
///////////////////////////////////////////////////////////////////////////
//
// File: model_audio.c
// Authors: Pooya Karimian
// Date: July 24 2006
//
// CVS info:
// $Source: /cvsroot/playerstage/code/stage/src/model_audio.c,v $
// $Author: pooya $
// $Revision: 1.1 $
//
///////////////////////////////////////////////////////////////////////////
/**
@ingroup model
@defgroup model_audio Audio model
<b>WARNING:</b> This is an experimental implementation. Any aspect of model,
implementation, messages, and world file properties may change in future.
[...1317 lines suppressed...]
*/
// unrender the data
// stg_model_fig_clear(mod, "audio_data_fig");
return 0; // ok
}
int audio_unrender_data(stg_model_t * mod, void *userp)
{
// CLEAR STUFF THAT YOU DREW
// stg_model_fig_clear(mod, "audio_data_fig");
return 1; // callback just runs one time
}
int audio_unrender_cfg(stg_model_t * mod, void *userp)
{
// CLEAR
stg_model_fig_clear(mod, "audio_cfg_fig");
return 1; // callback just runs one time
}
Index: rtk_fig.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/rtk_fig.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** rtk_fig.c 4 Apr 2006 22:11:15 -0000 1.20
--- rtk_fig.c 27 Jul 2006 02:33:02 -0000 1.21
***************
*** 198,202 ****
{
//printf( "destroying fig %p\n", fig );
!
// remove any glib sources that might access this figure (such as
--- 198,202 ----
{
//printf( "destroying fig %p\n", fig );
!
// remove any glib sources that might access this figure (such as
***************
*** 219,229 ****
STK_LIST_REMOVEX(fig->canvas->layer_fig, layer, fig);
! // Free the strokes
stg_rtk_fig_clear(fig);
free(fig->strokes);
// Clear the dirty regions
stg_rtk_region_destroy(fig->region);
!
free(fig);
}
--- 219,232 ----
STK_LIST_REMOVEX(fig->canvas->layer_fig, layer, fig);
! // Free the strokes
stg_rtk_fig_clear(fig);
+
+ //TODO: causing seg faults? run stest then close stage window. (pooya)
free(fig->strokes);
// Clear the dirty regions
stg_rtk_region_destroy(fig->region);
!
! // TODO: freeing figures twice?! (pooya)
free(fig);
}
***************
*** 987,996 ****
// draw the text
! stg_rtk_fig_text_alloc(fig, lx , ly , oa, text, &width, &height);
// draw the bubble
stg_rtk_point_t points[30];
! double tx = width * fig->canvas->sx;
! double ty = height * fig->canvas->sy;
for (int i = 1; i <= 24 ; i++)
--- 990,1000 ----
// draw the text
! // TODO: make it change direction if bx<0 or by<0 (pooya)
! stg_rtk_fig_text_alloc(fig, lx+ox , ly+oy , oa, text, &width, &height);
// draw the bubble
stg_rtk_point_t points[30];
! double tx = width * fig->canvas->sx * (bx<0?-1.0:1.0);
! double ty = height * fig->canvas->sy * (by<0?-1.0:1.0);
for (int i = 1; i <= 24 ; i++)
***************
*** 1753,1754 ****
--- 1757,1774 ----
g_source_remove_by_user_data( fig );
}
+
+
+ int stg_rtk_fig_destroy_later_callback( stg_rtk_fig_t* fig )
+ {
+ assert( fig );
+ stg_rtk_fig_destroy( fig );
+
+ return FALSE;
+ }
+
+
+ void stg_rtk_fig_destroy_later( stg_rtk_fig_t* fig, int life_ms )
+ {
+ assert( fig );
+ g_timeout_add( (guint)life_ms, (GSourceFunc)
(stg_rtk_fig_destroy_later_callback), fig );
+ }
Index: model_load.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/model_load.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** model_load.c 25 Mar 2006 01:15:47 -0000 1.8
--- model_load.c 27 Jul 2006 02:33:02 -0000 1.9
***************
*** 115,118 ****
--- 115,125 ----
stg_model_set_gripper_return( mod, grp );
}
+
+ if( wf_property_exists( mod->id, "audio_return" ))
+ {
+ int aud =
+ wf_read_int( mod->id, "audio_return", mod->audio_return );
+ stg_model_set_audio_return( mod, aud );
+ }
if( wf_property_exists( mod->id, "boundary" ))
Index: p_driver.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/p_driver.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** p_driver.h 29 Mar 2006 05:11:00 -0000 1.21
--- p_driver.h 27 Jul 2006 02:33:02 -0000 1.22
***************
*** 145,148 ****
--- 145,159 ----
};
+ class InterfaceAudio : public InterfaceModel
+ {
+ public:
+ InterfaceAudio( player_devaddr_t addr, StgDriver* driver, ConfigFile* cf,
int section );
+ virtual ~InterfaceAudio( void ){ /* TODO: clean up*/ };
+ virtual int ProcessMessage(MessageQueue* resp_queue,
+ player_msghdr_t* hdr,
+ void* data);
+ virtual void Publish( void );
+ };
+
class InterfaceLaser : public InterfaceModel
{
Index: stage_internal.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/stage_internal.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** stage_internal.h 25 May 2006 21:35:01 -0000 1.58
--- stage_internal.h 27 Jul 2006 02:33:02 -0000 1.59
***************
*** 209,212 ****
--- 209,213 ----
int blob_return;
int gripper_return;
+ int audio_return;
int ranger_return;
int fiducial_return;
Index: stage.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/stage.h,v
retrieving revision 1.189
retrieving revision 1.190
diff -C2 -d -r1.189 -r1.190
*** stage.h 25 May 2006 21:35:01 -0000 1.189
--- stage.h 27 Jul 2006 02:33:02 -0000 1.190
***************
*** 571,574 ****
--- 571,575 ----
void stg_model_set_stall( stg_model_t* mod, stg_bool_t stall );
void stg_model_set_gripper_return( stg_model_t* mod, int val );
+ void stg_model_set_audio_return( stg_model_t* mod, int val );
void stg_model_set_laser_return( stg_model_t* mod, int val );
void stg_model_set_obstacle_return( stg_model_t* mod, int val );
***************
*** 595,598 ****
--- 596,600 ----
#define STG_MP_RANGER_RETURN "_mp_ranger_return"
#define STG_MP_GRIPPER_RETURN "_mp_gripper_return"
+ #define STG_MP_AUDIO_RETURN "_mp_audio_return"
#define STG_MP_MASS "_mp_mass"
***************
*** 1102,1105 ****
--- 1104,1143 ----
} stg_speech_cmd_t;
+ // AUDIO MODEL --------------------------------------------------------
+
+ #define STG_AUDIO_MAX_STRING_LEN 256
+
+ typedef enum {
+ STG_AUDIO_CMD_NOP = 0, // default state
+ STG_AUDIO_CMD_SAY
+ } stg_audio_cmd_type_t;
+
+ /** audio configuration packet
+ */
+ typedef struct
+ {
+ char string[STG_AUDIO_MAX_STRING_LEN];
+ char say_string[STG_AUDIO_MAX_STRING_LEN];
+ stg_msec_t say_period;
+ stg_msec_t say_last_time;
+ } stg_audio_config_t;
+
+ /** audio data packet
+ */
+ typedef struct
+ {
+ char string[STG_AUDIO_MAX_STRING_LEN];
+ char recv[STG_AUDIO_MAX_STRING_LEN];
+ GList *audio_paths;
+ } stg_audio_data_t;
+
+ /** audio command packet
+ */
+ typedef struct
+ {
+ stg_audio_cmd_type_t cmd;
+ char string[STG_AUDIO_MAX_STRING_LEN];
+ } stg_audio_cmd_t;
+
// end the group of all models
/[EMAIL PROTECTED]/
Index: p_driver.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/p_driver.cc,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** p_driver.cc 29 Mar 2006 05:11:00 -0000 1.37
--- p_driver.cc 27 Jul 2006 02:33:02 -0000 1.38
***************
*** 398,401 ****
--- 398,405 ----
break;
+ case PLAYER_OPAQUE_CODE:
+ ifsrc = new InterfaceAudio( player_addr, this, cf, section );
+ break;
+
case PLAYER_BUMPER_CODE:
ifsrc = new InterfaceBumper( player_addr, this, cf, section );
Index: gui.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/gui.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** gui.h 29 Mar 2006 05:11:00 -0000 1.35
--- gui.h 27 Jul 2006 02:33:02 -0000 1.36
***************
*** 94,95 ****
--- 94,99 ----
#define STG_LAYER_SPEECHDATA 88
#define STG_SPEECH_COLOR "navy"
+
+ #define STG_LAYER_AUDIODATA 84
+ #define STG_AUDIO_COLOR "orange3"
+ #define STG_AUDIO_BUBBLE_COLOR "orange4"
Index: Makefile.am
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/Makefile.am,v
retrieving revision 1.140
retrieving revision 1.141
diff -C2 -d -r1.140 -r1.141
*** Makefile.am 25 May 2006 21:35:01 -0000 1.140
--- Makefile.am 27 Jul 2006 02:33:02 -0000 1.141
***************
*** 52,55 ****
--- 52,58 ----
model_wifi.cc \
model_speech.c \
+ model_audio.c \
+ dijkstra.c \
+ dijkstra.h \
raytrace.c \
stage.c \
***************
*** 94,97 ****
--- 97,101 ----
p_wifi.cc \
p_speech.cc \
+ p_audio.cc \
p_sonar.cc \
p_graphics2d.cc \
Index: p_simulation.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/p_simulation.cc,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** p_simulation.cc 30 May 2006 20:10:00 -0000 1.16
--- p_simulation.cc 27 Jul 2006 02:33:02 -0000 1.17
***************
*** 37,40 ****
--- 37,41 ----
- "laser_return" 0-2
- "gripper_return" 0-1
+ - "audio_return" 0-1
- "ranger_return" 0-1
- "obstacle_return" 0-1
Index: rtk.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/rtk.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** rtk.h 24 Mar 2006 20:12:42 -0000 1.16
--- rtk.h 27 Jul 2006 02:33:02 -0000 1.17
***************
*** 416,419 ****
--- 416,423 ----
void stg_rtk_fig_destroy(stg_rtk_fig_t *fig);
+ // destroy figure after at least life_ms milliseconds
+ void stg_rtk_fig_destroy_later( stg_rtk_fig_t* fig, int life_ms );
+
+
// Recursively free a whole tree of figures (rtv)
void stg_rtk_fig_and_descendents_destroy( stg_rtk_fig_t* fig );
--- NEW FILE: dijkstra.c ---
/*
* dijkstra.c - C implementation of Dijkstra's shortest path algorithm.
* Changed to fit for use in audio model of Stage
*
* Copyright (C) 2005-2006 W. Evan Sheehan
* Copyright (C) 2006 Pooya Karimian
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "dijkstra.h"
typedef struct {
int node;
double weight;
gboolean temp;
} dijkstra_node;
double *double_dup(const double d)
{
double *r = (double *) malloc(sizeof(double));
*r = d;
return r;
}
void initialize_dijkstra_d(int u, GList * vs, GHashTable * d)
{
// g_hash_table_insert (d, u, GINT_TO_POINTER (-1));
g_hash_table_insert(d, GINT_TO_POINTER(u), double_dup(INFINITY));
}
static void add_to_queue(int u, GList * vs, GQueue * q)
{
g_queue_push_head(q, GINT_TO_POINTER(u));
}
/* Comparison function for sorting the agenda queue for Dijkstra's algorithm.
*/
static gint dijkstra_compare(int u, int v, GHashTable * d)
{
// gint u_cost = GPOINTER_TO_INT (g_hash_table_lookup (d,
GINT_TO_POINTER(u)));
// gint v_cost;
double *u_cost = g_hash_table_lookup(d, GINT_TO_POINTER(u));
double *v_cost;
/* If u is infinity, put it after v in the queue */
if (u_cost == NULL)
return 1;
if (*u_cost >= INFINITY) {
return 1;
}
// v_cost = GPOINTER_TO_INT (g_hash_table_lookup (d, GINT_TO_POINTER(v)));
v_cost = g_hash_table_lookup(d, GINT_TO_POINTER(v));
/* If v is infinitiy, put it after u. Otherwise, compare the costs
* directly.
*/
if (v_cost == NULL)
return 1;
// if (v_cost == -1) {
if (*v_cost >= INFINITY) {
return -1;
} else if (*u_cost > *v_cost) {
return 1;
} else if (*u_cost == *v_cost) {
return 0;
}
return -1;
}
static GQueue *build_dijkstra_queue(GHashTable * adjacency, GHashTable * d)
{
GQueue *q = g_queue_new();
g_hash_table_foreach(adjacency, (GHFunc) add_to_queue, q);
g_queue_sort(q, (GCompareDataFunc) dijkstra_compare, d);
return q;
}
/* Update the table of shortest path estimates. If the path that ends with the
* edge (u,v) is shorter than the currently stored path to v, replace the cost
* in d with the new cost, and replace the old value of previous[v] with u.
*/
static void
relax(GHashTable * d, GHashTable * previous, int u, int v, double w)
{
/*
gint u_cost = GPOINTER_TO_INT (g_hash_table_lookup (d,
GINT_TO_POINTER(u)));
gint v_cost = GPOINTER_TO_INT (g_hash_table_lookup (d,
GINT_TO_POINTER(v)));
if (v_cost == -1 || v_cost > u_cost + 1) {
g_hash_table_insert (d, GINT_TO_POINTER(v), GINT_TO_POINTER
(u_cost + 1));
g_hash_table_insert (previous, GINT_TO_POINTER(v),
GINT_TO_POINTER(u));
}
*/
double *u_cost = g_hash_table_lookup(d, GINT_TO_POINTER(u));
double *v_cost = g_hash_table_lookup(d, GINT_TO_POINTER(v));
if (!u_cost)
u_cost = double_dup(INFINITY);
if (!v_cost)
v_cost = double_dup(INFINITY);
if ((*v_cost >= INFINITY) || ((*v_cost) > (*u_cost) + w)) {
g_hash_table_insert(d, GINT_TO_POINTER(v),
double_dup((*u_cost) + w));
g_hash_table_insert(previous, GINT_TO_POINTER(v),
GINT_TO_POINTER(u));
}
}
/* The meat of Dijkstra's algorithm is here. */
void
find_shortest_paths(GHashTable * adjacency, GHashTable * d,
GHashTable * previous)
{
// GSList *S = NULL;
GQueue *agenda = build_dijkstra_queue(adjacency, d);
/* Go through each node and calculate path costs */
while (!g_queue_is_empty(agenda)) {
/* Next node */
int u = GPOINTER_TO_INT(g_queue_pop_head(agenda));
/* Nodes connected to the current node */
GList *vs =
(GList *) g_hash_table_lookup(adjacency, GINT_TO_POINTER(u));
// printf("-GL- %p\n",vs);
// fflush(stdout);
// printf(" -GL#- %d\n", g_slist_length(vs));
// fflush(stdout);
/* Add the current node to the list of visited nodes */
// S = g_slist_prepend (S, GINT_TO_POINTER(u));
/* For each connected node update path costs */
for (GList * v = vs; v; v = g_list_next(v)) {
// printf(" -V- %p\n",v);
// fflush(stdout);
dijkstra_node *vptr = (dijkstra_node *) v->data;
// printf(" -VP- %p
(%d,%f)\n",vptr,vptr->node,vptr->weight);
// printf(" -VN- %p\n",g_slist_next(v));
// fflush(stdout);
// if (vptr!=NULL)
// printf(" -1-\n");
// fflush(stdout);
relax(d, previous, u, vptr->node, vptr->weight);
// printf(" -2-\n");
// fflush(stdout);
// printf(" -3-\n");
// fflush(stdout);
}
/* Re-sort the queue so that the node with the minimum cost is
* in front
*/
g_queue_sort(agenda, (GCompareDataFunc) dijkstra_compare, d);
}
/* Clean up */
// g_slist_free (S);
g_queue_free(agenda);
}
void double_destroy(double *d)
{
// printf("double_destory: %p\n");
free(d);
}
void dijkstra_init()
{
/* Shortest path estimate */
dijkstra_previous = g_hash_table_new(g_direct_hash, g_direct_equal);
dijkstra_adjacency = g_hash_table_new(g_direct_hash, g_direct_equal);
dijkstra_d =
g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
(GDestroyNotify) double_destroy);
}
void dijkstra_destroy()
{
/* Clean up */
g_hash_table_destroy(dijkstra_d);
g_hash_table_destroy(dijkstra_previous);
// TODO: clean up
// free_adjacency (adjacency);
}
void dijkstra_remove_temp_edges2(gpointer key, GList * vs, gpointer adj)
{
// printf("%d (%d): ",GPOINTER_TO_INT(key), g_list_length(vs));
// g_list_foreach(adj, (GFunc)dijkstra_remove_temp_edge, adj);
// while(((dijkstra_node*)adj->data)->temp) {
while (vs) {
dijkstra_node *vptr = (dijkstra_node *) vs->data;
if (!vptr->temp)
break;
//printf("%c",vptr->temp?'T':'.');
// GList *tmp=g_list_next(vs);
// vs=tmp;
free(vptr);
vs = g_list_delete_link(vs, vs);
}
// printf("\n");
// fflush(stdout);
g_hash_table_replace(adj, GINT_TO_POINTER(key), vs);
}
void dijkstra_remove_temp_edges()
{
g_hash_table_foreach(dijkstra_adjacency,
(GHFunc) dijkstra_remove_temp_edges2,
dijkstra_adjacency);
}
void dijkstra_insert_edge(int u, int v, double w, gboolean temp_edge)
{
GList *vs = (GList *) g_hash_table_lookup(dijkstra_adjacency,
GINT_TO_POINTER(u));
dijkstra_node *vptr = (dijkstra_node *) malloc(sizeof(dijkstra_node));
vptr->node = v;
vptr->weight = w;
vptr->temp = temp_edge;
// printf("list adding pointer: %p\n",vptr);
// printf("list before: %p\n",vs);
vs = g_list_prepend(vs, vptr);
// printf("list after: %p\n",vs);
// fflush(stdout);
g_hash_table_replace(dijkstra_adjacency, GINT_TO_POINTER(u), vs);
// if (temp_edge) {
// g_slist_prepend(dijkstra_temp_edges, vs);
// }
}
void dijkstra_free_d(int u, double *dist, gpointer junk)
{
free(dist);
}
void dijkstra_run()
{
/* Initialize shortest path estimates */
// g_hash_table_foreach(dijkstra_d, dijkstra_free_d, NULL);
g_hash_table_destroy(dijkstra_d);
// dijkstra_d = g_hash_table_new (g_direct_hash, g_direct_equal);
dijkstra_d =
g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
(GDestroyNotify) double_destroy);
g_hash_table_foreach(dijkstra_adjacency,
(GHFunc) initialize_dijkstra_d, dijkstra_d);
// start node is connected to start node with 0 distance
g_hash_table_insert(dijkstra_d, GINT_TO_POINTER(0), double_dup(0.0));
find_shortest_paths(dijkstra_adjacency, dijkstra_d, dijkstra_previous);
}
Index: model.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/model.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -C2 -d -r1.153 -r1.154
*** model.c 25 May 2006 21:35:01 -0000 1.153
--- model.c 27 Jul 2006 02:33:02 -0000 1.154
***************
*** 82,85 ****
--- 82,86 ----
fiducial_return 1
gripper_return 0
+ audio_return 0
fiducial_key 0
***************
*** 144,147 ****
--- 145,151 ----
- gripper_return [bool]
- iff 1, this model can be gripped by a gripper and can be pushed around
by collisions with anything that has a non-zero obstacle_return.
+ - audio_return [bool]
+ - if 1, this model will be an obstacle to audio and will be used to
precalculate the audio paths.
+ <b>warning: don't use this for moving objects</b>
*/
***************
*** 205,208 ****
--- 209,213 ----
void* user )
{
+ // TODO: free it somewhere or don't allocate it (pooya)
int* key = malloc(sizeof(int));
*key = address - (void*)mod;
***************
*** 394,397 ****
--- 399,403 ----
mod->laser_return = LaserVisible;
mod->gripper_return = 0;
+ mod->audio_return = 0;
mod->boundary = 0;
mod->color = 0xFF0000; // red;
***************
*** 960,963 ****
--- 966,976 ----
}
+ void stg_model_set_audio_return( stg_model_t* mod, int val )
+ {
+ assert(mod);
+ mod->audio_return = val;
+ model_change( mod, &mod->audio_return );
+ }
+
void stg_model_set_fiducial_return( stg_model_t* mod, int val )
{
***************
*** 1614,1617 ****
--- 1627,1635 ----
return 0;
}
+ if( ISPROP( name, STG_MP_AUDIO_RETURN ) )
+ {
+ stg_model_set_audio_return( mod, *(int*)value );
+ return 0;
+ }
if( ISPROP( name, STG_MP_COLOR ) )
{
Index: typetable.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/typetable.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** typetable.c 29 Mar 2006 05:11:00 -0000 1.8
--- typetable.c 27 Jul 2006 02:33:02 -0000 1.9
***************
*** 14,17 ****
--- 14,18 ----
int wifi_init( stg_model_t* mod );
int speech_init( stg_model_t* mod );
+ int audio_init( stg_model_t* mod );
int bumper_init( stg_model_t* mod );
***************
*** 30,33 ****
--- 31,35 ----
{ "wifi", wifi_init },
{ "speech", speech_init },
+ { "audio", audio_init },
{ "bumper", bumper_init },
{ NULL, 0, NULL } // this must be the last entry
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit