Esempio n. 1
0
/* handler for parser KEY_NAME state */
static
const CHAR*
key_name_state(
    struct parser *parser,
    const CHAR *pos)
{
    const CHAR *p, *token_end = parser->start;

    for (p = pos; !is_eol(parser, p); p++)
    {
        if (*p == ',') break;
        switch(*p)
        {

        case '=':
            push_token(parser, token_end);
            if (!add_field_from_token(parser, 1)) return NULL;
            parser->start = p + 1;
            push_state(parser, VALUE_NAME);
            set_state(parser, LEADING_SPACES);
            return p + 1;
        case ';':
            push_token(parser, token_end);
            if (!add_field_from_token(parser, 0)) return NULL;
            push_state(parser, LINE_START);
            set_state(parser, COMMENT);
            return p + 1;
        case '"':
            push_token(parser, token_end);
            parser->start = p + 1;
            push_state(parser, KEY_NAME);
            set_state(parser, QUOTES);
            return p + 1;
        case '\\':
            push_token(parser, token_end);
            parser->start = p;
            push_state(parser, KEY_NAME);
            set_state(parser, EOL_BACKSLASH);
            return p;
        default:
            if (!isspace((unsigned char)*p)) token_end = p + 1;
            else
            {
                push_token(parser, p);
                push_state(parser, KEY_NAME);
                set_state(parser, TRAILING_SPACES);
                return p;
            }
            break;
        }
    }
    push_token(parser, token_end);
    set_state(parser, VALUE_NAME);
    return p;
}
Esempio n. 2
0
static void expect_value_or_endlst(JSONRD_T *jsonrd) {
  switch (jsonrd->token.type) {
    case TOK_STRING:
      if (jsonrd->callbacks.atom_string) {
        STR_T *value;
        value = jsonrd->token.value_string;
        jsonrd->callbacks.atom_string(jsonrd->user_data, str_internal(value), str_len(value));
      }
      goto atom_value;
    case TOK_NUMBER:
      if (jsonrd->callbacks.atom_number) {
        jsonrd->callbacks.atom_number(jsonrd->user_data, jsonrd->token.value_number);
      }
      goto atom_value;
    case TOK_TRUE:
    case TOK_FALSE:
      if (jsonrd->callbacks.atom_bool) {
        jsonrd->callbacks.atom_bool(jsonrd->user_data, jsonrd->token.value_bool);
      }
      goto atom_value;
    case TOK_NULL:
      if (jsonrd->callbacks.atom_null) {
        jsonrd->callbacks.atom_null(jsonrd->user_data);
      }
atom_value:
      jsonrd->state = PS_COMMA_OR_ENDLST;
      break;
    case TOK_STARTOBJ:
      if (jsonrd->callbacks.start_object) {
        jsonrd->callbacks.start_object(jsonrd->user_data);
      }
      push_state(jsonrd, PS_COMMA_OR_ENDLST);
      jsonrd->state = PS_PROPERTY_OR_ENDOBJ;
      break;
    case TOK_STARTLST:
      if (jsonrd->callbacks.start_list) {
        jsonrd->callbacks.start_list(jsonrd->user_data);
      }
      push_state(jsonrd, PS_COMMA_OR_ENDLST);
      jsonrd->state = PS_VALUE_OR_ENDLST;
      break;
    case TOK_ENDLST:
      if (jsonrd->callbacks.end_list) {
        jsonrd->callbacks.end_list(jsonrd->user_data);
      }
      jsonrd->state = pop_state(jsonrd);
      if (jsonrd->state == PS_COMMA_OR_ENDOBJ && jsonrd->callbacks.end_property) {
        jsonrd->callbacks.end_property(jsonrd->user_data);
      }
      break;
    default:
      error(jsonrd, "Expected a list value or the end of the list.");
  }
}
Esempio n. 3
0
	GLvoid CMenuButton::draw()
	{	
		if (over)
		{
			push_state();
			GLfloat old_w = extent.width;
			GLfloat old_h = extent.height;
			scale(1.012f,1.12f);
			translate(-(extent.width-old_w)/2.0f,-(extent.height-old_h)/2.0f,0.0f);

			glPushMatrix();	
			set_color(red,0.0f,0.0f);
			red+=red_speed;
			if (red>1.0f || red<0.0f)
			{
				red_speed=-red_speed;
			}
			over=false;

			set_texture(effect_texture);
			CTexturedGUIButton::draw();
			glPopMatrix();

			pop_state();	
		}
		else
		{
			red=0.0f;
		}		

		set_color(1.0f,1.0f,1.0f);
		set_texture(normal_texture);
		CTexturedGUIButton::draw();
		set_caption_color(1.0f,0.0f,0.0f);
	}
Esempio n. 4
0
static void cmd_sem_unlock( TARGET * t )
{
    CMD * cmd = ( CMD * )t->cmds;
    TARGETS * iter;
    /* Release the semaphores. */
    for ( iter = cmd->unlock; iter; iter = iter->next )
    {
        if ( DEBUG_EXECCMD )
            printf( "SEM: %s is now free\n", object_str(
                iter->target->name ) );
        --iter->target->asynccnt;
        assert( iter->target->asynccnt <= 0 );
    }
    for ( iter = cmd->unlock; iter; iter = iter->next )
    {
        /* Find a waiting target that's ready */
        while ( iter->target->parents )
        {
            TARGETS * first = iter->target->parents;
            TARGET * t1 = first->target;

            /* Pop the first waiting CMD */
            if ( first->next )
                first->next->tail = first->tail;
            iter->target->parents = first->next;
            BJAM_FREE( first );

            if ( cmd_sem_lock( t1 ) )
            {
                push_state( &state_stack, t1, NULL, T_STATE_MAKE1C );
                break;
            }
        }
    }
}
Esempio n. 5
0
int
make1( TARGET *t )
{
	state *pState;

	memset( (char *)counts, 0, sizeof( *counts ) );

	/* Recursively make the target and its dependents */
	push_state(&state_stack, t, NULL, T_STATE_MAKE1A);

	do
	{
		while((pState = current_state(&state_stack)) != NULL)
		{
            if (intr) 
                pop_state(&state_stack);

			switch(pState->curstate)
			{
			case T_STATE_MAKE1A:
				make1a(pState);
				break;
			case T_STATE_MAKE1ATAIL:
				make1atail(pState);
				break;
			case T_STATE_MAKE1B:
				make1b(pState);
				break;
			case T_STATE_MAKE1C:
				make1c(pState);
				break;
			case T_STATE_MAKE1D:
				make1d(pState);
				break;
			default:
				break;
			}
		}
	

	/* Wait for any outstanding commands to finish running. */
	} while( execwait() );

	clear_state_freelist();

	/* Talk about it */
	if( counts->failed )
	    printf( "...failed updating %d target%s...\n", counts->failed,
		        counts->failed > 1 ? "s" : "" );

	if( DEBUG_MAKE && counts->skipped )
	    printf( "...skipped %d target%s...\n", counts->skipped,
		        counts->skipped > 1 ? "s" : "" );

	if( DEBUG_MAKE && counts->made )
	    printf( "...updated %d target%s...\n", counts->made,
		        counts->made > 1 ? "s" : "" );

	return counts->total != counts->made;
}
Esempio n. 6
0
void Game::change_state(Gamestate* state){
	if(!this->states.empty())
		pop_state();
	push_state(state);

	return;
}
Esempio n. 7
0
static carmen_inline void 
add_neighbours_to_queue(int x, int y, queue state_queue)
{
  int index;
  double cur_util, new_util, multiplier;
  int cur_x, cur_y;
  double parent_utility;
  
  parent_utility = *utility_value(x, y);

  for (index = 0; index < NUM_ACTIONS; index+=2) 
    {      
      if (index % 2 == 1)
	multiplier = M_SQRT2;
      else
	multiplier = 1;
      
      cur_x = x + carmen_planner_x_offset[index];
      cur_y = y + carmen_planner_y_offset[index];

      if (is_out_of_map(cur_x, cur_y) || *(costs+cur_x*y_size + cur_y) > 0.5)
	continue;
      
      cur_util = *(utility_value(cur_x, cur_y));
      new_util = parent_utility - *(costs+cur_x*y_size + cur_y)*multiplier;
      assert(new_util > 0);
      if (cur_util < 0)
	push_state(cur_x, cur_y, new_util, state_queue);
    } /* End of for (Index = 0...) */
  
}
Esempio n. 8
0
static void
make1a( state *pState)
{
    TARGET* t = pState->t;
	TARGETS	*c;
    TARGETS   *inc;

	/* If the parent is the first to try to build this target */
	/* or this target is in the make1c() quagmire, arrange for the */
	/* parent to be notified when this target is built. */

	if( pState->parent )
	    switch( pState->t->progress )
	{
	case T_MAKE_INIT:
	case T_MAKE_ACTIVE:
	case T_MAKE_RUNNING:
	    pState->t->parents = targetentry( pState->t->parents, pState->parent );
	    pState->parent->asynccnt++;
	}

	if( pState->t->progress != T_MAKE_INIT )
	{
		pop_state(&state_stack);
		return;
	}

	/* Asynccnt counts the dependents preventing this target from */
	/* proceeding to make1b() for actual building.  We start off with */
	/* a count of 1 to prevent anything from happening until we can */
	/* call all dependents.  This 1 is accounted for when we call */
	/* make1b() ourselves, below. */

	pState->t->asynccnt = 1;

    /* Add header node that was created during building process. */

    inc = 0;
    for (c = t->depends; c; c = c->next) {        
        if (c->target->rescanned && c->target->includes)
            inc = targetentry(inc, c->target->includes);           
    }
    t->depends = targetchain(t->depends, inc);

	/* against circular dependency. */

	pState->t->progress = T_MAKE_ONSTACK;

	{
		stack temp_stack = { NULL };
        for( c = t->depends; c && !intr; c = c->next )            
            push_state(&temp_stack, c->target, pState->t, T_STATE_MAKE1A);

		/* using stacks reverses the order of execution. Reverse it back */
		push_stack_on_stack(&state_stack, &temp_stack);
	}

	pState->curstate = T_STATE_MAKE1ATAIL;
}
Esempio n. 9
0
/*
 * jsonwr_property
 * Write a property. The next call must be a value.
 */
void jsonwr_property(JSONWR_T* jsonwr, char* property) {
  enforce_state(jsonwr->state, 2, JSON_EMPTY_OBJECT, JSON_OBJECT);
  if (jsonwr->state != JSON_EMPTY_OBJECT) fputs(",", jsonwr->file);
  write_nl_indent(jsonwr);
  convert_string(jsonwr->value_buf, property);
  fputs(str_internal(jsonwr->value_buf), jsonwr->file);
  fputs(": ", jsonwr->file);
  push_state(jsonwr->stack, JSON_OBJECT);
  jsonwr->state = JSON_PROPERTY;
}
Esempio n. 10
0
	GLvoid CItemButton::on_mouse_down()
	{
		set_texture(mouse_down_texture);		

		if (!first_down)
		{
			push_state(&top_texture_extent);			
			scale(0.9f,0.9f,&top_texture_extent);
			first_down=true;
		}
	}
Esempio n. 11
0
static void make_closure(
    void *closure, int status, timing_info* time)
{
    TARGET* built = (TARGET*)closure;

    call_timing_rule(built, time);
    if (DEBUG_EXECCMD)
        printf("%f sec system; %f sec user\n", time->system, time->user);
    
    push_state(&state_stack, built, NULL, T_STATE_MAKE1D)->status = status;
}
Esempio n. 12
0
static void handle_forwards_frame() {
    if (is_backwards_frame) {
        // We just stopped rewinding. To get a clean transition in the sound,
        // load the same frame we just rewound and run it forwards.
        load_top_state();
        is_backwards_frame = false;
    }
    else
        // Save the state to the rewind buffer. Rewind is always enabled for
        // now.
        push_state();
}
Esempio n. 13
0
sc_addr sc_generator::enter_system(sc_addr sys_sign)
{
	element(sys_sign);
	push_state(true);

	real_gen_state &st = GET_STATE();
	st.sys_sign = sys_sign;
	st.system_segment = active_segment;
	st.system_arc_type = system_arc_type;

	return sys_sign;
}
Esempio n. 14
0
sc_addr sc_generator::enter_set(sc_addr a_set)
{
	element(a_set);
	push_state(false);
	real_gen_state &old_st = *(state->end()-2);
	real_gen_state &st = GET_STATE();
	st.sys_sign = old_st.sys_sign;
	st.system_set = old_st.system_set;
	old_st.system_set.clear();
	st.set = a_set;
	return a_set;
}
Esempio n. 15
0
/* push the next MAKE1C state after a command is run. */
static void push_cmds( CMDLIST * cmds, int status )
{
    CMDLIST * cmd_iter;
    for( cmd_iter = cmds; cmd_iter; cmd_iter = cmd_iter->next )
    {
        if ( cmd_iter->iscmd )
        {
            CMD * next_cmd = cmd_iter->impl.cmd;
            /* Propagate the command status. */
            if ( next_cmd->status < status )
                next_cmd->status = status;
            if ( --next_cmd->asynccnt == 0 )
            {
                /* Select the first target associated with the action.
                 * This is safe because sibling CMDs cannot have targets
                 * in common.
                 */
                TARGET * first_target = bindtarget( list_front( lol_get( &next_cmd->args, 0 ) ) );
                first_target->cmds = (char *)next_cmd;
                push_state( &state_stack, first_target, NULL, T_STATE_MAKE1C );
            }
            else if ( DEBUG_EXECCMD )
            {
                TARGET * first_target = bindtarget( list_front( lol_get( &next_cmd->args, 0 ) ) );
                printf( "Delaying %s %s: %d targets not ready\n", object_str( next_cmd->rule->name ), object_str( first_target->boundname ), next_cmd->asynccnt );
            }
        }
        else
        {
            /* This is a target that we're finished updating */
            TARGET * updated_target = cmd_iter->impl.t;
            if ( updated_target->status < status )
                updated_target->status = status;
            updated_target->cmds = NULL;
            push_state( &state_stack, updated_target, NULL, T_STATE_MAKE1C );
        }
    }
}
Esempio n. 16
0
static void make_closure(
    void *closure, int status, timing_info* time, char *executed_command,
    char *command_output)
{
    TARGET* built = (TARGET*)closure;

    call_timing_rule(built, time);
    if (DEBUG_EXECCMD)
        printf("%f sec system; %f sec user\n", time->system, time->user);

    call_action_rule(built, status, time, executed_command, command_output);
    
    push_state(&state_stack, built, NULL, T_STATE_MAKE1D)->status = status;
}
Esempio n. 17
0
static void
parse_tag_element (GMarkupParseContext  *context,
                   const gchar          *element_name,
                   const gchar         **attribute_names,
                   const gchar         **attribute_values,
                   ParseInfo            *info,
                   GError              **error)
{
  GtkTextTag  *tag;
  const gchar *attribute_name  = NULL;
  const gchar *attribute_value = NULL;

  g_assert (peek_state (info) == STATE_MARKUP ||
            peek_state (info) == STATE_TAG    ||
            peek_state (info) == STATE_UNKNOWN);

  if (attribute_names)
    attribute_name = attribute_names[0];

  if (attribute_values)
    attribute_value = attribute_values[0];

  tag = gimp_text_buffer_name_to_tag (GIMP_TEXT_BUFFER (info->register_buffer),
                                      element_name,
                                      attribute_name, attribute_value);

  if (tag)
    {
      info->tag_stack = g_slist_prepend (info->tag_stack, tag);

      push_state (info, STATE_TAG);
    }
  else
    {
      push_state (info, STATE_UNKNOWN);
    }
}
Esempio n. 18
0
int make1( TARGET * const t )
{
    state * pState;

    memset( (char *)counts, 0, sizeof( *counts ) );

    /* Recursively make the target and its dependencies. */
    push_state( &state_stack, t, NULL, T_STATE_MAKE1A );

    while ( 1 )
    {
        while ( ( pState = current_state( &state_stack ) ) )
        {
            if ( intr )
                pop_state( &state_stack );

            switch ( pState->curstate )
            {
                case T_STATE_MAKE1A: make1a( pState ); break;
                case T_STATE_MAKE1B: make1b( pState ); break;
                case T_STATE_MAKE1C: make1c( pState ); break;
                default:
                    assert( !"make1(): Invalid state detected." );
            }
        }
        if ( !cmdsrunning )
            break;
        /* Wait for outstanding commands to finish running. */
        exec_wait();
    }

    clear_state_freelist();

    /* Talk about it. */
    if ( counts->failed )
        printf( "...failed updating %d target%s...\n", counts->failed,
            counts->failed > 1 ? "s" : "" );
    if ( DEBUG_MAKE && counts->skipped )
        printf( "...skipped %d target%s...\n", counts->skipped,
            counts->skipped > 1 ? "s" : "" );
    if ( DEBUG_MAKE && counts->made )
        printf( "...updated %d target%s...\n", counts->made,
            counts->made > 1 ? "s" : "" );

    return counts->total != counts->made;
}
Esempio n. 19
0
static int find_start(JSONRD_T *jsonrd, const char *chunk, size_t size) {
  int i;
  for (i = 0; i < size; i++) {
    if (chunk[i] == '{') {
      push_state(jsonrd, PS_FIND_LANDMARK);
      jsonrd->state = PS_PROPERTY_OR_ENDOBJ;
      jsonrd->token.state = TS_FOUND_TOKEN; // causes the token data to be reset on next_token call
      if (jsonrd->callbacks.start_data) {
        jsonrd->callbacks.start_data(jsonrd->user_data, str_internal(jsonrd->buf), str_len(jsonrd->buf));
      }
      if (jsonrd->callbacks.start_object) {
        jsonrd->callbacks.start_object(jsonrd->user_data);
      }
      return i + 1;
    }
  }
  return size;
}
// Change the game state, erasing the previous one
void GameStateMachine::change_state(GameState* state)
{
	if (!m_game_states.empty())
	{
		// Do not change to the same state
		if (m_game_states.back()->get_state_id() == state->get_state_id())
		{
			std::cerr << "Tried to change to the same state" << std::endl;
			return;
		}

		std::clog << "Changing state from " << m_game_states.back()->get_state_id() << " to " << state->get_state_id() << "..." << std::endl;

		pop_state();
	}

	push_state(state);
}		
Esempio n. 21
0
/*
 * jsonwr_open
 * Opens a JSON writer which aims to make human readable JSON
 * indented min_cols with each sub-section indented another tab_cols
 * aiming for a maximum line length of line_cols.
 */
JSONWR_T* jsonwr_open(FILE *dest, int min_cols, int tab_cols, int line_cols) {
  JSONWR_T *jsonwr;
  jsonwr = mm_malloc(sizeof(JSONWR_T));
  memset(jsonwr, 0, sizeof(JSONWR_T));
  jsonwr->file = dest;
  jsonwr->min_cols = min_cols;
  jsonwr->tab_cols = tab_cols;
  jsonwr->line_cols = line_cols;
  jsonwr->indent = min_cols + tab_cols;
  jsonwr->column = 0;
  jsonwr->value_buf = str_create(10);
  jsonwr->line_buf = str_create(line_cols);
  jsonwr->state = JSON_EMPTY_OBJECT;
  jsonwr->stack = linklst_create();
  push_state(jsonwr->stack, JSON_DONE);
  fputc('{', jsonwr->file);
  return jsonwr;
}
Esempio n. 22
0
static void
start_element_handler (GMarkupParseContext  *context,
                       const gchar          *element_name,
                       const gchar         **attribute_names,
                       const gchar         **attribute_values,
                       gpointer              user_data,
                       GError              **error)
{
  ParseInfo *info = user_data;

  switch (peek_state (info))
    {
    case STATE_START:
      if (! strcmp (element_name, "markup"))
        {
          if (! check_no_attributes (context, element_name,
                                     attribute_names, attribute_values,
                                     error))
            return;

          push_state (info, STATE_MARKUP);
          break;
        }
      else
        {
          set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
                     _("Outermost element in text must be <markup> not <%s>"),
                     element_name);
        }
      break;

    case STATE_MARKUP:
    case STATE_TAG:
    case STATE_UNKNOWN:
      parse_tag_element (context, element_name,
                         attribute_names, attribute_values,
                         info, error);
      break;

    default:
      g_assert_not_reached ();
      break;
    }
}
Esempio n. 23
0
/* handler for parser SECTION_NAME state */
static const WCHAR *section_name_state( struct parser *parser, const WCHAR *pos )
{
  const WCHAR *p;

  for (p = pos; !is_eol( parser, p ); p++)
    {
      if (*p == ']')
        {
          push_token( parser, p );
          if (add_section_from_token( parser ) == NULL)
            return NULL;
          push_state( parser, LINE_START );
          set_state( parser, COMMENT );  /* ignore everything else on the line */
          return p + 1;
        }
    }
  parser->error = INF_STATUS_BAD_SECTION_NAME_LINE; /* unfinished section name */
  return NULL;
}
Esempio n. 24
0
/* handler for parser LINE_START state */
static
const CHAR*
line_start_state(
    struct parser *parser,
    const CHAR *pos)
{
    const CHAR *p;

    for (p = pos; !is_eof(parser, p); p++)
    {
        switch(*p)
        {
        case '\r':
            continue;

        case '\n':
            parser->line_pos++;
            close_current_line(parser);
            break;

        case ';':
            push_state(parser, LINE_START);
            set_state(parser, COMMENT);
            return p + 1;

        case '[':
            parser->start = p + 1;
            set_state(parser, SECTION_NAME);
            return p + 1;

        default:
            if (!isspace((unsigned char)*p))
            {
                parser->start = p;
                set_state(parser, KEY_NAME);
                return p;
            }
            break;
        }
    }
    close_current_line(parser);
    return NULL;
}
Esempio n. 25
0
/* handler for parser EOL_BACKSLASH state */
static
const CHAR*
eol_backslash_state(
    struct parser *parser,
    const CHAR *pos )
{
    const CHAR *p;

    for (p = pos; !is_eof(parser, p); p++)
    {
        switch(*p)
        {
        case '\r':
            continue;

        case '\n':
            parser->line_pos++;
            parser->start = p + 1;
            set_state(parser, LEADING_SPACES);
            return p + 1;

        case '\\':
            continue;

        case ';':
            push_state(parser, EOL_BACKSLASH);
            set_state(parser, COMMENT);
            return p + 1;

        default:
            if (isspace((unsigned char)*p))
                continue;
            push_token(parser, p);
            pop_state(parser);
            return p;
        }
    }
    parser->start = p;
    pop_state(parser);

    return p;
}
Esempio n. 26
0
/* Add a new state to the current chain of states without
   pushing it onto the state stack */
void chain_state(interp_core_type *interp) {
    object_type *new_state=interp->added;

    TRACE("C")

    /* handle the first list entry correctly */
      if(car(interp->current)==0) {
	/* we don't need to do anythin else here */
	set(interp, CAR);
	return;
    } 

    /* Before throwing current, we 
       need to make sure that it has been added */

    push_state(interp);
    interp->state_stack->type=CHAIN;
    
    add_object(interp, new_state);
    set(interp, CAR);

}
static svn_error_t *
start_getloc(svn_ra_serf__xml_parser_t *parser,
             void *userData,
             svn_ra_serf__dav_props_t name,
             const char **attrs)
{
    loc_context_t *loc_ctx = userData;

    if (!loc_ctx->state && strcmp(name.name, "get-locations-report") == 0)
    {
        push_state(loc_ctx, REPORT);
    }
    else if (loc_ctx->state &&
             loc_ctx->state->state == REPORT &&
             strcmp(name.name, "location") == 0)
    {
        svn_revnum_t rev = SVN_INVALID_REVNUM;
        const char *revstr, *path;

        revstr = svn_xml_get_attr_value("rev", attrs);
        if (revstr)
        {
            rev = SVN_STR_TO_REV(revstr);
        }

        path = svn_xml_get_attr_value("path", attrs);

        if (SVN_IS_VALID_REVNUM(rev) && path)
        {
            apr_hash_set(loc_ctx->paths,
                         apr_pmemdup(loc_ctx->pool, &rev, sizeof(rev)),
                         sizeof(rev),
                         apr_pstrdup(loc_ctx->pool, path));
        }
    }

    return SVN_NO_ERROR;
}
Esempio n. 28
0
/*
 * Start either an array or object which is surrounded by brackets
 */
static void write_start(JSONWR_T* jsonwr, JSON_EN new_state) {
  enforce_state(jsonwr->state, 4, JSON_PROPERTY, JSON_EMPTY_ARRAY, 
      JSON_SL_ARRAY, JSON_ML_ARRAY);
  if (jsonwr->state != JSON_PROPERTY) {// an array
    if (jsonwr->state != JSON_ML_ARRAY) {
      fputc('[', jsonwr->file);
      jsonwr->column += 1;
      write_nl_indent(jsonwr);
    }
    if (jsonwr->state == JSON_SL_ARRAY) {
      fputs(str_internal(jsonwr->line_buf), jsonwr->file);
      jsonwr->column += str_len(jsonwr->line_buf);
    }
    if (jsonwr->state != JSON_EMPTY_ARRAY) {
      fputs(", ", jsonwr->file);
      jsonwr->column += 2;
    }
    push_state(jsonwr->stack, JSON_ML_ARRAY);
    if ((jsonwr->column + 1) >= jsonwr->line_cols) write_nl_indent(jsonwr);
  }
  jsonwr->state = new_state;
  jsonwr->column += 1;
  jsonwr->indent += jsonwr->tab_cols;
}
Esempio n. 29
0
 void set_state(Game_State* state) { pop_state(); push_state(state); }
Esempio n. 30
0
int main()
{
    //shell vars
    bool render = false;

    //allegro vars
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;

    //allegro init functions
    printf ("Initializing allegro\n");
    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Creating display\n");
    display = al_create_display(WIDTH, HEIGHT);
    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Installing addons\n");
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(10);

    //project inits
    srand(time(NULL));

    printf("Initializing timer\n");
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    printf("Registering event sources\n");
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    printf("Init mouse and keyboard\n");
    init_keyboard();
    init_mouse();

    printf("Loading assets\n");
    load_bitmaps();
    load_fonts();
    load_samples();

    printf ("Creating manager\n");
    push_state(new TitleMenu());
    
    printf("Beginning game\n");
    while (!is_game_over())
    {
        //declare an event
        ALLEGRO_EVENT event;

        //monitor event sources
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            end_game();
        }
        else if (event.type == ALLEGRO_EVENT_TIMER)
        {
            render = true;

            update_mouse();
            update_keyboard();

            handle_key();
            update_game();
        }

        // Render screen
        if (render && al_event_queue_is_empty(event_queue))
        {
            render = false;
            render_game();
            al_flip_display();
        }
    }

    unload_assets();
    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_timer(timer);

    return 0;
}