Exemplo n.º 1
0
void Menu_HUD::refresh()
{
	AttributePtr<Attribute_Player>		ptr_player		=	ptr_splitScreen->ptr_player;
	AttributePtr<Attribute_Health>		ptr_health		=	ptr_player->ptr_health;
	AttributePtr<Attribute_WeaponStats>	ptr_weaponStats	=	ptr_player->ptr_weaponStats;

	Ammunition* ammunition = &ptr_weaponStats->ammunition[ptr_weaponStats->currentAmmunitionType];
	FiringMode* firingMode = &ptr_weaponStats->firingMode[ptr_weaponStats->currentFiringModeType];
	int firingIndex = firingMode->type;
	int ammoIndex = ammunition->type;
	float fadeTime = 1.0f;


	//
	// Update powerup display
	//

	hudPowerupDispayer.update();


	//
	// Update scheduling hud
	//

	schedulingHud.refresh();


	//
	// Update weapon info hud
	//

	weaponInfoHud.update(firingIndex, ammoIndex);


	//
	// Show ammunition info
	//

	int numAmmo = firingMode->nrOfShotsLeftInClip[ammoIndex];
	int clipSize = firingMode->clipSize;
	int ammoLeft = ammunition->currentTotalNrOfShots;
	ui.label_ammo->setNum(numAmmo);
	ui.label_totalAmmo->setNum((int)ptr_weaponStats->ammunition[ammoIndex].currentTotalNrOfShots);
	int prev_ammoRatio = ui.progressBar_ammo->value();
	int numFullyReloaded = clipSize;
	if(clipSize > ammoLeft && ammoLeft > 0)
		numFullyReloaded = ammoLeft; 
	int ammoRatio = (int)((numAmmo / (float)numFullyReloaded) * 100);
	int reloadRatio = (int)((firingMode->reloadTimeLeft / (float)firingMode->reloadTime) * 100);

	// Show menu if ammo has changed otherwise fade after a few seconds
	if(reloadRatio == 100 && ammoRatio != prev_ammoRatio)
	{
		prev_ammoRatio = ammoRatio;
		ammoFade = fadeTime;
	}
	else if(reloadRatio != prev_reloadRatio)
	{
		prev_reloadRatio = reloadRatio;
		ammoFade = fadeTime;
	}

	int largestRatio = ammoRatio;
	if(ammoRatio < (100 - reloadRatio))
		largestRatio = (100 - reloadRatio);

	ui.progressBar_ammo->setValue(largestRatio);

	// Hide bar if full
	if(ammoRatio == 100)
		ammoFade = 0.0f;

	// Perform fade
	if(ammoFade > 0.0f)
	{
		ammoFade -= SETTINGS->trueDeltaTime;

		// Show progress bar if hidden
		if(ui.progressBar_ammo->isHidden())
			ui.progressBar_ammo->show();


		ui.progressBar_ammo->update();
	}
	else
	{
		// Hide progress bar if shown
		if(!ui.progressBar_ammo->isHidden())
			ui.progressBar_ammo->hide();
	}


	//
	// Show health info
	//

	if(ptr_health->health < 1.0f && ptr_health->health > 0.0f) //Prevent player health showing as 0 when the player is still alive
	{
		ui.label_health->setNum(1);
	}
	else
	{
		ui.label_health->setNum(static_cast<int>(ptr_health->health));
	}
	

	int healthRatio = (int)((ptr_health->health / ptr_health->maxHealth) * 100);

	// Show menu if health has changed otherwise fade after a few seconds
	if(healthRatio != ui.progressBar_health->value())
	{
		healthFade = fadeTime;
	}

	// Hide bar if dead
	if(ptr_player->detectedAsDead)
		healthFade = 0.0f;

	if(healthFade > 0.0f)
	{
		healthFade -= SETTINGS->trueDeltaTime;

		// Show progress bar if hidden
		if(ui.progressBar_health->isHidden())
			ui.progressBar_health->show();


		// Update value
		ui.progressBar_health->setValue(healthRatio);
		ui.progressBar_health->update();
	}
	else
	{
		// Hide progress-bar if shown
		if(!ui.progressBar_health->isHidden())
			ui.progressBar_health->hide();
	}


	//
	// Display HUD-messages
	//

	hudMessage_manager.update();


	// Show hit effects

	// Player is damaged
	if(hitOverlayFade > 0.0f)
	{
		hitOverlayFade -= SETTINGS->trueDeltaTime;
		if(ui.label_hitOverlay->isHidden())
		{
			ui.label_hitOverlay->show();
		}
	}
	else
	{
		if(!ui.label_hitOverlay->isHidden())
		{
			ui.label_hitOverlay->hide();
		}
	}

	// Player damages another player
	if(crosshair_targetHitFade > 0.0f)
	{
		crosshair_targetHitFade -= SETTINGS->trueDeltaTime;
		if(ui.label_aim_targetHit->isHidden())
		{
			ui.label_aim_targetHit->show();
		}
	}
	else
	{
		if(!ui.label_aim_targetHit->isHidden())
		{
			ui.label_aim_targetHit->hide();
		}
	}


	// Show death effects
	if(ptr_player->detectedAsDead)
	{
		if(ui.label_deathOverlay->isHidden())
		{
			ui.label_deathOverlay->show();
			ui.frame_top->hide();
			ui.label_aim->hide();
			ui.label_firingMode->hide();
			ui.frame_bottom->hide();
			schedulingHud.hide();

			ui.progressBar_health->hide();
			ui.progressBar_ammo->hide();
			
		}
	}
	else
	{
		if(!ui.label_deathOverlay->isHidden())
		{
			ui.label_deathOverlay->hide();
			ui.frame_top->show();
			ui.label_aim->show();
			ui.label_firingMode->show();
			ui.frame_bottom->show();
			schedulingHud.show();
		}
	}

	//
	// Update Scoreboard
	//

	scoreboard.refresh();
	if(ptr_player->detectedAsDead || GET_STATE() == STATE_GAMEOVER || ptr_player->showScoreboard)
	{
		if(ptr_player->showScoreboard)
			scoreboardFade = 0.0f;

		// Show scoreboard if delay has expired
		if(scoreboardFade > 0.0f)
			scoreboardFade -= SETTINGS->trueDeltaTime;
		if(scoreboardFade <= 0.0f)
		{
			// Show scoreboard if hidden
			if(ui.frame_scoreboard->isHidden())
			{
				hudMessage_manager.silenceAllMessages();
				ui.frame_scoreboard->show();
				ptr_player->isScoreBoardVisible = true;

				// Hide aim
				if(!ui.label_aim->isHidden())
				{
					ui.label_aim->hide();
					ui.label_firingMode->hide();
				}
			}
		}
	}
	else
	{
		// Reset scoreboard timer
		scoreboardFade = 2.0f;

		// Hide scoreboard if shown
		if(!ui.frame_scoreboard->isHidden())
		{
			ui.frame_scoreboard->hide();
			ptr_player->isScoreBoardVisible = false;

			// Show aim if it was hidden
			if(ui.label_aim->isHidden())
			{
				ui.label_aim->show();
				ui.label_firingMode->show();
			}
		}
	}




	//
	// Scheduling info
	//

	ui.label_priority_advantage->setNum(ptr_player->priority);

	// Determine priority advantage
	//{
	//	std::string str_priorityAdvantage = "";

	//	int scoreDiff = scoreboard.maxPriority - ptr_player->priority;

	//	// If first player, show score difference to second closest
	//	if(scoreDiff == 0)
	//		scoreDiff = scoreboard.maxPriority - scoreboard.secondMaxPriority;
	//	// ELSE: Show score difference to second closest
	//	else
	//		scoreDiff = ptr_player->cycles - scoreboard.maxPriority;

	//	// Set label
	//	if(scoreDiff >= 0)
	//		ui.label_priority_advantage->setText("+" +QString::number(scoreDiff));
	//	else
	//		ui.label_priority_advantage->setNum(scoreDiff);

	//}





	/*QString str_time = QDateTime::fromTime_t(SETTINGS->timeUntilScheduling).toString("mm:ss");
	ui.label_schedulingTimer->setText(str_time);*/


	//
	// Set cross-hair based on selected ammo
	//

	// Only change if weapon has been switched
	if(index_crosshair != ammoIndex)
	{
		index_crosshair = ammoIndex;

		// Determine image
		QString path;
		switch(index_crosshair) 
		{
		case XKILL_Enums::BULLET:
			path = ":/xkill/images/icons/cross_hairs/crosshair_bullet.png";
			break;
		case XKILL_Enums::SCATTER:
			path = ":/xkill/images/icons/cross_hairs/crosshair_scatter.png";
			break;
		case XKILL_Enums::EXPLOSIVE:
			path = ":/xkill/images/icons/cross_hairs/crosshair_explosive.png";
			break;
		default:
			path = ":/xkill/images/icons/default.png";
			break;
		}

		// Set image to label
		ui.label_aim->setPixmap(path);
	}


	//
	// Set indicator based on firiring-mode
	//

	// Only change if weapon has been switched
	if(index_firingMode != firingIndex)
	{
		index_firingMode = firingIndex;
		firingModeFade = fadeTime;

		// Determine image
		QString path;
		switch(index_firingMode)
		{
		case XKILL_Enums::SINGLE:
			path = ":/xkill/images/icons/cross_hairs/firing_single.png";
			break;
		case XKILL_Enums::SEMI:
			path = ":/xkill/images/icons/cross_hairs/firing_semi.png";
			break;
		case XKILL_Enums::AUTO:
			path = ":/xkill/images/icons/cross_hairs/firing_auto.png";
			break;
		default:
			path = ":/xkill/images/icons/default.png";
			break;
		}

		// Set image to label
		ui.label_firingMode->setPixmap(path);
	}

	//if(firingModeFade > 0.0f)
	//{
	//	firingModeFade -= SETTINGS->trueDeltaTime;

	//	// Show progress bar if hidden
	//	if(ui.label_firingMode->isHidden())
	//		ui.label_firingMode->show();
	//}
	//else
	//{
	//	// Hide progress-bar if shown
	//	if(!ui.label_firingMode->isHidden())
	//		ui.label_firingMode->hide();
	//}

	 
	// Update scoreboard progress bars
	bool isEnabled_cycleLimit = SETTINGS->cycleLimit != 0;
	bool isEnabled_timeLimit = SETTINGS->timeLimit != 0;
	int highestCycles = scoreboard.maxCycles;
	if(isEnabled_cycleLimit && scoreboard.previousMaxCycles != highestCycles)
	{
		scoreboard.previousMaxCycles = highestCycles;

		// Perform update
		int cyclesLimit = SETTINGS->cycleLimit;
		int cycleRatio = (int)((highestCycles/(float)cyclesLimit) * 100);
		ui.progressBar_cycleRatio->setValue(cycleRatio);
		ui.progressBar_cycleRatio->update();
		QString str_cycleRatio = QString::number(highestCycles) + "/" + QString::number(cyclesLimit)  + " Cycles";
		ui.label_cycleRatio->setText(str_cycleRatio);
	}
	int currentTime = SETTINGS->timeLimit - SETTINGS->timeLeft;
	if(isEnabled_timeLimit && scoreboard.previousTime != currentTime)
	{
		scoreboard.previousTime = currentTime;

		// Perform update
		int timeLimit = SETTINGS->timeLimit;
		int timeRatio = (int)((currentTime/(float)timeLimit) * 100);
		ui.progressBar_timeRatio->setValue(timeRatio);
		ui.progressBar_timeRatio->update();
		QString str_timeRatio = QString::number(currentTime) + "/" + QString::number(timeLimit)  + " Time";
		ui.label_timeRatio->setText(str_timeRatio);
	}
}
Exemplo n.º 2
0
void sc_generator::push_state(bool is_system)
{
	state->push_back(real_gen_state());
	GET_STATE().system_context = is_system;
}
Exemplo n.º 3
0
/*
 * This will check with plug-ins if dependencies for stop is met.
 * If this returns FALSE deps for stopping are not met, try again later.
 * If this returns FAIL stop deps, wont EVER be met, stop trying.
 */
int initng_depend_stop_dep_met(active_db_h * service, int verbose)
{
	active_db_h *currentA = NULL;
	int count = 0;

	assert(service);

	/*
	 * Check so all deps, that needs service, is down.
	 * if there are services depending on this one still running,
	 * return false and still try.
	 */
	while_active_db(currentA) {
		count++;
		if (service->depend_cache >= count)
			continue;

		/* temporary increase depend_cache - will degrese before
		 * reutrn (FALSE) */
		service->depend_cache++;

		if (currentA == service)
			continue;

		/* Does service depends on current ?? */
		if (initng_depend(currentA, service) == FALSE)
			continue;

		switch (GET_STATE(currentA)) {
		/* if its done, this is perfect */
		case IS_DOWN:
			continue;

		/* If the dep is failed, continue */
		case IS_FAILED:
			continue;

		/* BIG TODO.
		 * This is not correct, but if we wait for a service that is
		 * starting to stop, and that service is waiting for this
		 * service to start, until it starts, makes a deadlock.
		 *
		 * Asuming that STARTING services WAITING_FOR_START_DEP are
		 * down for now.
		 */
		case IS_STARTING:
			if (strstr(currentA->current_state->name,
				   "WAITING_FOR_START_DEP"))
				continue;
			break;
		}

#ifdef DEBUG
		/* else RETURN */
		if (verbose)
			D_("still waiting for service %s state %s\n",
			   currentA->name, currentA->current_state->name);
		else
			D_("still waiting for service %s state %s\n",
			   currentA->name, currentA->current_state->name);
#endif

		/* no, the dependency are not met YET */
		service->depend_cache--;
		return FALSE;
	}

	/* run the global module dep check */
	{
		s_event event;

		event.event_type = &EVENT_STOP_DEP_MET;
		event.data = service;

		initng_event_send(&event);
		if (event.status == FAILED) {
			if (verbose) {
				F_("Service %s can not be started because a "
				   "module (START_DEP_MET) says so.\n",
				   service->name);
			}

			return FALSE;
		}
	}

	service->depend_cache = 0;
	return TRUE;
}
Exemplo n.º 4
0
/*
 * call-seq: allow_nan?
 *
 * Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise
 * returns false.
 */
static VALUE cState_allow_nan_p(VALUE self)
{
    GET_STATE(self);
    return state->allow_nan ? Qtrue : Qfalse;
}
Exemplo n.º 5
0
/*
 * call-seq: remember(object)
 *
 * Remember _object_, to find out if it was already encountered (if a cyclic
 * data structure is rendered). 
 */
static VALUE cState_remember(VALUE self, VALUE object)
{
    GET_STATE(self);
    return rb_hash_aset(state->seen, rb_obj_id(object), Qtrue);
}
Exemplo n.º 6
0
/*
 * call-seq: array_nl()
 *
 * This string is put at the end of a line that holds a JSON array.
 */
static VALUE cState_array_nl(VALUE self)
{
    GET_STATE(self);
    return state->array_nl;
}
Exemplo n.º 7
0
/*
 * call-seq: check_circular?
 *
 * Returns true, if circular data structures should be checked,
 * otherwise returns false.
 */
static VALUE cState_check_circular_p(VALUE self)
{
    GET_STATE(self);
    return state->check_circular ? Qtrue : Qfalse;
}
Exemplo n.º 8
0
/*
 * call-seq: quirks_mode=(enable)
 *
 * If set to true, enables the quirks_mode mode.
 */
static VALUE cState_quirks_mode_set(VALUE self, VALUE enable)
{
    GET_STATE(self);
    state->quirks_mode = RTEST(enable);
    return Qnil;
}
Exemplo n.º 9
0
/*
 * call-seq: depth
 *
 * This integer returns the current depth of data structure nesting.
 */
static VALUE cState_depth(VALUE self)
{
    GET_STATE(self);
    return LONG2FIX(state->depth);
}
Exemplo n.º 10
0
/*
 * call-seq: ascii_only?
 *
 * Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise
 * returns false.
 */
static VALUE cState_ascii_only_p(VALUE self)
{
    GET_STATE(self);
    return state->ascii_only ? Qtrue : Qfalse;
}
Exemplo n.º 11
0
/*
 * call-seq: quirks_mode?
 *
 * Returns true, if quirks mode is enabled. Otherwise returns false.
 */
static VALUE cState_quirks_mode_p(VALUE self)
{
    GET_STATE(self);
    return state->quirks_mode ? Qtrue : Qfalse;
}
Exemplo n.º 12
0
/*
 * call-seq: max_nesting=(depth)
 *
 * This sets the maximum level of data structure nesting in the generated JSON
 * to the integer depth, max_nesting = 0 if no maximum should be checked.
 */
static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
{
    GET_STATE(self);
    Check_Type(depth, T_FIXNUM);
    return state->max_nesting = FIX2LONG(depth);
}
Exemplo n.º 13
0
/*
 * call-seq: array_nl()
 *
 * This string is put at the end of a line that holds a JSON array.
 */
static VALUE cState_array_nl(VALUE self)
{
    GET_STATE(self);
    return state->array_nl ? rb_str_new(state->array_nl, state->array_nl_len) : rb_str_new2("");
}
Exemplo n.º 14
0
/*
 * call-seq: space_before()
 *
 * This string is used to insert a space before the ':' in JSON objects.
 */
static VALUE cState_space_before(VALUE self)
{
    GET_STATE(self);
    return state->space_before ? rb_str_new(state->space_before, state->space_before_len) : rb_str_new2("");
}
Exemplo n.º 15
0
/*
 * call-seq: object_nl()
 *
 * This string is put at the end of a line that holds a JSON object (or
 * Hash).
 */
static VALUE cState_object_nl(VALUE self)
{
    GET_STATE(self);
    return state->object_nl;
}
Exemplo n.º 16
0
/*
 * call-seq: buffer_initial_length
 *
 * This integer returns the current inital length of the buffer.
 */
static VALUE cState_buffer_initial_length(VALUE self)
{
    GET_STATE(self);
    return LONG2FIX(state->buffer_initial_length);
}
Exemplo n.º 17
0
/*
 * call-seq: object_nl=(object_nl)
 *
 * This string is put at the end of a line that holds a JSON object (or
 * Hash).
 */
static VALUE cState_object_nl_set(VALUE self, VALUE object_nl)
{
    GET_STATE(self);
    Check_Type(object_nl, T_STRING);
    return state->object_nl = object_nl;
}
Exemplo n.º 18
0
/*
 * call-seq: configure(opts)
 *
 * Configure this State instance with the Hash _opts_, and return
 * itself.
 */
static VALUE cState_configure(VALUE self, VALUE opts)
{
    VALUE tmp;
    GET_STATE(self);
    tmp = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
    if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h");
    if (NIL_P(tmp)) {
        rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash");
    }
    opts = tmp;
    tmp = rb_hash_aref(opts, ID2SYM(i_indent));
    if (RTEST(tmp)) {
        unsigned long len;
        Check_Type(tmp, T_STRING);
        len = RSTRING_LEN(tmp);
        state->indent = fstrndup(RSTRING_PTR(tmp), len + 1);
        state->indent_len = len;
    }
    tmp = rb_hash_aref(opts, ID2SYM(i_space));
    if (RTEST(tmp)) {
        unsigned long len;
        Check_Type(tmp, T_STRING);
        len = RSTRING_LEN(tmp);
        state->space = fstrndup(RSTRING_PTR(tmp), len + 1);
        state->space_len = len;
    }
    tmp = rb_hash_aref(opts, ID2SYM(i_space_before));
    if (RTEST(tmp)) {
        unsigned long len;
        Check_Type(tmp, T_STRING);
        len = RSTRING_LEN(tmp);
        state->space_before = fstrndup(RSTRING_PTR(tmp), len + 1);
        state->space_before_len = len;
    }
    tmp = rb_hash_aref(opts, ID2SYM(i_array_nl));
    if (RTEST(tmp)) {
        unsigned long len;
        Check_Type(tmp, T_STRING);
        len = RSTRING_LEN(tmp);
        state->array_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
        state->array_nl_len = len;
    }
    tmp = rb_hash_aref(opts, ID2SYM(i_object_nl));
    if (RTEST(tmp)) {
        unsigned long len;
        Check_Type(tmp, T_STRING);
        len = RSTRING_LEN(tmp);
        state->object_nl = fstrndup(RSTRING_PTR(tmp), len + 1);
        state->object_nl_len = len;
    }
    tmp = ID2SYM(i_max_nesting);
    state->max_nesting = 100;
    if (option_given_p(opts, tmp)) {
        VALUE max_nesting = rb_hash_aref(opts, tmp);
        if (RTEST(max_nesting)) {
            Check_Type(max_nesting, T_FIXNUM);
            state->max_nesting = FIX2LONG(max_nesting);
        } else {
            state->max_nesting = 0;
        }
    }
    tmp = ID2SYM(i_depth);
    state->depth = 0;
    if (option_given_p(opts, tmp)) {
        VALUE depth = rb_hash_aref(opts, tmp);
        if (RTEST(depth)) {
            Check_Type(depth, T_FIXNUM);
            state->depth = FIX2LONG(depth);
        } else {
            state->depth = 0;
        }
    }
    tmp = ID2SYM(i_buffer_initial_length);
    if (option_given_p(opts, tmp)) {
        VALUE buffer_initial_length = rb_hash_aref(opts, tmp);
        if (RTEST(buffer_initial_length)) {
            long initial_length;
            Check_Type(buffer_initial_length, T_FIXNUM);
            initial_length = FIX2LONG(buffer_initial_length);
            if (initial_length > 0) state->buffer_initial_length = initial_length;
        }
    }
    tmp = rb_hash_aref(opts, ID2SYM(i_allow_nan));
    state->allow_nan = RTEST(tmp);
    tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only));
    state->ascii_only = RTEST(tmp);
    tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode));
    state->quirks_mode = RTEST(tmp);
    return self;
}
Exemplo n.º 19
0
/*
 * call-seq: array_nl=(array_nl)
 *
 * This string is put at the end of a line that holds a JSON array.
 */
static VALUE cState_array_nl_set(VALUE self, VALUE array_nl)
{
    GET_STATE(self);
    Check_Type(array_nl, T_STRING);
    return state->array_nl = array_nl;
}
Exemplo n.º 20
0
inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth) {
    long i, len = RARRAY_LEN(self);
    VALUE shift, result;
    long depth = NIL_P(Vdepth) ? 0 : FIX2LONG(Vdepth);
    VALUE delim = rb_str_new2(",");
    GET_STATE(Vstate);

    check_max_nesting(state, depth);
    if (state->check_circular) {
        VALUE self_id = rb_obj_id(self);
        rb_hash_aset(state->seen, self_id, Qtrue);
        result = rb_str_buf_new(len);
        if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl);
        shift = rb_str_times(state->indent, LONG2FIX(depth + 1));

        rb_str_buf_cat2(result, "[");
        OBJ_INFECT(result, self);
        rb_str_buf_append(result, state->array_nl);
        for (i = 0;  i < len; i++) {
            VALUE element = RARRAY_PTR(self)[i];
            if (RTEST(rb_hash_aref(state->seen, rb_obj_id(element)))) {
                rb_raise(eCircularDatastructure,
                        "circular data structures not supported!");
            }
            OBJ_INFECT(result, element);
            if (i > 0) rb_str_buf_append(result, delim);
            rb_str_buf_append(result, shift);
            element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1));
            Check_Type(element, T_STRING);
            rb_str_buf_append(result, element);
        }
        if (RSTRING_LEN(state->array_nl)) {
            rb_str_buf_append(result, state->array_nl);
            rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth)));
        }
        rb_str_buf_cat2(result, "]");
        rb_hash_delete(state->seen, self_id);
    } else {
        result = rb_str_buf_new(len);
        OBJ_INFECT(result, self);
        if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl);
        shift = rb_str_times(state->indent, LONG2FIX(depth + 1));

        rb_str_buf_cat2(result, "[");
        rb_str_buf_append(result, state->array_nl);
        for (i = 0;  i < len; i++) {
            VALUE element = RARRAY_PTR(self)[i];
            OBJ_INFECT(result, element);
            if (i > 0) rb_str_buf_append(result, delim);
            rb_str_buf_append(result, shift);
            element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1));
            Check_Type(element, T_STRING);
            rb_str_buf_append(result, element);
        }
        rb_str_buf_append(result, state->array_nl);
        if (RSTRING_LEN(state->array_nl)) {
            rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth)));
        }
        rb_str_buf_cat2(result, "]");
    }
    return result;
}
Exemplo n.º 21
0
/*
 * call-seq: max_nesting
 *
 * This integer returns the maximum level of data structure nesting in
 * the generated JSON, max_nesting = 0 if no maximum is checked.
 */
static VALUE cState_max_nesting(VALUE self)
{
    GET_STATE(self);
    return LONG2FIX(state->max_nesting);
}
Exemplo n.º 22
0
/*
 * call-seq: indent()
 *
 * This string is used to indent levels in the JSON text.
 */
static VALUE cState_indent(VALUE self)
{
    GET_STATE(self);
    return state->indent;
}
Exemplo n.º 23
0
/*
 * call-seq: seen?(object)
 *
 * Returns _true_, if _object_ was already seen during this generating run. 
 */
static VALUE cState_seen_p(VALUE self, VALUE object)
{
    GET_STATE(self);
    return rb_hash_aref(state->seen, rb_obj_id(object));
}
Exemplo n.º 24
0
/*
 * call-seq: indent=(indent)
 *
 * This string is used to indent levels in the JSON text.
 */
static VALUE cState_indent_set(VALUE self, VALUE indent)
{
    GET_STATE(self);
    Check_Type(indent, T_STRING);
    return state->indent = indent;
}
Exemplo n.º 25
0
/*
 * call-seq: forget(object)
 *
 * Forget _object_ for this generating run.
 */
static VALUE cState_forget(VALUE self, VALUE object)
{
    GET_STATE(self);
    return rb_hash_delete(state->seen, rb_obj_id(object));
}
Exemplo n.º 26
0
/*
 * call-seq: space_before()
 *
 * This string is used to insert a space before the ':' in JSON objects.
 */
static VALUE cState_space_before(VALUE self)
{
    GET_STATE(self);
    return state->space_before;
}
Exemplo n.º 27
0
void sc_generator::finish()
{
	GET_STATE().prev_els.clear();
	GET_STATE().elements.clear();
}
Exemplo n.º 28
0
/*
 * call-seq: space_before=(space_before)
 *
 * This string is used to insert a space before the ':' in JSON objects.
 */
static VALUE cState_space_before_set(VALUE self, VALUE space_before)
{
    GET_STATE(self);
    Check_Type(space_before, T_STRING);
    return state->space_before = space_before;
}
Exemplo n.º 29
0
/*
 * call-seq: indent()
 *
 * This string is used to indent levels in the JSON text.
 */
static VALUE cState_indent(VALUE self)
{
    GET_STATE(self);
    return state->indent ? rb_str_new(state->indent, state->indent_len) : rb_str_new2("");
}
Exemplo n.º 30
0
/*
 * call-seq: generate(obj)
 *
 * Generates a valid JSON document from object +obj+ and returns the
 * result. If no valid JSON document can be created this method raises a
 * GeneratorError exception.
 */
static VALUE cState_generate(VALUE self, VALUE obj)
{
    VALUE result = cState_partial_generate(self, obj);
    GET_STATE(self);
    return result;
}