예제 #1
0
static int rd_history(void)
{
	u32b tmp32u;
	size_t i;
	
	history_clear();
	
	rd_u32b(&tmp32u);
	for (i = 0; i < tmp32u; i++)
	{
		s32b turn;
		s16b dlev, clev;
		u16b type;
		byte art_name;
		char text[80];
		
		rd_u16b(&type);
		rd_s32b(&turn);
		rd_s16b(&dlev);
		rd_s16b(&clev);
		rd_byte(&art_name);
		rd_string(text, sizeof(text));
		
		history_add_full(type, art_name, dlev, clev, turn, text);
	}

	return 0;
}
예제 #2
0
파일: log.c 프로젝트: holodnak/nesemu3
int log_init()
{
	historyline_t *line;

	if(logfd) {
		printf("log_init:  already initialized\n");
		return(0);
	}

	//clear the string
	memset(logfilename,0,MAX_PATH);

	//parse the log path
	config_get_eval_string(logfilename,"path.user");

	//append the path seperator
	str_appendchar(logfilename,PATH_SEPERATOR);

	//append the bios filename
	strcat(logfilename,LOGFILENAME);

	//try to open
	if((logfd = fopen(logfilename,"wt")) == 0) {
		strcpy(logfilename,LOGFILENAME);
		if((logfd = fopen(LOGFILENAME,"wt")) == 0) {
			printf("log_init:  error opening log file '%s'\n",logfilename);
			return(1);
		}
	}

	//catch up the log file with lines that weren't added
	line = history.lines;
	while(line->next) {
		line = line->next;
	}
	while(line) {
		fputs(line->str,logfd);
		line = line->prev;
	}
	fflush(logfd);
	history_clear(&history);

	log_printf("log_init:  log initialized.  nesemu2 v"VERSION"\n");
	log_printf("log_init:  log filename is '%s'.\n",logfilename);
	return(0);
}
예제 #3
0
/**
 * Free player struct
 */
static void cleanup_player(void) {
	int i;

	/* Free the history */
	history_clear(player);

	/* Free the things that are always initialised */
	object_free(player->obj_k);
	mem_free(player->timed);
	mem_free(player->upkeep->quiver);
	mem_free(player->upkeep->inven);
	mem_free(player->upkeep);
	player->upkeep = NULL;

	/* Free the things that are only there if there is a loaded player -
	 * checking if there are quests will suffice */
	if (player->quests) {
		player_quests_free(player);
		player_spells_free(player);
		object_pile_free(player->gear);
		object_pile_free(player->gear_k);
		for (i = 0; i < player->body.count; i++)
			string_free(player->body.slots[i].name);
		mem_free(player->body.slots);
		string_free(player->body.name);
		mem_free(player->history);
	}
	if (player->cave) {
		cave_free(player->cave);
		player->cave = NULL;
	}

	/* Free the basic player struct */
	mem_free(player);
	player = NULL;
}
예제 #4
0
static void handle_touch(struct wl_input_event *ev)
{
	//int offset,offset_count,
	int article_link_number=-1;
	int enter_touch_y_pos_record;
	//int time_diff_search;
	int mode;
	struct keyboard_key * key;
	static int last_5_y[5];
	static unsigned long last_5_y_time_ticks[5];
	int i;

	DP(DBG_WL, ("%s() touch event @%d,%d val %d\n", __func__,
		ev->touch_event.x, ev->touch_event.y, ev->touch_event.value));

	mode = keyboard_get_mode();
	if (display_mode == DISPLAY_MODE_INDEX && (mode == KEYBOARD_CHAR || mode == KEYBOARD_NUM))
	{
		article_buf_pointer = NULL;
		key = keyboard_get_data(ev->touch_event.x, ev->touch_event.y);
		if (ev->touch_event.value == 0) {
			keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
			enter_touch_y_pos_record = enter_touch_y_pos;
			enter_touch_y_pos = -1;
			touch_search = 0;
			press_delete_button = false;
			pre_key = NULL;
			if (key) {
				if (!touch_down_on_keyboard) {
					touch_down_on_keyboard = 0;
					touch_down_on_list = 0;
					goto out;
				}
				handle_search_key(key->key);
			}
			else {
				if (!touch_down_on_list || ev->touch_event.y < RESULT_START - RESULT_HEIGHT) {
					touch_down_on_keyboard = 0;
					touch_down_on_list = 0;
					goto out;
				}
				if(search_result_count()==0)
				   goto out;

				 //search_set_selection(last_selection);
				 //search_open_article(last_selection);
				 if(search_result_selected()>=0)
				 {
				    display_mode = DISPLAY_MODE_ARTICLE;
				    last_display_mode = DISPLAY_MODE_INDEX;
				    search_open_article(search_result_selected());
				 }
			}
			touch_down_on_keyboard = 0;
			touch_down_on_list = 0;
		} else {
			if(enter_touch_y_pos<0)  //record first touch y pos
			   enter_touch_y_pos = ev->touch_event.y;
			last_index_y_pos = ev->touch_event.y;
			start_search_time = ev->touch_event.ticks;
			last_delete_time = start_search_time;
			if (key) {
				if(key->key==8)//press "<" button
				{
				    press_delete_button = true;
			       }
				else if(key->key == -42)
				{
					mode = keyboard_get_mode();
					if(mode == KEYBOARD_CHAR)
						keyboard_set_mode(KEYBOARD_NUM);
					else if(mode == KEYBOARD_NUM)
						keyboard_set_mode(KEYBOARD_CHAR);
					guilib_fb_lock();
					keyboard_paint();
					guilib_fb_unlock();
				}

				if (!touch_down_on_keyboard && !touch_down_on_list)
					touch_down_on_keyboard = 1;

				if (pre_key && pre_key->key == key->key) goto out;

				if (touch_down_on_keyboard) {
					keyboard_key_invert(key);
					pre_key = key;
				}
			} else {
				if (!touch_down_on_keyboard && !touch_down_on_list)
					touch_down_on_list = 1;
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
				pre_key = NULL;

				if (!search_result_count()) goto out;

				if(touch_search == 0)
				{
				    //last_search_y_pos = ev->touch_event.y;
				    touch_search = 1;
				}
				else
				{
				    if(search_result_selected()>=0 && abs(ev->touch_event.y-search_touch_pos_y_last)>5)
				    {
					invert_selection(search_result_selected(),-1, RESULT_START, RESULT_HEIGHT);
					search_set_selection(-1);
				    }
				    goto out;
				}

				int new_selection;
				if((ev->touch_event.y - RESULT_START)<0)
				    new_selection = -1;
				else
				    new_selection = ((unsigned int)ev->touch_event.y - RESULT_START) / RESULT_HEIGHT;

				if (new_selection == search_result_selected()) goto out;

				unsigned int avail_count = keyboard_get_mode() == KEYBOARD_NONE ?
					NUMBER_OF_FIRST_PAGE_RESULTS : NUMBER_OF_RESULTS_KEYBOARD;
				avail_count = search_result_count() > avail_count ? avail_count : search_result_count();
				if (new_selection >= avail_count) goto out;
				if (touch_down_on_keyboard) goto out;

				//invert_selection(search_result_selected(), new_selection, RESULT_START, RESULT_HEIGHT);
				invert_selection(-1, new_selection, RESULT_START, RESULT_HEIGHT);

				 last_selection = new_selection ;
				search_set_selection(new_selection);
				search_touch_pos_y_last = ev->touch_event.y;
			}
		}
	}
	else if (display_mode == DISPLAY_MODE_HISTORY && mode == KEYBOARD_CLEAR_HISTORY)
	{
		key = keyboard_get_data(ev->touch_event.x, ev->touch_event.y);
		if (ev->touch_event.value == 0) {
			#ifdef INCLUDED_FROM_KERNEL
			delay_us(100000 * 2);
			#endif
			keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW);
			enter_touch_y_pos_record = enter_touch_y_pos;
			enter_touch_y_pos = -1;
			touch_search = 0;
			press_delete_button = false;
			pre_key = NULL;
			if (key) {
				if (!touch_down_on_keyboard) {
					touch_down_on_keyboard = 0;
					touch_down_on_list = 0;
					goto out;
				}
				if (key->key == 'Y') {
					history_clear();
					keyboard_set_mode(KEYBOARD_NONE);
					history_reload();
				} else if (key->key == 'N') {
					keyboard_set_mode(KEYBOARD_NONE);
					guilib_fb_lock();
					draw_clear_history(1);
					guilib_fb_unlock();
				}
			}
			else {
				touch_down_on_keyboard = 0;
				touch_down_on_list = 0;
				goto out;
			}
		} else {
			if(enter_touch_y_pos<0)  //record first touch y pos
			   enter_touch_y_pos = ev->touch_event.y;
			last_index_y_pos = ev->touch_event.y;
			if (key) {
				if (!touch_down_on_keyboard)
					touch_down_on_keyboard = 1;

				if (pre_key && pre_key->key == key->key) goto out;

				if (touch_down_on_keyboard) {
					keyboard_key_invert(key);
					pre_key = key;
				}
			} else {
				touch_down_on_keyboard = 0;
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
				pre_key = NULL;

			}
		}
	}
	else if (display_mode == DISPLAY_MODE_RESTRICTED)
	{
		key = keyboard_get_data(ev->touch_event.x, ev->touch_event.y);
		if (ev->touch_event.value == 0) {
			if (key->key == 'Y' || key->key == 'N' || key->key == 'P')
			{
				#ifdef INCLUDED_FROM_KERNEL
				delay_us(100000 * 2);
				#endif
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW);
			}
			else
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
			enter_touch_y_pos_record = enter_touch_y_pos;
			enter_touch_y_pos = -1;
			touch_search = 0;
			press_delete_button = false;
			pre_key = NULL;
			if (key) {
				if (!touch_down_on_keyboard) {
					touch_down_on_keyboard = 0;
					goto out;
				}
				handle_password_key(key->key);
			}
			touch_down_on_keyboard = 0;
		} else {
			if(enter_touch_y_pos<0)  //record first touch y pos
			   enter_touch_y_pos = ev->touch_event.y;
			last_index_y_pos = ev->touch_event.y;
			start_search_time = ev->touch_event.ticks;
			last_delete_time = start_search_time;
			if (key) {
				if(key->key==8)//press "<" button
				{
				    press_delete_button = true;
			       }
				else if(key->key == -42)
				{
					mode = keyboard_get_mode();
					if(mode == KEYBOARD_PASSWORD_CHAR)
						keyboard_set_mode(KEYBOARD_PASSWORD_NUM);
					else if(mode == KEYBOARD_PASSWORD_NUM)
						keyboard_set_mode(KEYBOARD_PASSWORD_CHAR);
					guilib_fb_lock();
					keyboard_paint();
					guilib_fb_unlock();
				}

				if (!touch_down_on_keyboard)
					touch_down_on_keyboard = 1;

				if (pre_key && pre_key->key == key->key) goto out;

				if (touch_down_on_keyboard) {
					keyboard_key_invert(key);
					pre_key = key;
				}
			} else {
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW);
				pre_key = NULL;

				search_touch_pos_y_last = ev->touch_event.y;
			}
		}
	} else {
		if (ev->touch_event.value == 0) {
			unsigned long diff_ticks = 0;
			long diff_y = 0;

			for (i = 4; i > 0; i--)
			{
				if (last_5_y[i])
				{
					diff_y = ev->touch_event.y - last_5_y[i];
					diff_ticks = time_diff(ev->touch_event.ticks, last_5_y_time_ticks[i]);
					break;
				}
			}

			if (diff_ticks <= 0 || abs(article_moved_pixels) > SMOOTH_SCROLL_ACTIVATION_OFFSET_HIGH_THRESHOLD ||
				abs(article_moved_pixels) < SMOOTH_SCROLL_ACTIVATION_OFFSET_LOW_THRESHOLD)
				finger_move_speed = 0;
			else
			{
				// Event timesing is not good for short period due to the events are queued without timestamp
				finger_move_speed = -(float)diff_y * ((float)seconds_to_ticks(1) / (float)diff_ticks);
				if (abs(finger_move_speed) > SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD)
				{
					if (finger_move_speed > 0)
					{
						if (display_mode == DISPLAY_MODE_ARTICLE)
							finger_move_speed = ARTICLE_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed - SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
						else
							finger_move_speed = LIST_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed - SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
					}
					else
					{
						if (display_mode == DISPLAY_MODE_ARTICLE)
							finger_move_speed = ARTICLE_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed + SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
						else
							finger_move_speed = LIST_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed + SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
					}
				}
				else
					finger_move_speed = 0;
			}

			if (finger_move_speed != 0)
			{
				time_scroll_article_last = ev->touch_event.ticks;
			}

			article_moved = false;
			if (finger_move_speed == 0 && b_show_scroll_bar)
			{
				b_show_scroll_bar = 0;
				show_scroll_bar(0); // clear scroll bar
			}
			article_scroll_pixel = INITIAL_ARTICLE_SCROLL_PIXEL;
			article_moved_pixels = 0;
			touch_y_last_unreleased = 0;
			start_move_time = 0;

			article_link_number = get_activated_article_link_number();
			if(article_link_number>=0)
			{
				if (link_to_be_inverted >= 0)
				{
					if (link_currently_inverted >= 0)
						invert_link(link_currently_inverted);
					invert_link(link_to_be_inverted);
				}
				if (finger_move_speed == 0)
				{
					init_invert_link();
					last_display_mode = display_mode;
					display_mode = DISPLAY_MODE_ARTICLE;
					open_article_link_with_link_number(article_link_number);
				}
				else
				{
					if (link_currently_inverted >= 0)
						invert_link(link_currently_inverted);
					init_invert_link();
				}
				return;
			}

			reset_article_link_number();
			article_touch_down_handled = 0;
		} else {
			finger_move_speed = 0;

			if(touch_y_last_unreleased == 0)
			{
				touch_y_last_unreleased = ev->touch_event.y;
				last_unreleased_time = ev->touch_event.ticks;
				reset_article_link_number();
				article_moved_pixels = 0;
				last_5_y[0] = ev->touch_event.y;
				last_5_y_time_ticks[0] = ev->touch_event.ticks;
				for (i = 1; i < 5; i++)
					last_5_y[i] = 0;

			}
			else
			{
				article_moved_pixels += touch_y_last_unreleased - ev->touch_event.y;
				if(abs(touch_y_last_unreleased - ev->touch_event.y) >=article_scroll_pixel)
				{
					if (finger_move_speed == 0)
						display_article_with_pcf(touch_y_last_unreleased - ev->touch_event.y);
					touch_y_last_unreleased = ev->touch_event.y;
					for (i = 4; i >= 1; i--)
					{
						last_5_y[i] = last_5_y[i-1];
						last_5_y_time_ticks[i] = last_5_y_time_ticks[i-1];
					}
					last_5_y[0] = ev->touch_event.y;
					last_5_y_time_ticks[0] = ev->touch_event.ticks;
					b_show_scroll_bar = 1;
					article_scroll_pixel = 1;
				}
				else if (article_moved_pixels < article_scroll_pixel &&
					time_diff(get_time_ticks(), last_unreleased_time) > seconds_to_ticks(0.075))
				{
					article_moved_pixels = 0;
					touch_y_last_unreleased = ev->touch_event.y;
					last_unreleased_time = ev->touch_event.ticks;
					last_5_y[0] = ev->touch_event.y;
					last_5_y_time_ticks[0] = ev->touch_event.ticks;
					for (i = 1; i < 5; i++)
						last_5_y[i] = 0;
				}

				if (abs(article_moved_pixels) > ARTICLE_MOVED_THRESHOLD)
				{
					article_moved = true;
					reset_article_link_number();
				}
			}

			if (!article_moved)
			{
				article_link_number =isArticleLinkSelected(ev->touch_event.x,ev->touch_event.y);
				if (article_link_number >= 0)
					set_article_link_number(article_link_number, ev->touch_event.ticks);
				else
					reset_article_link_number();
			}

			if (!article_touch_down_handled) {
				article_touch_down_pos.x = ev->touch_event.x;
				article_touch_down_pos.y = ev->touch_event.y;
				article_touch_down_handled = 1;
			}
		}
	}
out:
	return;
}
예제 #5
0
LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    // Build list when first playing a file
    if ( uMsg == WM_USER && lParam == IPC_PLAYING_FILE )
    {
        OutputDebugString( "IPC_PLAYING_FILE" );
        OutputDebugString(( char* )wParam );
        
        if ( !master_built )
        {
			OutputDebugString( "Play: Rebuilding track lists" );
            
            build_master();
            copy_master();
            
            master_built = 1;
        }
        
        // Restore playing status
        if ( is_pause )
        {
            OutputDebugString( "Pausing:" );
            SendMessage( hwnd, WM_COMMAND, WINAMP_PAUSE, 0 );
        }
        
        is_pause = 0;
    }
    
    // Mark the playlist as dirty upon any modification
    if ( uMsg == WM_USER && lParam == IPC_PLAYLIST_MODIFIED )
    {
        master_built = 0;
        
        // Clear the history
        history_clear();
    }
    
    
    if ( uMsg == WM_USER && lParam == IPC_GET_PREVIOUS_PLITEM )
    {
        // If plugin not enabled, let winamp do default action
        if ( !cfg_enabled )
            return -1;
            
        // If there is history, return that and rebuild the random list
        if ( history_size() > 0 )
        {
			// Get playing status
            status = SendMessage( hwnd, WM_WA_IPC, 0, IPC_ISPLAYING );

            // Pretend it is paused if anything but playing.
            is_pause = ( status != IS_PLAY );
            
            if ( is_pause )
                OutputDebugString( "Prev track: Is paused" );

			OutputDebugString( "Prev track: Rebuilding track lists" );

            copy_master();
            return history_pop();
        }
    }
    
    if ( uMsg == WM_USER && lParam == IPC_GET_NEXT_PLITEM )
    {
        // Playlist is dirty! Rebuild
        if ( !master_built )
        {
			OutputDebugString( "Next track: Rebuilding track lists" );
            
            build_master();
            copy_master();
            
            master_built = 1;
        }

		if(	atrack_size() == 0 )
		{
			/* Apparently Winamp crashes anyways if your playlist is all separators
			 * and you can't do anything to stop it. This is stupid. */

			OutputDebugString( "Next track: No playable tracks" );
			return -1;
		}

        index = SendMessage( plugin.hwndParent, WM_WA_IPC, 0, IPC_GETLISTPOS );
        
        // Check for any other plugin that wants to modify the next item
        // Especially JTFE
        ft_index = CallWindowProc( lpWndProcOld, hwnd, uMsg, wParam, lParam );
        
        if ( ft_index != -1 )
        {
            wsprintf( debug_string, "Next track: Fall through index: %d", ft_index );
            OutputDebugString( debug_string );
            
            if ( cfg_enabled )
            {
                history_add( index );
                copy_master();
            }
            
            return ft_index;
        }
        
        // If plugin is not enabled, let Winamp shuffle
        if ( !cfg_enabled )
        {
            return -1;
        }
        
        playlist_wnd = get_playlist_hwnd();
        
        pl_len = SendMessage( hwnd, WM_WA_IPC, 0, IPC_GETLISTLENGTH );
        
        file.fileindex = index; // This is zero indexed
        ret = SendMessage( playlist_wnd, WM_WA_IPC, IPC_PE_GETINDEXTITLE, ( LPARAM ) & file );
        
        // If it returns 0 then track information was received
        if ( !ret )
        {
            // Check the track type to determine our behavior
            
            int type = atrack_type( index );
            
            // Get playing status
            status = SendMessage( hwnd, WM_WA_IPC, 0, IPC_ISPLAYING );

            // Pretend it is paused if anything but playing. Don't include separators because they are always stopped.
            is_pause = ( status != IS_PLAY && type != IS_ALBUM_SEP && type != IS_RANDOM_SEP );
            
            if ( is_pause )
                OutputDebugString( "Next track: Is paused" );
                
            wsprintf( debug_string, "Next track: Track type: %d", type );
            OutputDebugString( debug_string );
            
            if ( ( type == IS_ALBUM || type == IS_ALBUM_SEP ) && index < pl_len - 1 )
            {
                /* Track is an album separator or is in an album. Do not shuffle. Return
                 * the next in the playlist */
                OutputDebugString( "In an album:" );
                wsprintf( debug_string, "Old index: %d", index );
                OutputDebugString( debug_string );
                
                if ( type == IS_ALBUM )
                    history_add( index );
                    
                return ( index + 1 ) % pl_len;
            }
            else
            {
                /* Track is a random separator, the end of an album, the last album separator,
				 * or in a random section.
                 * Select a random track from the remaining list */
                is_shuffle = SendMessage( hwnd, WM_WA_IPC, 0, IPC_GET_SHUFFLE );
                
                if ( is_shuffle )
                {
                    int rand_i;
                    
                    // Return random number in interval [0 atrack_size()]
                    OutputDebugString( "Next track: Not in an album / exiting an album" );
                    
                    wsprintf( debug_string, "Next track: Items remaining: %d", atrack_size() );
                    OutputDebugString( debug_string );
                    
                    // Select random entry and play the entry
                    rand_i = ( unsigned int )( atrack_size() * genrand_real2() );
                    next = rm_atrack( rand_i );
                    
                    wsprintf( debug_string, "Next track: Random selected: %d", next );
                    OutputDebugString( debug_string );
                    
                    // If the list of random tracks is empty, copy from the master list
                    if ( atrack_size() == 0 )
                    {
                        OutputDebugString( "Next track: Track list empty, rebuilding the list" );
                        copy_master();
                    }
                    
                    // Don't add separators to the history
                    if ( type == IS_ALBUM_LAST || type == IS_RANDOM )
                        history_add( index );
                        
                    return next;
                }
                else
                    return -1;
            }
        }
        return -1;
    }
    
    return CallWindowProc( lpWndProcOld, hwnd, uMsg, wParam, lParam );
}
예제 #6
0
void			builtin_history_clear(void)
{
	history_clear(edit_singleton()->history);
}
예제 #7
0
파일: history.c 프로젝트: holodnak/nesemu3
void history_destroy(history_t *h)
{
	history_clear(h);
	mem_free(h);
}