📄 uevents.c
字号:
/****************************************************************************** uevents.c -- ** OpenGVS software responsible for responding to * device and window manager related events******************************************************************************/#include <g_sys.h>#include <string.h>#include <ctype.h>#include <g_key.h>#include <g_timer.h>#include <gv_cam.h>#include <gv_chn.h>#include <gv_geo.h>#include <gv_user.h>#include <gvu_sge.h>#include <tgifts.h>#include "train.h"#include "hostdata.h"/* Globals through this module only */static char addtext[TKUI_NCHRS_MAX];static TParse_data *tdata = NULL;static GV_Obi ownspot = NULL;static GV_Obi owntrain = NULL;/* General pointers used for opcode,data events */static int * ptr_int = NULL;static float * ptr_float = NULL;/****************************************************************************** tkui_event_user -- ** Demo specific event handler -- called from GV_user_events* inside of $GV_ROOT/gifts/tkui.c for those devices* not known to the kui facility******************************************************************************/int tkui_event_user( int device, int value ){ (void) value; /* Not used */ switch( device ) { default: break; } return G_SUCCESS;}/******************************************************************************* tkui_event_reset -- ** Demo specific reset logic -- called from * inside $GV_ROOT/gifts/tkui.c*******************************************************************************/void tkui_event_reset( int reason ){ GVU_Path path; (void) reason; GVU_path_inq_first( &path ); while( path ) { GVU_path_reset( path ); GVU_path_set_speed_scale( path, 1.0f ); GVU_path_set_state( path, G_ON ); GVU_path_inq_next( path, &path ); }}/******************************************************************************* tkui_event_change_camera -- ** Demo specific reset logic -- called from * inside $GV_ROOT/gifts/tkui.c*******************************************************************************/void tkui_event_change_camera( int reason ){ tkui_append_description( reason, ": Not implemented" );}/******************************************************************************* tkui_event_pause -- ** Pause the application (demo specific)*******************************************************************************/void tkui_event_pause( int reason, G_Boolean pause ){ pcf_pause = pause; /* Global pause setting */ if( pcf_pause ) tkui_append_description( reason, ": Paused"); else tkui_append_description( reason, "");}/******************************************************************************* tkui_event_toggle_autoplay --** Application specific callback function (called from inside* $GV_ROOT/gifts/tkui.c) to toggle autoplay (autopilot)* off and on for this application*******************************************************************************/void tkui_event_toggle_autoplay( int reason ){ tkui_append_description( reason, ": Active by default" );}/******************************************************************************* event_playback_speed --** Increase/decrease playback speed*******************************************************************************/static void event_playback_speed( int reason ){ static float delta_speed = 1.01; GVU_Path path; GVU_path_inq_first( &path ); while( path ) { float speed; GVU_path_inq_speed_scale( path, &speed ); if( reason == '>' ) speed *= delta_speed; else if( reason == '<' ) speed /= delta_speed; GVU_path_set_speed_scale( path, speed ); /* Assumption: paths are all running at the same speed so display any one should be fine for all */ sprintf( addtext, ": %.3f", speed ); GVU_path_inq_next( path, &path ); } tkui_append_description( '>', addtext );}/******************************************************************************* event_toggle_recording --** Toggle recording of owntrain data OFF and ON*******************************************************************************/static void event_toggle_recording( int reason ){ if( pcf_record ) { char * filename; static GV_Rgba white = {1.0, 1.0, 1.0, 1.0}; trecord_end(); pcf_record = G_FALSE; filename = trecord_inq_filename(); sprintf( addtext, ": saved in %s", filename ); tkui_append_description( reason, addtext ); tkui_add_color( reason, &white ); } else { static GV_Rgba magenta = {1.0, 0.0, 1.0, 1.0}; trecord_start(); pcf_record = G_TRUE; tkui_append_description( reason, ": active" ); tkui_add_color( reason, &magenta ); }}/*************************************************************************** ** event_quit --** Network related event - master says it is time to quit*****************************************************************************/static void event_quit( int reason ){ static unsigned int millisec = 100; /* Ensure slaves see the quit message */ int status; (void) reason; /* Not used */ /* Inform slaves immediately that master is quitting now */ host_data.dhd_dgd.dgd_quit = G_TRUE; dnet_master_send_data( host_data_length, &host_data ); status = dnet_master_quit() ; if( status == G_SUCCESS ) fprintf( stdout, "event_quit: Master is shutting down now.\n" ); else fprintf( stderr, "event_quit: " "Error detected while shutting down master...\n" ); G_sleep( millisec ); GV_sys_set_mode( GV_SYS_MODE_SHUTDOWN ); GV_sys_shutdown(); exit( EXIT_SUCCESS );}/******************************************************************************* mspotlight_toggle_cone_effect --** Toggle the special effect for the light cone off and on*******************************************************************************/static void mspotlight_toggle_cone_effect( int reason ){ GV_Obi spotlight_cone; G_State state; Tevent event; tspotlight_toggle_cone_effect( reason ); GV_obi_inq_by_name( TSPOTLIGHT_CONE_NAME, &spotlight_cone ); if( spotlight_cone ) { GV_obi_inq_state( spotlight_cone, &state ); /* Encode the event data for the slaves to act upon */ event.opcode = APP_EVENT_SPOTLIGHT_CONE_STATE; ptr_int = (int *)&event.data[0]; *ptr_int = state; host_data.event = event; host_data.discrete_count++; }}/****************************************************************************** mspotlight_event_toggle --** Toggle the point light special effect off/on******************************************************************************/static void mspotlight_event_toggle( int reason ){ GVU_Plsr spotlight; G_State state; Tevent event; tspotlight_event_toggle( reason ); GVU_plsr_inq_by_name( TSPOTLIGHT_NAME, &spotlight ); if( spotlight ) { GVU_plsr_inq_state( spotlight, &state ); /* Encode the event data for the slaves to act upon */ event.opcode = APP_EVENT_SPOTLIGHT_STATE; ptr_int = (int *)&event.data[0]; *ptr_int = state; host_data.event = event; host_data.discrete_count++; }}/******************************************************************************* mspotlight_heading_decrease --** Change the heading of the spotlight by changing the orientation* of the subpart on the owntrain object (the spotlight effect* is attached to this subpart)*******************************************************************************/static void mspotlight_heading_decrease( int reason ){ tspotlight_heading_decrease( reason ); if( !ownspot ) { GV_obi_inq_by_name( "OWNTRAIN", &owntrain ); GV_obi_inq_by_name_relative( owntrain, ".../spotlight", &ownspot ); } #if 0 /* Currently - the rotation angles for the spotlight are transmitted * each frame */ if( ownspot ) { G_Rotation rot; Tevent event; GV_obi_inq_rotation( ownspot, &rot ); /* Encode the event data for the slaves to act upon */ event.opcode = APP_EVENT_SPOTLIGHT_ROTATION; ptr_float = (float *)&event.data[0]; *ptr_float = rot.x; ptr_float += 1; *ptr_float = rot.y; ptr_float += 1; *ptr_float = rot.z; /* Update discrete count */ host_data.event = event; host_data.discrete_count++; } #endif}/******************************************************************************* mspotlight_heading_increase --** Change the heading of the spotlight by changing the orientation* of the subpart on the owntrain object (the spotlight effect* is attached to this subpart)*******************************************************************************/static void mspotlight_heading_increase( int reason ){ tspotlight_heading_increase( reason ); if( !ownspot ) { GV_obi_inq_by_name( "OWNTRAIN", &owntrain ); GV_obi_inq_by_name_relative( owntrain, ".../spotlight", &ownspot ); } #if 0 if( ownspot ) { G_Rotation rot; Tevent event; GV_obi_inq_rotation( ownspot, &rot ); #if DEBUG fprintf( stdout, "spotlight rotx-roty-rotz: %f %f %f\n", rot.x, rot.y, rot.z ); #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -