iterator(IteratorData const& iterdata_, base_iterator_type& first , base_iterator_type const& last, char_type const* state = 0) : base_type(functor_type(unique_functor_type() , shared_functor_type(iterdata_, first, last))) { set_state(map_state(state)); }
// Runs the Game... void Ultra1::App::Run( ) { // All of the game states we could be in... Intro intro( this ); MainMenu menu( this ); Game game( this ); MapState map_state( this ); WonState won( this ); LostState lost( this ); HelpState help( this ); StoryState story( this ); OptionsState options( this ); // Must be entered into array in same order as the const values... GameState* states[] = { &intro, &menu, &game, &map_state, &won, &lost, &help, &story, &options }; // We start in the intro... StateNumber current_state = INTRO_STATE; while( current_state != QUIT_STATE ) { // Run the current state and assign the next state to it... current_state = states[current_state]->Run( ); } }
void MainMenuState::on_input(const InputData& input) { switch (input.key) { case 'n': { std::unique_ptr<State> map_state(new MapState); states::push_state(std::move(map_state)); } break; case 'q': { states::pop_state(); } break; } }
void event_state (int state, char *remote, char *remote_name, char *local, char *local_context) { last_state = state; /* This is needed for auto-reconnect */ if (state == 0) { connected = 0; /* FIXME: we should wake up the main thread somehow */ /* in fg mode the next incoming packet will do that anyway */ } snprintf (tmp, sizeof (tmp), "S%c0x%x%c%s%c%.50s%c%.50s%c%.50s%c%.50s", delim, state, delim, map_state (state), delim, remote, delim, remote_name, delim, local, delim, local_context); report (tmp); }
/* * Generates a uuid based on version 1 format. * Returns 0 on success and -1 on failure. */ static int uuid_create(struct uuid *uuid) { uuid_time_t timestamp; uuid_node_t system_node; int ret, non_unique = 0; /* * Get the system MAC address and/or cache it */ if (node_init) { bcopy(&node_id_cache, &system_node, sizeof (uuid_node_t)); } else { gen_ethernet_address(&system_node); bcopy(&system_node, &node_id_cache, sizeof (uuid_node_t)); node_init = 1; } /* * Access the state file, mmap it and initialize the shared lock. * file_type tells us whether we had access to the state file or * created a temporary one. */ if (map_state() == -1) return (-1); /* * Acquire the lock */ for (;;) { if ((ret = mutex_lock(&data->lock)) == 0) break; else switch (ret) { case EOWNERDEAD: revalidate_data(&system_node); (void) mutex_consistent(&data->lock); (void) mutex_unlock(&data->lock); break; case ENOTRECOVERABLE: return (ret); } } /* State file is either new or is temporary, get a random clock seq */ if (data->state.clock == 0) { data->state.clock = get_random(); non_unique++; } if (memcmp(&system_node, &data->state.node, sizeof (uuid_node_t)) != 0) data->state.clock++; get_current_time(×tamp); /* * If timestamp is not set or is not in the past, bump * data->state.clock */ if ((data->state.ts == 0) || (data->state.ts >= timestamp)) { data->state.clock++; data->state.ts = timestamp; } if (non_unique) system_node.nodeID[0] |= 0x80; /* Stuff fields into the UUID struct */ format_uuid(uuid, data->state.clock, timestamp, system_node); (void) mutex_unlock(&data->lock); return (0); }