Esempio n. 1
0
static void remove_input_controller(
	void)
{
	remove_timer_task(input_task);
	if (replay.game_is_being_recorded)
	{
		stop_recording();
	}
	else if (replay.game_is_being_replayed)
	{
		if (replay.resource_data)
		{
			delete []replay.resource_data;
			replay.resource_data= NULL;
			replay.resource_data_size= 0l;
			replay.film_resource_offset= NONE;
		}
		else
		{
			FilmFile.Close();
		}
	}

	replay.valid= false;
}
Esempio n. 2
0
File: vbl.c Progetto: DrItanium/moo
static void remove_input_controller(
	void)
{
	remove_timer_task(input_task);
	if (replay.game_is_being_recorded)
	{
		stop_recording();
	}
	else if (replay.game_is_being_replayed)
	{
		if (replay.resource_data)
		{
			free(replay.resource_data);
			replay.resource_data= NULL;
			replay.resource_data_size= 0l;
			replay.film_resource_offset= NONE;
		}
		else
		{
			assert(replay.recording_file_refnum>0);
			close_file(replay.recording_file_refnum);
		}
	}

	replay.valid= FALSE;

	return;
}
Esempio n. 3
0
RecordVideo::~RecordVideo()
{
	stop_recording();
	delete_buffer();
	delete trigger_lock;
        delete pause_record_lock;
        delete record_paused_lock;
}
		// End recording: adds 100 msec of data to catch final events
static void end_trial(void)
{
  clear_full_screen_window(target_background_color);    /* hide display */
  end_realtime_mode();   // NEW: ensure we release realtime lock
  pump_delay(100);       // CHANGED: allow Windows to clean up  
                         // while we record additional 100 msec of data 
  stop_recording();
}
Esempio n. 5
0
void close_application (GtkWidget *widget, gpointer user_data)
{
    write_config_file ();
    stop_recording (TRUE);
    stop_scripting (TRUE);
    stop_replaying (TRUE);
    gtk_main_quit ();
    applicationExiting = TRUE;
}
Esempio n. 6
0
void vhalt(const char *message)
{
	stop_recording();
        logFatal("vhalt: %s", message);
	GetCurrentLogger()->flush();
	shutdown_application();
	system_alert_user(message, fatalError);
	abort();
}
void vhalt(const char *message)
{
	stop_recording();
        logFatal1("vhalt: %s", message);
	fprintf(stderr, "vhalt %s\n", message);
#if defined(__APPLE__) && defined(__MACH__)
	* (char *) 0x0 = 0;
#else
	abort();
#endif
}
Esempio n. 8
0
static void
on_record_toggled (GtkToggleToolButton *tb, void *user_data)
{
    Viewer *self = (Viewer*) user_data;
    int record = gtk_toggle_tool_button_get_active (tb);

    if (record && ! self->is_recording) {
        start_recording (self);
    } else {
        stop_recording (self);
    }
}
Esempio n. 9
0
int start_recording(recorder_context_t *rctx)
{
    int retval = 0;
    time_t current_time;

    Log(LOG_INFO, "Starting recorder.\n");


    if ((retval = init_filenames(rctx)) < 0){
        Log(LOG_ERR, "Failed in the initialization of the recording file.\n");
        goto exit;
    }
    Log(LOG_INFO, "Filenames created.\n");

    if ((retval = init_pa(rctx)) < 0){
        Log(LOG_ERR, "Failed in the initializaion of pulse audio.\n");
        goto exit;
    }
    Log(LOG_INFO, "PulseAudio connected.\n");

    Log(LOG_INFO, "Calibrating threshold.\n");
    printf("*****  ATTENTION  *****\n");
    printf("Keep quiet for the next %d seconds please.\n", QUIET_TIME);
    pa_stream_set_read_callback(rctx->recording_stream, detect_threshold_cb, rctx);
    rctx->timestamp = time(NULL);
    current_time = rctx->timestamp;
#ifdef DEBUG
    threshold_file = fopen("/tmp/threshold.pcm", "wb");
#endif
    while (difftime(current_time, rctx->timestamp) < QUIET_TIME){
        pa_mainloop_iterate(rctx->pa_ml, 0, &retval);
        current_time = time(NULL);
        if (retval < 0){
            Log(LOG_ERR,
                "There was a problem calculating the threshold power.\n");
            goto exit;
        }
    }
    Log(LOG_DEBUG, "Threshold: %f\n", rctx->threshold);

    Log(LOG_INFO, "Entering into the mainloop.\n");
    printf("\nNow you can start talking.\n");
    rctx->timestamp = time(NULL);
    pa_stream_set_read_callback(rctx->recording_stream, stream_request_cb, rctx);
    pa_mainloop_run(rctx->pa_ml, &retval);

exit:
    stop_recording(rctx, false);
    return retval;
}
Esempio n. 10
0
/* End recording: adds 100 msec of data to catch final events */
static void end_trial(void)
{
  clear_full_screen_window(target_background_color);    /* hide display */
  end_realtime_mode();   /* NEW: ensure we release realtime lock */
  pump_delay(100);       /* CHANGED: allow Windows to clean up   */
                         /* while we record additional 100 msec of data  */
  stop_recording();
  
    /* Reset link data, disable fixation event data */
  eyecmd_printf("link_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON");
  eyecmd_printf("fixation_update_interval = 0");
  eyecmd_printf("fixation_update_accumulate = 0");
 
}
Eyelink::~Eyelink(){
    
    boost::mutex::scoped_lock lock(EyelinkDriverLock);
    
	if (Eyelink_Initialized) {
        
		if (!stopped) {
			mwarning(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink is still running !");
            //eyelink stop recording
			if(eyelink_is_connected()) { stop_recording(); }
		}
        
		if (schedule_node) {
			schedule_node->cancel();
			schedule_node.reset();
		}
		
		if(eyelink_is_connected()) {
			
			// Places EyeLink tracker in off-line (idle) mode
			set_offline_mode();
			// close any open data files
			
			if ( close_data_file() == 0 ) {
                mprintf(M_IODEVICE_MESSAGE_DOMAIN,"Eyelink closed data file %s.",data_file_name);
            }
			
			if (eyelink_close(1)) // disconnect from tracker
			{
				merror(M_IODEVICE_MESSAGE_DOMAIN, "Could not close Eyelink connection");
			}
            
			//close_eyelink_system();
			
            mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Eyelink %d System Version %s disconnected.",tracker_version,version_info);
            
		}
		else {
			mwarning(M_IODEVICE_MESSAGE_DOMAIN,"Error, Eyelink Shutdown failed");
		}
		
		Eyelink_Initialized = false;
        
    }
}
Esempio n. 12
0
// ######################################################################
void EyeTrackerEyeLink::stopTracking()
{
#ifndef HAVE_EYELINK
  LFATAL("Proprietary EyeLink developer API not installed");
#else
  // report response result: 0=timeout, else button number:
  eyemsg_printf(const_cast<char*>("TRIAL_RESULT 1"));

  // stop the tracker:
  stop_recording();

	// set FIXUPDATE event property (close it)
  eyecmd_printf(const_cast<char*>("fixation_update_interval = 0"));
  eyecmd_printf(const_cast<char*>("fixation_update_accumulate = 0"));

	set_offline_mode();
#endif
}
bool Eyelink::stopDeviceIO() {
    boost::mutex::scoped_lock lock(EyelinkDriverLock);
	
	if(!stopped) {
		
		if (schedule_node) {
			schedule_node->cancel();
			schedule_node.reset();
		}
		
		if(eyelink_is_connected()) {
			//eyelink stop recording
			stop_recording();
			//go to eyelink offline mode
			set_offline_mode();
		}
		else mwarning(M_IODEVICE_MESSAGE_DOMAIN, "Warning! Could not stop EyeLink! Connection Lost!! (StopIO)");
		
		if (e_time != NULL) e_time -> setValue( (float)MISSING_DATA );
		if (e_rx != NULL) e_rx -> setValue( (float)MISSING_DATA );
		if (e_ry != NULL) e_ry -> setValue( (float)MISSING_DATA );
		if (e_lx != NULL) e_lx -> setValue( (float)MISSING_DATA );
		if (e_ly != NULL) e_ly -> setValue( (float)MISSING_DATA );
		if (e_x != NULL) e_x -> setValue( (float)MISSING_DATA );
		if (e_y != NULL) e_y -> setValue( (float)MISSING_DATA );
		if (e_z != NULL) e_z -> setValue( (float)MISSING_DATA );
		if (h_rx != NULL) h_rx -> setValue( (float)MISSING_DATA );
		if (h_ry != NULL) h_ry -> setValue( (float)MISSING_DATA );
		if (h_lx != NULL) h_lx -> setValue( (float)MISSING_DATA );
		if (h_ly != NULL) h_ly -> setValue( (float)MISSING_DATA );
		if (p_rx != NULL) p_rx -> setValue( (float)MISSING_DATA );
		if (p_ry != NULL) p_ry -> setValue( (float)MISSING_DATA );
		if (p_lx != NULL) p_lx -> setValue( (float)MISSING_DATA );
		if (p_ly != NULL) p_ly -> setValue( (float)MISSING_DATA );
		if (p_r != NULL) p_r -> setValue( (float)MISSING_DATA );
		if (p_l != NULL) p_l -> setValue( (float)MISSING_DATA );
		
		
		stopped = true;
		mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Eyelink successfully stopped.");
	}
	
    return stopped;
}
PsychError EyelinkStopRecording(void)
{
	// Add help strings
	PsychPushHelp(useString, synopsisString, seeAlsoString);
	
	// Output help if asked
	if(PsychIsGiveHelp()) {
		PsychGiveHelp();
		return(PsychError_none);
	}

	// Check arguments
	PsychErrorExit(PsychCapNumInputArgs(0));
	PsychErrorExit(PsychRequireNumInputArgs(0));
	PsychErrorExit(PsychCapNumOutputArgs(0));
	
	// Verify eyelink is up and running
	EyelinkSystemIsConnected();
	//EyelinkSystemIsInitialized();

	stop_recording();
	
	return(PsychError_none); 
}
Esempio n. 15
0
// seg000:04CD
int __pascal far process_key() {
	char sprintf_temp[80];
	int key;
	const char* answer_text;
	word need_show_text;
	need_show_text = 0;
	key = key_test_quit();

	if (start_level == 0) {
		if (key || control_shift) {
			#ifdef USE_QUICKSAVE
			if (key == SDL_SCANCODE_F9) need_quick_load = 1;
			#endif
			#ifdef USE_REPLAY
			if (key == SDL_SCANCODE_TAB) {
				start_replay();
			}
			else
			#endif
			if (key == (SDL_SCANCODE_L | WITH_CTRL)) { // ctrl-L
				if (!load_game()) return 0;
			} else {
				start_level = 1;
			}
			draw_rect(&screen_rect, 0);
#ifdef USE_FADE
			if (is_global_fading) {
				fade_palette_buffer->proc_restore_free(fade_palette_buffer);
				is_global_fading = 0;
			}
#endif
			start_game();
		}
	}
	// If the Kid died, enter or shift will restart the level.
	if (rem_min != 0 && Kid.alive > 6 && (control_shift || key == SDL_SCANCODE_RETURN)) {
		key = SDL_SCANCODE_A | WITH_CTRL; // ctrl-a
	}
#ifdef USE_REPLAY
	if (recording) key_press_while_recording(&key);
	else if (replaying) key_press_while_replaying(&key);
#endif
	if (key == 0) return 0;
	if (is_keyboard_mode) clear_kbd_buf();

	switch(key) {
		case SDL_SCANCODE_ESCAPE: // esc
		case SDL_SCANCODE_ESCAPE | WITH_SHIFT: // allow pause while grabbing
			is_paused = 1;
		break;
		case SDL_SCANCODE_SPACE: // space
			is_show_time = 1;
		break;
		case SDL_SCANCODE_A | WITH_CTRL: // ctrl-a
			if (current_level != 15) {
				stop_sounds();
				is_restart_level = 1;
			}
		break;
		case SDL_SCANCODE_G | WITH_CTRL: // ctrl-g
			// CusPoP: first and last level where saving is allowed
//			if (current_level > 2 && current_level < 14) { // original
			if (current_level >= saving_allowed_first_level && current_level <= saving_allowed_last_level) {
				save_game();
			}
		break;
		case SDL_SCANCODE_J | WITH_CTRL: // ctrl-j
			if ((sound_flags & sfDigi) && sound_mode == smTandy) {
				answer_text = "JOYSTICK UNAVAILABLE";
			} else {
				if (set_joy_mode()) {
					answer_text = "JOYSTICK MODE";
				} else {
					answer_text = "JOYSTICK NOT FOUND";
				}
			}
			need_show_text = 1;
		break;
		case SDL_SCANCODE_K | WITH_CTRL: // ctrl-k
			answer_text = "KEYBOARD MODE";
			is_joyst_mode = 0;
			is_keyboard_mode = 1;
			need_show_text = 1;
		break;
		case SDL_SCANCODE_R | WITH_CTRL: // ctrl-r
			start_level = 0;
			start_game();
		break;
		case SDL_SCANCODE_S | WITH_CTRL: // ctrl-s
			turn_sound_on_off((!is_sound_on) * 15);
			answer_text = "SOUND OFF";
			if (is_sound_on) {
				answer_text = "SOUND ON";
			}
			//
			need_show_text = 1;
		break;
		case SDL_SCANCODE_V | WITH_CTRL: // ctrl-v
			answer_text = "PRINCE OF PERSIA  V1.0";
			need_show_text = 1;
		break;
		case SDL_SCANCODE_L | WITH_SHIFT: // shift-l
			if (current_level <= 3 || cheats_enabled) {
				// if shift is not released within the delay, the cutscene is skipped
				Uint32 delay = 250;
				key_states[SDL_SCANCODE_LSHIFT] = 0;
				key_states[SDL_SCANCODE_RSHIFT] = 0;
				SDL_TimerID timer;
				timer = SDL_AddTimer(delay, temp_shift_release_callback, NULL);
				if (timer == 0) {
					sdlperror("SDL_AddTimer");
					quit(1);
				}
				if (current_level == 14) {
					next_level = 1;
				} else {
					if (current_level == 15 && cheats_enabled) {
#ifdef USE_COPYPROT
                        if (options.enable_copyprot) {
                        	next_level = copyprot_level;
                        	copyprot_level = -1;
                        }
#endif
					} else {
						next_level = current_level + 1;
						if (!cheats_enabled && rem_min > 15) {
							rem_min = 15;
							rem_tick = 719;
						}
					}
				}
				stop_sounds();
			}
		break;
#ifdef USE_QUICKSAVE
		case SDL_SCANCODE_F6:
		case SDL_SCANCODE_F6 | WITH_SHIFT:
			if (Kid.alive < 0) need_quick_save = 1;
		break;
		case SDL_SCANCODE_F9:
		case SDL_SCANCODE_F9 | WITH_SHIFT:
			need_quick_load = 1;
		break;
#ifdef USE_REPLAY
		case SDL_SCANCODE_TAB | WITH_CTRL:
		case SDL_SCANCODE_TAB | WITH_CTRL | WITH_SHIFT:
			if (recording) { // finished recording
				stop_recording();
			}
			else { // should start recording
				start_recording();
			}
			break;
#endif // USE_RECORD_REPLAY
#endif // USE_QUICKSAVE
	}
	if (cheats_enabled) {
		switch (key) {
			case SDL_SCANCODE_C: // c
				snprintf(sprintf_temp, sizeof(sprintf_temp), "S%d L%d R%d A%d B%d", drawn_room, room_L, room_R, room_A, room_B);
				answer_text = /*&*/sprintf_temp;
				need_show_text = 1;
			break;
			case SDL_SCANCODE_C | WITH_SHIFT: // shift-c
				snprintf(sprintf_temp, sizeof(sprintf_temp), "AL%d AR%d BL%d BR%d", room_AL, room_AR, room_BL, room_BR);
				answer_text = /*&*/sprintf_temp;
				need_show_text = 1;
			break;
			case SDL_SCANCODE_MINUS:
			case SDL_SCANCODE_KP_MINUS:		// '-' --> subtract time cheat
				if (rem_min > 1) --rem_min;
				text_time_total = 0;
				text_time_remaining = 0;
				is_show_time = 1;
			break;
			case SDL_SCANCODE_EQUALS | WITH_SHIFT: // '+'
			case SDL_SCANCODE_KP_PLUS:	   // '+' --> add time cheat
				++rem_min;
				text_time_total = 0;
				text_time_remaining = 0;
				is_show_time = 1;
			break;
			case SDL_SCANCODE_R: // R --> revive kid cheat
				if (Kid.alive > 0) {
					resurrect_time = 20;
					Kid.alive = -1;
					erase_bottom_text(1);
				}
			break;
			case SDL_SCANCODE_K: // K --> kill guard cheat
				guardhp_delta = -guardhp_curr;
				Guard.alive = 0;
			break;
			case SDL_SCANCODE_I | WITH_SHIFT: // shift+I --> invert cheat
				toggle_upside();
			break;
			case SDL_SCANCODE_W | WITH_SHIFT: // shift+W --> feather fall cheat
				feather_fall();
			break;
			case SDL_SCANCODE_H: // H --> view room to the left
				draw_guard_hp(0, 10);
				next_room = room_L;
			break;
			case SDL_SCANCODE_J: // J --> view room to the right
				draw_guard_hp(0, 10);
				next_room = room_R;
			break;
			case SDL_SCANCODE_U: // U --> view room above
				draw_guard_hp(0, 10);
				next_room = room_A;
			break;
			case SDL_SCANCODE_N: // N --> view room below
				draw_guard_hp(0, 10);
				next_room = room_B;
			break;
			case SDL_SCANCODE_B | WITH_SHIFT: // shift-b
				is_blind_mode = !is_blind_mode;
				if (is_blind_mode) {
					draw_rect(&rect_top, 0);
				} else {
					need_full_redraw = 1;
				}
			break;
			case SDL_SCANCODE_S | WITH_SHIFT: // shift-s
				if (hitp_curr != hitp_max) {
					play_sound(sound_33_small_potion); // small potion (cheat)
					hitp_delta = 1;
					flash_color = 4; // red
					flash_time = 2;
				}
			break;
			case SDL_SCANCODE_T | WITH_SHIFT: // shift-t
				play_sound(sound_30_big_potion); // big potion (cheat)
				flash_color = 4; // red
				flash_time = 4;
				add_life();
			break;
			#ifdef USE_DEBUG_CHEATS
			case SDL_SCANCODE_T:
				printf("Remaining minutes: %d\tticks:%d\n", rem_min, rem_tick);
				snprintf(sprintf_temp, sizeof(sprintf_temp), "M:%d S:%d T:%d", rem_min, rem_tick / 12, rem_tick);
				answer_text = sprintf_temp;
				need_show_text = 1;
			break;
			#endif
		}
	}

	if (need_show_text) {
		display_text_bottom(answer_text);
		text_time_total = 24;
		text_time_remaining = 24;
	}
	return 1;
}
Esempio n. 16
0
/*
 * The callback will record when mute isn't activated and:
 *    - it'll always record the first SILENCE_BREAKPOINTS events that are 
 *    above the low_point but below the high_point (these are normally the 
 *    trailing of a utterance).
 *    - it'll always record if the event is well below the high_level 
 *    (these are normally the utterances)
 *
 * The counter_activity (which is one of the responsible to record after all, 
 * see the above comment) is reseted mainly by a detected high_point utterance 
 * or when we have detected a long streak of idle.
 *
 * The callback will split an utterance when nothing interesting has been 
 * said in the last HOT_ZONE seconds.
 */
static void stream_request_cb(pa_stream *stream, size_t length, void *userdata)
{
    const void *data;
    size_t size = 0;
    double power, low_point, high_point;
    int retval, retries;
    time_t current_time;
    recorder_context_t *rctx = (recorder_context_t *) userdata;

    if (rctx->dirty_filename){
        fclose(rctx->recording_file);
        fclose(rctx->length_file);

        retries = 0;
        do{
            retval = init_filenames(rctx);
            retries++;
        } while(retval != 0 && retries < 20);
        if (retries == 20){
            Log(LOG_ERR, 
                "There was some nasty problems with the opening of %s file.\n",
                rctx->filename);
            stop_recording(rctx, false);
        }

        rctx->dirty_filename = false;
    }

    if (!rctx->mute){
        pa_stream_peek(stream, &data, &size);
        rctx->is_recording = false;

        power = calculate_rms_power(data, size);
        low_point = rctx->threshold * LOW_BREAKPOINT;
        high_point = rctx->threshold * HIGH_BREAKPOINT;
        rctx->total_activity++;
        if (data){
            if (power >= low_point){
                if (rctx->counter_silence < SILENCE_BREAKPOINT ||
                    power > high_point){

                    rctx->counter_idle = 0;

                    current_time = time(NULL);
                    if (difftime(current_time, rctx->timestamp) >= HOT_ZONE){
                        if (is_interesting(rctx)){
                            dump(rctx);
                            rctx->high_activity = rctx->total_activity = 0;
                        }
                        rctx->timestamp = current_time;
                    }

                    if (power <= high_point){
                        rctx->counter_silence++;
                    }else{
                        rctx->counter_silence = 0;
                        rctx->high_activity++;
                    }

                    rctx->is_recording = true;
                    buffer(rctx, data, size);

                    Log(LOG_DEBUG,
                        "-> power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
                }else{
                    Log(LOG_DEBUG,
                        "SS power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
                }
            }else{
                rctx->counter_idle = fmin(++rctx->counter_idle, IDLE_BREAKPOINT);
                if (rctx->counter_idle == IDLE_BREAKPOINT)
                    rctx->counter_silence = 0;
                Log(LOG_DEBUG,
                    "   power: %12.6f[%f, %f] threshold: %f silence: %d idle: %d\n",
                        power, low_point, high_point, rctx->threshold,
                        rctx->counter_silence, rctx->counter_idle);
            }
            pa_stream_drop(stream);
        }
    }
}
/**
 * @name best_first_search
 *
 * Find the best segmentation by doing a best first search of the
 * solution space.
 */
void Wordrec::best_first_search(CHUNKS_RECORD *chunks_record,
                                WERD_CHOICE *best_choice,
                                WERD_CHOICE *raw_choice,
                                STATE *state,
                                DANGERR *fixpt,
                                STATE *best_state) {
  SEARCH_RECORD *the_search;
  inT16 keep_going;
  STATE guided_state;   // not used

  num_joints = chunks_record->ratings->dimension() - 1;
  the_search = new_search(chunks_record, num_joints,
                          best_choice, raw_choice, state);

  // The default state is initialized as the best choice.  In order to apply
  // segmentation adjustment, or any other contextual processing in permute,
  // we give the best choice a poor rating to force the processed raw choice
  // to be promoted to best choice.
  the_search->best_choice->set_rating(100000.0);
  evaluate_state(chunks_record, the_search, fixpt);
  if (permute_debug) {
    tprintf("\n\n\n =========== BestFirstSearch ==============\n");
    best_choice->print("**Initial BestChoice**");
  }

#ifndef GRAPHICS_DISABLED
  save_best_state(chunks_record);
#endif
  start_recording();
  FLOAT32 worst_priority = 2.0f * prioritize_state(chunks_record, the_search);
  if (worst_priority < wordrec_worst_state)
    worst_priority = wordrec_worst_state;
  if (segment_debug) {
    print_state("BestFirstSearch", best_state, num_joints);
  }

  guided_state = *state;
  do {
                                 /* Look for answer */
    if (!hash_lookup (the_search->closed_states, the_search->this_state)) {

      if (tord_blob_skip) {
        free_state (the_search->this_state);
        break;
      }

      guided_state = *(the_search->this_state);
      keep_going = evaluate_state(chunks_record, the_search, fixpt);
      hash_add (the_search->closed_states, the_search->this_state);

      if (!keep_going ||
          (the_search->num_states > wordrec_num_seg_states) ||
          (tord_blob_skip)) {
        if (segment_debug)
          tprintf("Breaking best_first_search on keep_going %s numstates %d\n",
                  ((keep_going) ? "T" :"F"), the_search->num_states);
        free_state (the_search->this_state);
        break;
      }

      FLOAT32 new_worst_priority = 2.0f * prioritize_state(chunks_record,
                                                           the_search);
      if (new_worst_priority < worst_priority) {
        if (segment_debug)
          tprintf("Lowering WorstPriority %f --> %f\n",
                  worst_priority, new_worst_priority);
        // Tighten the threshold for admitting new paths as better search
        // candidates are found.  After lowering this threshold, we can safely
        // popout everything that is worse than this score also.
        worst_priority = new_worst_priority;
      }
      expand_node(worst_priority, chunks_record, the_search);
    }

    free_state (the_search->this_state);
    num_popped++;
    the_search->this_state = pop_queue (the_search->open_states);
    if (segment_debug && !the_search->this_state)
      tprintf("No more states to evalaute after %d evals", num_popped);
  }
  while (the_search->this_state);

  state->part1 = the_search->best_state->part1;
  state->part2 = the_search->best_state->part2;
  stop_recording();
  if (permute_debug) {
    tprintf("\n\n\n =========== BestFirstSearch ==============\n");
            // best_choice->debug_string(getDict().getUnicharset()).string());
    best_choice->print("**Final BestChoice**");
  }
  // save the best_state stats
  delete_search(the_search);
}
Esempio n. 18
0
gboolean start_new_game (gchar *game_filename, gchar *graphics_filename,
			 gchar *splash_filename, gchar *music_filename,
			 gchar *hints_filename)
{
    const gchar *filters[] =
	{
	    "Magnetic Scrolls data file (*.mag)", "*.mag",
	    NULL
	};

    if (!game_filename)
	game_filename = file_selector (FALSE, NULL, filters, "Open game file");

    if (!game_filename)
	return TRUE;

    stop_main_loop ();

    if (ms_is_running ())
    {
	ms_stop ();
	ms_freemem ();
    }

    stop_recording (TRUE);
    stop_scripting (TRUE);
    stop_replaying (TRUE);

    if (!graphics_filename)
	graphics_filename = change_file_extension (game_filename, "gfx");

    if (!splash_filename)
	splash_filename = change_file_extension (game_filename, "png");
    
    if (!music_filename)
	music_filename = change_file_extension (game_filename, "mp3");

    if (!hints_filename)
	hints_filename = change_file_extension (game_filename, "hnt");

    display_splash_screen (splash_filename, music_filename);

    text_clear ();
    graphics_clear ();
    hints_clear ();

    if (applicationExiting)
	return FALSE;

    if (!ms_init ((type8s *) game_filename, (type8s *) graphics_filename, (type8s *) hints_filename), NULL)
    {
	GtkWidget *error;
	gchar *basename;
	
	basename = g_path_get_basename (game_filename);
	error = gtk_message_dialog_new (
	    GTK_WINDOW (Gui.main_window),
	    GTK_DIALOG_DESTROY_WITH_PARENT,
	    GTK_MESSAGE_ERROR,
	    GTK_BUTTONS_OK,
	    "Could not start the game! The most likely cause is\n"
	    "that '%s' is not a valid game file.",
	    basename);
	gtk_dialog_run (GTK_DIALOG (error));
	g_free (basename);
	gtk_widget_destroy (error);
    } else
	start_main_loop ();
    
    g_free (game_filename);
    g_free (graphics_filename);
    g_free (splash_filename);
    g_free (music_filename);
    g_free (hints_filename);
    
    gtk_widget_grab_focus (Gui.text_view);
    return TRUE;
}
Esempio n. 19
0
File: rec.c Progetto: oliv3/phaspa
int
main(int argc, char **argv) {
    char     *buf = NULL;
    uint32_t size = BUF_SIZE;
    char     command[MAXATOMLEN];
    int      index, version;

    if ((buf = (char *)calloc(size, sizeof(char))) == NULL)
        return -1;

    while (read_cmd(buf, &size) > 0) {
        /* Reset the index, so that ei functions can decode terms from the
         * beginning of the buffer */
        index = 0;

        // D("buf: %s", buf);

        /* Ensure that we are receiving the binary term by reading and
         * stripping the version byte */
        check(ei_decode_version(buf, &index, &version));

        /* Ici donc le code du recorder:
         *
         * if decode_atom => stop:
         *   arreter le thread -> ok, {error, not_started} sinon
         * else
         * if decode tuple de taille 2:
         *   starter le thread -> ok, {error, already_started} sinon
         */
        if (!ei_decode_atom(buf, &index, command)) {
            // D("Got atom: %s", command);
            if (!strcmp(command, "stop")) {
                if (recording)
                    stop_recording();
                else
                    ok();
            } else
                check(-1);
        } else {
            int arity;
            // long _span;

            check(ei_decode_tuple_header(buf, &index, &arity));
            // D("Arity: %d", arity);
            if (arity != 2) check(-1);

            check(ei_decode_atom(buf, &index, command));
            // D("Got atom: %s", command);
            if (strcmp(command, "record")) check(-1);

            check(ei_decode_long(buf, &index, &frequency));
            // D("Freq: %li", frequency);

            /* check(ei_decode_long(buf, &index, &_span)); */
            /* span = _span; */
            /* D("SPAN: %i", span); */

            if (!recording) {
                start_recording();
            } else
                error();
        }

        memset(buf, 0, size*sizeof(char));
    }

    free(buf);

    return 0;
}