Exemple #1
0
//
//	sequence::undoredo
//
//	private routine used to undo/redo spanrange events to/from 
//	the sequence - handles 'grouped' events
//
bool sequence::undoredo (eventstack &source, eventstack &dest)
{
	span_range *range = 0;
	size_t group_id;

	if(source.empty())
		return false;

	// make sure that no "optimized" actions can occur
	record_action(action_invalid, 0);

	group_id = source.back()->group_id;

	do
	{
		// remove the next event from the source stack
		range = source.back();
		source.pop_back();

		// add event onto the destination stack
		dest.push_back(range);

		// do the actual work
		restore_spanrange(range, source == undostack ? true : false);
	}
	while(!source.empty() && (source.back()->group_id == group_id && group_id != 0));

	return true;
}
Exemple #2
0
//
//	Import the specified range of data into the sequence so we have our own private copy
//
bool sequence::import_buffer (const seqchar *buf, size_t len, size_t *buffer_offset)
{
	buffer_control *bc;
	
	// get the current modify-buffer
	bc = buffer_list[modifybuffer_id];

	// if there isn't room then allocate a new modify-buffer
	if(bc->length + len >= bc->maxsize)
	{
		bc = alloc_modifybuffer(len + 0x10000);
		
		// make sure that no old spans use this buffer
		record_action(action_invalid, 0);
	}

	if(bc == 0)
		return false;

	// import the data
	memcpy(bc->buffer + bc->length, buf, len * sizeof(seqchar));
	
	*buffer_offset = bc->length;
	bc->length += len;

	return true;
}
Exemple #3
0
/** This methods handles the basic agent functionality: bookeeping
  *  the number of episodes, frames, etc... It calls the method 
  *  act(), which will provide it with an action. act() which should 
  *  be overriden by subclasses.
  */
Action PlayerAgent::agent_step() {
  // Terminate if we have a maximum number of frames
  if (i_max_num_frames > 0 && frame_number >= i_max_num_frames)
    end_game();

  // Terminate this episode if we have reached the max. number of frames 
  if (i_max_num_frames_per_episode > 0 && 
      episode_frame_number >= i_max_num_frames_per_episode) {
    return RESET;
  }

  // Only take an action if manual control is disabled
  Action a;
  if (manual_control) {
      a = waitForKeypress();
  } else {
      a = act();
  }

  if (record_trajectory) record_action(a);

  frame_number++;
  episode_frame_number++;
  
  return a;
}
Exemple #4
0
//
//	sequence::replace
//
//	A 'replace' (or 'overwrite') is a combination of erase+inserting
//  (first we erase a section of the sequence, then insert a new block
//  in it's place). 
//
//	Doing this as a distinct operation (erase+insert at the 
//  same time) is really complicated, so I just make use of the existing 
//  sequence::erase and sequence::insert and combine them into action. We
//	need to play with the undo stack to combine them in a 'true' sense.
//
bool sequence::replace(size_w index, const seqchar *buf, size_w length, size_w erase_length)
{
	size_t remlen = 0;

	debug("Replacing: idx=%d len=%d %.*s\n", index, length, length, buf);

	// make sure operation is within allowed range
	if(index > sequence_length || MAX_SEQUENCE_LENGTH - index < length)
		return false;

	// for a "replace" which will overrun the sequence, make sure we 
	// only delete up to the end of the sequence
	remlen = min(sequence_length - index, erase_length);

	// combine the erase+insert actions together
	group();

	// first of all remove the range
	if(remlen > 0 && index < sequence_length && !erase_worker(index, remlen, action_replace))
	{
		ungroup();
		return false;
	}
	
	// then insert the data
	if(insert_worker(index, buf, length, action_replace))
	{
		ungroup();
		record_action(action_replace, index + length);
		return true;
	}
	else
	{
		// failed...cleanup what we have done so far
		ungroup();
		record_action(action_invalid, 0);

		span_range *range = undostack.back();
		undostack.pop_back();
		restore_spanrange(range, true);
		delete range;

		return false;
	}
}
Exemple #5
0
Action PlayerAgent::episode_start(void) {
  episode_frame_number = 0;

  Action a = act();
  if (record_trajectory) record_action(a);

  frame_number++;
  episode_frame_number++;

  return a;
}
Exemple #6
0
//
//	sequence::erase 
//
//  "removes" the specified range of data from the sequence. 
//
bool sequence::erase (size_w index, size_w len)
{
	if(erase_worker(index, len, action_erase))
	{
		record_action(action_erase, index);
		return true;
	}
	else
	{
		return false;
	}
}
Exemple #7
0
//
//	sequence::insert
//
//	Insert a buffer into the sequence at the specified position.
//	Consecutive insertions are optimized into a single event
//
bool sequence::insert (size_w index, const seqchar *buf, size_w length)
{
	if(insert_worker(index, buf, length, action_insert))
	{
		record_action(action_insert, index + length);
		return true;
	}
	else
	{
		return false;
	}
}
void hf_commit_creation (gpointer data) {
//	Commit the filter
	filter_dialog_struct *fds;
	hf_wrapper_struct *hfw;
	hfw = (hf_wrapper_struct *) data;
//	printf("HFW, HFW->creation_mode in hf_commit_creation: %d, %d\n",data,hfw->creation_mode);
// printf("HFW->window->window: %d->%d\n",hfw->window,hfw->window->window);
	hfw->creation_mode = FALSE;  // Supposed to be done in hf_wrapper_copy...
//	hfw->hf_options->current_calculation = NULL;
	hfw->apply_filter = FALSE;

//	Backup the filter definition and nullify it - we 1st commit the HF without the filter
	if (hfw->hf_options->fd_struct) {
		set_filter_defaults (hfw->hf_options->fd_struct);
	}
	
	record_action(hfw, hfw->hf_options->last_creation_action);
	if (hfw->hf_options->fd_struct) {
		fds = hfw->hf_options->fd_struct;
		if (fds->current_filter) {
		    filter_apply(hfw->hf_struct,
			fds->current_filter,
			hfw->hf_options->dist_matrix,
			fds->revert_filter,
			fds->filter_level,
			fds->merge_oper);
//	Now we commit the HF with the filter
		record_action(hfw,_("Shape filter"));

		}
	}
//	If we are in the shape filter subdialog in the tools dialog:
	if (hfw->hf_options->img)
		hfw->hf_options->fd_struct = hfw->hf_options->img->fd_struct;
	else
		hfw->hf_options->fd_struct = NULL;

//	"expose_event" seems required to display the cursor ?
	emit_expose_event(hfw->area);
}
Exemple #9
0
bool sequence::init ()
{
	sequence_length = 0;

	if(!alloc_modifybuffer(0x10000))
		return false;

	record_action(action_invalid, 0);
	group_id		= 0;
	group_refcount	= 0;
	undoredo_index	= 0;
	undoredo_length = 0;

	return true;
}
Exemple #10
0
//
//	sequence::insert
//
//	Insert a buffer into the sequence at the specified position.
//	Consecutive insertions are optimized into a single event
//
bool sequence::insert (size_w index, const seqchar *buf, size_w length)
{
	bool append = index == sequence_length ? true : false;

	if(insert_worker(index, buf, length, action_insert))
	{
		if(can_quicksave && !append)
			can_quicksave = false;

		record_action(action_insert, index + length);
		return true;
	}
	else
	{
		return false;
	}
}
Exemple #11
0
bool sequence::init ()
{
	sequence_length  = 0;
	origfile_id		 = -1;
	origfile_name[0] = '\0';
	can_quicksave    = false;

	if(!alloc_modifybuffer(0x10000))
		return false;

	record_action(action_invalid, 0);
	group_id		= 0;
	group_refcount	= 0;
	undoredo_index	= 0;
	undoredo_length = 0;
	undoredo_datalength = 0;

	return true;
}
Exemple #12
0
sequence::sequence ()
{
	record_action(action_invalid, 0);
	
	head = tail		= 0;
	sequence_length = 0;
	group_id		= 0;
	group_refcount	= 0;

	head			= new span(0, 0, 0);
	tail			= new span(0, 0, 0);
	head->next		= tail;
	tail->prev		= head;

#ifdef DEBUG_SEQUENCE
	SYSTEMTIME st;
	GetLocalTime(&st);
	sprintf(debugfile, "seqlog-%04d%02d%02d-%02d%02d%0d.txt", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
#endif
}
Exemple #13
0
Fichier : prefs.c Projet : vigna/ne
int save_prefs(buffer * const b, const char * const name) {
	if (!b || !name) return ERROR;

	assert_buffer(b);

	char_stream *cs = alloc_char_stream(PREF_FILE_SIZE_GUESS);
	if (cs) {
		/* We create a macro by recording an action for each kind of flag. */

		if (!saving_defaults && b->syn) record_action(cs, SYNTAX_A, -1, (const char *)b->syn->name, verbose_macros);

		record_action(cs, TABSIZE_A,          b->opt.tab_size,       NULL, verbose_macros);
		/* Skip cur_clip */
		record_action(cs, RIGHTMARGIN_A,      b->opt.right_margin,   NULL, verbose_macros);
		record_action(cs, FREEFORM_A,         b->opt.free_form,      NULL, verbose_macros);
		record_action(cs, HEXCODE_A,          b->opt.hex_code,       NULL, verbose_macros);
		record_action(cs, WORDWRAP_A,         b->opt.word_wrap,      NULL, verbose_macros);
		record_action(cs, AUTOINDENT_A,       b->opt.auto_indent,    NULL, verbose_macros);
		record_action(cs, PRESERVECR_A,       b->opt.preserve_cr,    NULL, verbose_macros);
		record_action(cs, INSERT_A,           b->opt.insert,         NULL, verbose_macros);
		record_action(cs, DOUNDO_A,           b->opt.do_undo,        NULL, verbose_macros);
		record_action(cs, AUTOPREFS_A,        b->opt.auto_prefs,     NULL, verbose_macros);
		record_action(cs, NOFILEREQ_A,        b->opt.no_file_req,    NULL, verbose_macros);
		/* Skip read_only */
		/* Skip search_back */
		record_action(cs, CASESEARCH_A,       b->opt.case_search,    NULL, verbose_macros);
		record_action(cs, TABS_A,             b->opt.tabs,           NULL, verbose_macros);
		record_action(cs, DELTABS_A,          b->opt.del_tabs,       NULL, verbose_macros);
		record_action(cs, SHIFTTABS_A,        b->opt.shift_tabs,     NULL, verbose_macros);
		record_action(cs, AUTOMATCHBRACKET_A, b->opt.automatch,      NULL, verbose_macros);
		record_action(cs, BINARY_A,           b->opt.binary,         NULL, verbose_macros);
		record_action(cs, UTF8AUTO_A,         b->opt.utf8auto,       NULL, verbose_macros);
		record_action(cs, VISUALBELL_A,       b->opt.visual_bell,    NULL, verbose_macros);

		if (saving_defaults) {
			/* We only save the global flags that differ from their defaults. */
			/* Make sure these are in sync with the defaults near the top of ne.c. */
#ifndef ALTPAGING
			if (req_order)       record_action(cs, REQUESTORDER_A,  req_order,      NULL, verbose_macros);
#else
			if (!req_order)      record_action(cs, REQUESTORDER_A,  req_order,      NULL, verbose_macros);
#endif
			if (fast_gui)        record_action(cs, FASTGUI_A,       fast_gui,       NULL, verbose_macros);
			if (!status_bar)     record_action(cs, STATUSBAR_A,     status_bar,     NULL, verbose_macros);
			if (!verbose_macros) record_action(cs, VERBOSEMACROS_A, verbose_macros, NULL, verbose_macros);
			saving_defaults = false;
		}

		const int error = save_stream(cs, name, b->is_CRLF, false);
		free_char_stream(cs);
		return error;
	}

	return OUT_OF_MEMORY;
}