Ejemplo n.º 1
0
bool map_has_some_fx_itile( map_t * pmesh, int itile, Uint8 test_fx ) {
	if (!pmesh) {
		throw std::runtime_error("nullptr == pmesh");
	}
	uint8_t tile_fx = (*pmesh)(itile).fx;
    return HAS_SOME_BITS( tile_fx, test_fx );
}
Ejemplo n.º 2
0
CHR_REF Passage::whoIsBlockingPassage( const CHR_REF isrc, IDSZ idsz, const BIT_FIELD targeting_bits, IDSZ require_item ) const
{
    // Skip if the one who is looking doesn't exist
    if ( !_currentModule->getObjectHandler().exists( isrc ) ) return INVALID_CHR_REF;
    Object *psrc = _currentModule->getObjectHandler().get( isrc );

    // Look at each character
    for ( CHR_REF character = 0; character < OBJECTS_MAX; character++ )
    {
        if ( !_currentModule->getObjectHandler().exists( character ) ) continue;
        Object * pchr = _currentModule->getObjectHandler().get( character );

        // dont do scenery objects unless we allow items
        if ( !HAS_SOME_BITS( targeting_bits, TARGET_ITEMS ) && ( CHR_INFINITE_WEIGHT == pchr->phys.weight ) ) continue;

        //Check if the object has the requirements
        if ( !chr_check_target( psrc, character, idsz, targeting_bits ) ) continue;

        //Now check if it actually is inside the passage area
        if ( objectIsInPassage( pchr->getPosX(), pchr->getPosY(), pchr->bump_1.size ) )
        {
            // Found a live one, do we need to check for required items as well?
            if ( IDSZ_NONE == require_item )
            {
                return character;
            }

            // It needs to have a specific item as well
            else
            {
                // I: Check left hand
                if ( chr_is_type_idsz( pchr->holdingwhich[SLOT_LEFT], require_item ) )
                {
                    // It has the item...
                    return character;
                }

                // II: Check right hand
                if ( chr_is_type_idsz( pchr->holdingwhich[SLOT_RIGHT], require_item ) )
                {
                    // It has the item...
                    return character;
                }

                // III: Check the pack
                for(const std::shared_ptr<Object> pitem : pchr->getInventory().iterate())
                {
                    if ( chr_is_type_idsz( pitem->getCharacterID(), require_item ) )
                    {
                        // It has the ipacked in inventory...
                        return character;
                    }
                }
            }
        }
    }

    // No characters found
    return INVALID_CHR_REF;
}
Ejemplo n.º 3
0
bool Passage::close()
{
    //is it already closed?
    if(!isOpen()) {
        return true;
    }

    // don't compute all of this for nothing
    if (EMPTY_BIT_FIELD == _mask) {
        return true;
    }

    // check to see if a wall can close
    if (0 != HAS_SOME_BITS(_mask, MAPFX_IMPASS | MAPFX_WALL))
    {
        std::vector<std::shared_ptr<Object>> crushedCharacters;

        // Make sure it isn't blocked
        for(const std::shared_ptr<Object> &object : _module.getObjectHandler().iterator())
        {
            //Scenery can neither be crushed nor prevents doors from closing
            if(object->isScenery()) {
                continue;
            }

            if (object->canCollide())
            {
                if (objectIsInPassage(object))
                {
                    if (!object->canbecrushed || (object->isAlive() && object->getProfile()->canOpenStuff()))
                    {
                        // Someone is blocking who can open stuff, stop here
                        return false;
                    }
                    else
                    {
                        crushedCharacters.push_back(object);
                    }
                }
            }
        }

        // Crush any unfortunate characters
        for(const std::shared_ptr<Object> &character : crushedCharacters) {
            SET_BIT( character->ai.alert, ALERTIF_CRUSHED );
        }
    }

    // Close it off
    _open = false;
    for(const Index1D &fan : _passageFans) {
        _module.getMeshPointer()->add_fx(fan, _mask);
    }
 
    return true;    
}
Ejemplo n.º 4
0
ObjectRef Passage::whoIsBlockingPassage( ObjectRef objRef, const IDSZ2& idsz, const BIT_FIELD targeting_bits, const IDSZ2& require_item ) const
{
    // Skip if the one who is looking doesn't exist
    if ( !_module.getObjectHandler().exists(objRef) ) return ObjectRef::Invalid;
    Object *psrc = _module.getObjectHandler().get(objRef);

    // Look at each character
    for(const std::shared_ptr<Object> &pchr : _module.getObjectHandler().iterator())
    {
        if(pchr->isTerminated()) {
            continue;
        }

        // dont do scenery objects unless we allow items
        if (!HAS_SOME_BITS(targeting_bits, TARGET_ITEMS) && pchr->isScenery()) continue;

        //Check if the object has the requirements
        if ( !chr_check_target( psrc, pchr, idsz, targeting_bits ) ) continue;

        //Now check if it actually is inside the passage area
        if (objectIsInPassage(pchr))
        {

            // Found a live one, do we need to check for required items as well?
            if ( IDSZ2::None == require_item )
            {
                return pchr->getObjRef();
            }

            // It needs to have a specific item as well
            else
            {
                // I: Check hands
                if(pchr->isWieldingItemIDSZ(require_item)) {
                    return pchr->getObjRef();
                }
                
                // II: Check the pack
                for(const std::shared_ptr<Object> pitem : pchr->getInventory().iterate())
                {
                    if ( pitem->getProfile()->hasTypeIDSZ(require_item) )
                    {
                        // It has the required item in inventory...
                        return pchr->getObjRef();
                    }
                }
            }
        }
    }

    // No characters found
    return ObjectRef::Invalid;
}
Ejemplo n.º 5
0
void SDLX_sdl_video_flags_t::download(SDLX_sdl_video_flags_t& self, uint32_t bits) {
    self.full_screen = HAS_SOME_BITS(bits, SDL_WINDOW_FULLSCREEN);
    self.opengl = HAS_SOME_BITS(bits, SDL_WINDOW_OPENGL);
    self.resizable = HAS_SOME_BITS(bits, SDL_WINDOW_RESIZABLE);
    self.borderless = HAS_SOME_BITS(bits, SDL_WINDOW_BORDERLESS);
    self.highdpi = HAS_SOME_BITS(bits, SDL_WINDOW_ALLOW_HIGHDPI);
    if (self.full_screen) {
        self.use_desktop_size = HAS_SOME_BITS(bits, SDL_WINDOW_FULLSCREEN_DESKTOP);
    }
}
Ejemplo n.º 6
0
Archivo: ui.c Proyecto: wangeek/Egoboo
//--------------------------------------------------------------------------------------------
void ui_setWidgetactive( ui_Widget_t * pw )
{
    if ( NULL == pw )
    {
        ui_context.active = UI_Nothing;
    }
    else
    {
        ui_context.active = pw->id;

        pw->timeout = egoboo_get_ticks() + 100;
        if ( HAS_SOME_BITS( pw->mask, UI_BITS_CLICKED ) )
        {
            // use exclusive or to flip the bit
            pw->state ^= UI_BITS_CLICKED;
        };
    };
}
Ejemplo n.º 7
0
Archivo: ui.c Proyecto: wangeek/Egoboo
//--------------------------------------------------------------------------------------------
void ui_setWidgethot( ui_Widget_t * pw )
{
    if ( NULL == pw )
    {
        ui_context.hot = UI_Nothing;
    }
    else if (( ui_context.active == pw->id || ui_context.active == UI_Nothing ) )
    {
        if ( pw->timeout < egoboo_get_ticks() )
        {
            pw->timeout = egoboo_get_ticks() + 100;

            if ( HAS_SOME_BITS( pw->mask, UI_BITS_MOUSEOVER ) && ui_context.hot != pw->id )
            {
                // use exclusive or to flip the bit
                pw->state ^= UI_BITS_MOUSEOVER;
            };
        };

        // Only allow hotness to be set if this control, or no control is active
        ui_context.hot = pw->id;
    }
}
Ejemplo n.º 8
0
SDL_Event *ConsoleHandler::handle_event(SDL_Event *event)
{
	Ego::Core::Console *console = egolib_console_top;

	if (!event)
	{
		return nullptr;
	}
	if (!console)
	{
		return event;
	}

	// Only handle keyboard events.
	if (SDL_TEXTINPUT != event->type && SDL_TEXTEDITING != event->type && SDL_KEYDOWN != event->type)
		return event;

	SDL_Scancode vkey = SDL_SCANCODE_UNKNOWN;
	bool is_alt = false;
	bool is_shift = false;

	if (SDL_KEYDOWN == event->type)
	{
		// Grab the virtual scancode.
		vkey = event->key.keysym.scancode;

		// Get the key modifiers.
		SDL_Keymod kmod = SDL_GetModState();

		// Is alt or shift down?
		is_alt = HAS_SOME_BITS(kmod, KMOD_ALT | KMOD_CTRL);
		is_shift = HAS_SOME_BITS(kmod, KMOD_SHIFT);

		// If the virtual key code for the backquote is pressed,
		// toggle the console on the top of the console stack.
		if (!is_alt && !is_shift && (SDL_SCANCODE_GRAVE == vkey || (console->on && SDL_SCANCODE_ESCAPE == vkey)))
		{
			if (!console->on)
			{
				console->on = true;
				console->buffer_carat = 0;
				console->buffer[0] = CSTR_END;

				SDL_StartTextInput();
				return nullptr;
			}
			else
			{
				console->on = false;
				console->buffer_carat = 0;
				console->buffer[0] = CSTR_END;

				SDL_StopTextInput();
				return nullptr;
			}
		}
	}

	// Only grab the keycodes if the console is on.
	if (!console->on)
	{
		return event;
	}

	// Handle any console commands.
	if (SDL_KEYDOWN == event->type && !is_alt && !is_shift)
	{
		// backspace: delete character before the carat.
		if (SDL_SCANCODE_BACKSPACE == vkey)
		{
			while (console->buffer_carat > 0)
			{
				console->buffer_carat--;
				char a = console->buffer[console->buffer_carat];
				if ((a & 0x80) == 0x00 || (a & 0xC0) == 0xC0)
					break;
			}
			console->buffer[console->buffer_carat] = CSTR_END;

			event = nullptr;
		}
		else if (SDL_SCANCODE_UP == vkey)
		{
			console->history.up();
			strcpy(console->buffer,console->history.get_saved());
			console->buffer_carat = strlen(console->buffer);
			event = nullptr;
		}
		else if (SDL_SCANCODE_DOWN == vkey)
		{
			console->history.down();
			strcpy(console->buffer, console->history.get_saved());
			console->buffer_carat = strlen(console->buffer);
			event = nullptr;
		}
		else if (SDL_SCANCODE_LEFT == vkey)
		{
			console->buffer_carat--;
			console->buffer_carat = Ego::Math::constrain(console->buffer_carat, (size_t)0, (size_t)(ConsoleSettings::LineSettings::Length - 1));

			event = nullptr;
		}
		else if (SDL_SCANCODE_RIGHT == vkey)
		{
			console->buffer_carat++;
			console->buffer_carat = Ego::Math::constrain(console->buffer_carat, (size_t)0, (size_t)(ConsoleSettings::LineSettings::Length - 1));

			event = nullptr;
		}
		else if (SDL_SCANCODE_RETURN == vkey || SDL_SCANCODE_KP_ENTER == vkey)
		{
			console->buffer[console->buffer_carat] = CSTR_END;

			// Add this command line to the list of saved command line.
			console->history.add_saved(console->buffer);

			// Add the command line to the output buffer.
			console->print("%s %s\n", ConsoleSettings::InputSettings::Prompt.c_str(), console->buffer);

			// Actually execute the command line.
			console->run();

			// Blank the command line.
			console->buffer_carat = 0;
			console->buffer[0] = CSTR_END;

			event = nullptr;
		}
	}

	if (nullptr == event || SDL_KEYDOWN == event->type) return nullptr;

	bool addToLine = SDL_TEXTINPUT == event->type;
	char *text = SDL_TEXTINPUT == event->type ? event->text.text : event->edit.text;
	size_t textLength = strlen(text);

	// handle normal keystrokes
	if (console->buffer_carat + textLength + 1 < ConsoleSettings::LineSettings::Length)
	{
		strcat(console->buffer + console->buffer_carat, event->text.text);
		console->buffer[console->buffer_carat + textLength] = CSTR_END;
		if (addToLine)
			console->buffer_carat += strlen(event->text.text);

		event = nullptr;
	}

	return event;
}
Ejemplo n.º 9
0
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
egolib_rv phys_intersect_oct_bb_close_index(int index, const oct_bb_t& src1, const oct_vec_v2_t& ovel1, const oct_bb_t& src2, const oct_vec_v2_t& ovel2, int test_platform, float *tmin, float *tmax)
{
    if (!tmin)
    {
        throw std::invalid_argument("nullptr == tmin");
    }
    if (!tmax)
    {
        throw std::invalid_argument("nullptr == tmax");
    }
    if (index < 0)
    {
        throw std::invalid_argument("index < 0");
    }
    if (index >= OCT_COUNT)
    {
        throw std::invalid_argument("index >= OCT_COUNT");
    }
    float vdiff = ovel2[index] - ovel1[index];
    if (0.0f == vdiff) return rv_fail;

    /// @todo Use src1.getMin(index), src2.getMax(index) and src1.getMid(index).
    float src1_min = src1._mins[index];
    float src1_max = src1._maxs[index];
    float opos1 = (src1_min + src1_max) * 0.5f;

    /// @todo Use src2.getMin(index), src2.getMax(index) and src2.getMid(index).
    float src2_min = src2._mins[index];
    float src2_max = src2._maxs[index];
    float opos2 = (src2_min + src2_max) * 0.5f;

    if (OCT_Z != index)
    {
        bool platform_1 = HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ1);
        bool platform_2 = HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ2);

        if (!platform_1 && !platform_2)
        {
            // NEITHER is a platform.
            // Use the eqn. from phys_intersect_oct_bb_index().

            float time[4];

            time[0] = (src1_min - src2_min) / vdiff;
            time[1] = (src1_min - src2_max) / vdiff;
            time[2] = (src1_max - src2_min) / vdiff;
            time[3] = (src1_max - src2_max) / vdiff;

			*tmin = std::min({ time[0], time[1], time[2], time[3] });
			*tmax = std::max({ time[0], time[1], time[2], time[3] });
        }
        else if ( platform_1 && !platform_2 )
        {
            float time[2];

            // 1st object is the platform.
            time[0] = (src1_min - opos2) / vdiff;
            time[1] = (src1_max - opos2) / vdiff;

            *tmin = std::min(time[0], time[1]);
            *tmax = std::max(time[0], time[1]);
        }
        else if (!platform_1 && platform_2)
        {
            float time[2];

            // 2nd object is the platform.
            time[0] = (opos1 - src2_min) / vdiff;
            time[1] = (opos1 - src2_max) / vdiff;

            *tmin = std::min(time[0], time[1]);
            *tmax = std::max(time[0], time[1]);
        }
        else
        {
            // BOTH are platforms. must check all possibilities.
            float time[4];

            // 1st object is the platform.
            time[0] = (src1_min - opos2) / vdiff;
            time[1] = (src1_max - opos2) / vdiff;

            // 2nd object 2 is the platform.
            time[2] = (opos1 - src2_min) / vdiff;
            time[3] = (opos1 - src2_max) / vdiff;

            *tmin = std::min(std::min(time[0], time[1]), std::min(time[2], time[3]));
            *tmax = std::max(std::max(time[0], time[1]), std::max(time[2], time[3]));
        }
    }
    else /* OCT_Z == index */
    {
        float plat_min, plat_max;
        float obj_pos;

        float tolerance_1 =  HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ1)
                          ? PLATTOLERANCE : 0.0f;
        float tolerance_2 =  HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ2)
                          ? PLATTOLERANCE : 0.0f;

        if (0.0f == tolerance_1 && 0.0f == tolerance_2)
        {
            // NEITHER is a platform.
            // Use the eqn. from phys_intersect_oct_bb_index().

            float time[4];

            time[0] = (src1_min - src2_min) / vdiff;
            time[1] = (src1_min - src2_max) / vdiff;
            time[2] = (src1_max - src2_min) / vdiff;
            time[3] = (src1_max - src2_max) / vdiff;

            *tmin = std::min({ time[0], time[1], time[2], time[3] });
            *tmax = std::max({ time[0], time[1], time[2], time[3] });
        }
        else if (0.0f != tolerance_1 && 0.0f == tolerance_2)
        {
            float time[2];

            // 1st object is the platform.
            obj_pos  = src2_min;
            plat_min = src1_min;
            plat_max = src1_max + tolerance_1;

            time[0] = (plat_min - obj_pos) / vdiff;
            time[1] = (plat_max - obj_pos) / vdiff;

            *tmin = std::min(time[0], time[1]);
            *tmax = std::max(time[0], time[1]);
        }
        else if (0.0f == tolerance_1 && 0.0f != tolerance_2)
        {
            float time[2];

            // 2nd object is the platform.
            obj_pos  = src1_min;
            plat_min = src2_min;
            plat_max = src2_max + tolerance_2;

            time[0] = (obj_pos - plat_min) / vdiff;
            time[1] = (obj_pos - plat_max) / vdiff;

            *tmin = std::min(time[0], time[1]);
            *tmax = std::max(time[0], time[1]);
        }
        else
        {
            // BOTH are platforms.
            float time[4];

            // 2nd object is a platform.
            obj_pos  = src1_min;
            plat_min = src2_min;
            plat_max = src2_max + tolerance_2;

            time[0] = (obj_pos - plat_min) / vdiff;
            time[1] = (obj_pos - plat_max) / vdiff;

            // 1st object is a platform.
            obj_pos  = src2_min;
            plat_min = src1_min;
            plat_max = src1_max + tolerance_1;

            time[2] = (plat_min - obj_pos) / vdiff;
            time[3] = (plat_max - obj_pos) / vdiff;

            *tmin = std::min({ time[0], time[1], time[2], time[3] });
            *tmax = std::max({ time[0], time[1], time[2], time[3] });
        }
    }

    // Normalize the results for the diagonal directions.
    if (OCT_XY == index || OCT_YX == index)
    {
        *tmin *= Ego::Math::invSqrtTwo<float>();
        *tmax *= Ego::Math::invSqrtTwo<float>();
    }

    if (*tmax < *tmin) return rv_fail;

    return rv_success;
}
Ejemplo n.º 10
0
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
egolib_rv phys_intersect_oct_bb_index(int index, const oct_bb_t& src1, const oct_vec_v2_t& ovel1, const oct_bb_t& src2, const oct_vec_v2_t& ovel2, int test_platform, float *tmin, float *tmax)
{
    if (!tmin)
    {
        throw std::invalid_argument("nullptr == tmin");
    }
    if (!tmax)
    {
        throw std::invalid_argument("nullptr == tmax");
    }
    if (index < 0)
    {
        throw std::invalid_argument("index < 0");
    }
    if (index >= OCT_COUNT)
    {
        throw std::invalid_argument("index >= OCT_COUNT");
    }

    float vdiff = ovel2[index] - ovel1[index];
    if ( 0.0f == vdiff ) return rv_fail;

    float src1_min = src1._mins[index];
    float src1_max = src1._maxs[index];
    float src2_min = src2._mins[index];
    float src2_max = src2._maxs[index];

    if (OCT_Z != index)
    {
        // Is there any possibility of the 2 objects acting as a platform pair.
        bool close_test_1 = HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ1);
        bool close_test_2 = HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ2);

        // Only do a close test if the object's feet are above the platform.
        close_test_1 = close_test_1 && (src1._mins[OCT_Z] > src2._maxs[OCT_Z]);
        close_test_2 = close_test_2 && (src2._mins[OCT_Z] > src1._maxs[OCT_Z]);

        if (!close_test_1 && !close_test_2)
        {
            // NEITHER is a platform.
            float time[4];

            time[0] = (src1_min - src2_min) / vdiff;
            time[1] = (src1_min - src2_max) / vdiff;
            time[2] = (src1_max - src2_min) / vdiff;
            time[3] = (src1_max - src2_max) / vdiff;

            *tmin = std::min( std::min( time[0], time[1] ), std::min( time[2], time[3] ) );
            *tmax = std::max( std::max( time[0], time[1] ), std::max( time[2], time[3] ) );
        }
        else
        {
            return phys_intersect_oct_bb_close_index(index, src1, ovel1, src2, ovel2, test_platform, tmin, tmax);
        }
    }
    else /* OCT_Z == index */
    {
        float plat_min, plat_max;

        // Add in a tolerance into the vertical direction for platforms
        float tolerance_1 = HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ1) ? PLATTOLERANCE : 0.0f;
        float tolerance_2 = HAS_SOME_BITS(test_platform, PHYS_PLATFORM_OBJ2) ? PLATTOLERANCE : 0.0f;

        if ( 0.0f == tolerance_1 && 0.0f == tolerance_2 )
        {
            // NEITHER is a platform.
            float time[4];

            time[0] = (src1_min - src2_min) / vdiff;
            time[1] = (src1_min - src2_max) / vdiff;
            time[2] = (src1_max - src2_min) / vdiff;
            time[3] = (src1_max - src2_max) / vdiff;

            *tmin = std::min( std::min( time[0], time[1] ), std::min( time[2], time[3] ) );
            *tmax = std::max( std::max( time[0], time[1] ), std::max( time[2], time[3] ) );
        }
        else if (0.0f == tolerance_1)
        {
            float time[4];

            // 2nd object is a platform.
            plat_min = src2_min;
            plat_max = src2_max + tolerance_2;

            time[0] = (src1_min - plat_min) / vdiff;
            time[1] = (src1_min - plat_max) / vdiff;
            time[2] = (src1_max - plat_min) / vdiff;
            time[3] = (src1_max - plat_max) / vdiff;

            *tmin = std::min(std::min(time[0], time[1]), std::min(time[2], time[3]));
            *tmax = std::max(std::max(time[0], time[1]), std::max(time[2], time[3]));
        }
        else if (0.0f == tolerance_2)
        {
            float time[4];

            // 1st object is a platform.
            plat_min = src1_min;
            plat_max = src1_max + tolerance_2;

            time[0] = (plat_min - src2_min) / vdiff;
            time[1] = (plat_min - src2_max) / vdiff;
            time[2] = (plat_max - src2_min) / vdiff;
            time[3] = (plat_max - src2_max) / vdiff;

            *tmin = std::min(std::min(time[0], time[1]), std::min(time[2], time[3]));
            *tmax = std::max(std::max(time[0], time[1]), std::max(time[2], time[3]));
        }
        else if ( tolerance_1 > 0.0f && tolerance_2 > 0.0f )
        {
            // BOTH are platforms.
            // They cannot both act as plaforms at the same time,
            // so do 8 tests.

            float time[8];
            float tmp_min1, tmp_max1;
            float tmp_min2, tmp_max2;

            // Assume: 2nd object is platform.
            plat_min = src2_min;
            plat_max = src2_max + tolerance_2;

            time[0] = (src1_min - plat_min) / vdiff;
            time[1] = (src1_min - plat_max) / vdiff;
            time[2] = (src1_max - plat_min) / vdiff;
            time[3] = (src1_max - plat_max) / vdiff;
            tmp_min1 = std::min(std::min(time[0], time[1]), std::min(time[2], time[3]));
            tmp_max1 = std::max(std::max(time[0], time[1]), std::max(time[2], time[3]));

            // Assume: 1st object is platform.
            plat_min = src1_min;
            plat_max = src1_max + tolerance_2;

            time[4] = (plat_min - src2_min) / vdiff;
            time[5] = (plat_min - src2_max) / vdiff;
            time[6] = (plat_max - src2_min) / vdiff;
            time[7] = (plat_max - src2_max) / vdiff;
            tmp_min2 = std::min(std::min(time[4], time[5]), std::min(time[6], time[7]));
            tmp_max2 = std::max(std::max(time[4], time[5]), std::max(time[6], time[7]));

            *tmin = std::min(tmp_min1, tmp_min2);
            *tmax = std::max(tmp_max1, tmp_max2);
        }
    }

    // Normalize the results for the diagonal directions.
    if (OCT_XY == index || OCT_YX == index)
    {
        *tmin *= Ego::Math::invSqrtTwo<float>();
        *tmax *= Ego::Math::invSqrtTwo<float>();
    }

    if (*tmax <= *tmin) return rv_fail;

    return rv_success;
}
Ejemplo n.º 11
0
map_t * map_generate_tile_twist_data( map_t * pmesh )
{
    /// @author BB
    /// @details generates twist data for all tiles from the bitmap

    size_t   mapx, mapy;
    size_t   tile_x, tile_y, itile;
    int      step_x, step_y;

    // does the mesh exist?
    if ( NULL == pmesh ) return pmesh;

    // are there tiles?
    if (pmesh->_mem.tiles.empty()) return pmesh;

    step_x = 1;
    step_y = pmesh->_info.getTileCountY();
    for ( mapy = 0, tile_y = 0; mapy < pmesh->_info.getTileCountY(); mapy++, tile_y += step_y )
    {
        for ( mapx = 0, tile_x = 0; mapx < pmesh->_info.getTileCountX(); mapx++, tile_x += step_x )
        {
            int itile_mx, itile_px, itile_my, itile_py;
            float hgt_mx, hgt_px, hgt_my, hgt_py;

            itile = tile_x + tile_y;

            itile_mx = LAMBDA( mapx <= 0, -1, itile - step_x );
            if ( itile_mx < 0 )
            {
                hgt_mx = Info<float>::Grid::Size();
            }
            else
            {
                hgt_mx = LAMBDA( HAS_SOME_BITS( pmesh->_mem.tiles[itile_mx].fx, MAPFX_WALL | MAPFX_IMPASS ), Info<float>::Grid::Size(), 0.0f );
            }

            itile_px = LAMBDA( mapx >= pmesh->_info.getTileCountX() - 1, -1, itile + step_x );
            if ( itile_px < 0 )
            {
                hgt_px = Info<float>::Grid::Size();
            }
            else
            {
                hgt_px = LAMBDA( HAS_SOME_BITS(pmesh->_mem.tiles[itile_px].fx, MAPFX_WALL | MAPFX_IMPASS ), Info<float>::Grid::Size(), 0.0f );
            }

            itile_my = LAMBDA( mapy <= 0, -1, itile - step_y );
            if ( itile_my < 0 )
            {
                hgt_my = Info<float>::Grid::Size();
            }
            else
            {
                hgt_my = LAMBDA( HAS_SOME_BITS( pmesh->_mem.tiles[itile_my].fx, MAPFX_WALL | MAPFX_IMPASS ), Info<float>::Grid::Size(), 0.0f );
            }

            itile_py = LAMBDA( mapy >= pmesh->_info.getTileCountY() - 1, -1, itile + step_y );
            if ( itile_py < 0 )
            {
                hgt_py = Info<float>::Grid::Size();
            }
            else
            {
                hgt_py = LAMBDA( HAS_SOME_BITS( pmesh->_mem.tiles[itile_py].fx, MAPFX_WALL | MAPFX_IMPASS ), Info<float>::Grid::Size(), 0.0f );
            }

            // calculate the twist of this tile
            pmesh->_mem.tiles[itile].twist = cartman_calc_twist(( hgt_px - hgt_mx ) / 8, ( hgt_py - hgt_my ) / 8 );
        }
    }

    return pmesh;
}
Ejemplo n.º 12
0
bool Passage::close()
{
    //is it already closed?
    if(!isOpen()) {
        return true;
    }

    // don't compute all of this for nothing
    if ( EMPTY_BIT_FIELD == _mask ) {
        return true;
    }

    // check to see if a wall can close
    if ( 0 != HAS_SOME_BITS( _mask, MAPFX_IMPASS | MAPFX_WALL ) )
    {
        std::vector<std::shared_ptr<Object>> crushedCharacters;

        // Make sure it isn't blocked
        for(const std::shared_ptr<Object> &object : _currentModule->getObjectHandler().iterator())
        {
            if(object->isTerminated()) {
                continue;
            }

            //Don't do held items
            if (object->isBeingHeld()) continue;

            if ( 0.0f != object->bump_stt.size )
            {
                if ( objectIsInPassage( object->getPosX(), object->getPosY(), object->bump_1.size ) )
                {
                    if ( !object->canbecrushed || ( object->isAlive() && object->getProfile()->canOpenStuff() ) )
                    {
                        // Someone is blocking who can open stuff, stop here
                        return false;
                    }
                    else
                    {
                        crushedCharacters.push_back(object);
                    }
                }
            }
        }

        // Crush any unfortunate characters
        for(const std::shared_ptr<Object> &character : crushedCharacters) {
            SET_BIT( character->ai.alert, ALERTIF_CRUSHED );
        }
    }

    // Close it off
    _open = false;
    for ( int y = _area._top; y <= _area._bottom; y++ )
    {
        for ( int x = _area._left; x <= _area._right; x++ )
        {
            TileIndex fan = _currentModule->getMeshPointer()->get_tile_int(PointGrid(x, y));
            ego_mesh_add_fx( _currentModule->getMeshPointer(), fan, _mask );
        }
    }

    return true;    
}
Ejemplo n.º 13
0
//--------------------------------------------------------------------------------------------
bool BIT_FIELD_missing_bits( BIT_FIELD val, BIT_FIELD test )
{
    return HAS_SOME_BITS( val, test ) && !HAS_ALL_BITS( val, test );
}
Ejemplo n.º 14
0
//--------------------------------------------------------------------------------------------
bool BIT_FIELD_has_some_bits( BIT_FIELD val, BIT_FIELD test )
{
    return HAS_SOME_BITS( val, test );
}
Ejemplo n.º 15
0
//--------------------------------------------------------------------------------------------
void SDLX_download_sdl_video_flags( Uint32 iflags, SDLX_sdl_video_flags_t * pflags )
{
    if ( NULL != pflags )
    {
        pflags->hw_surface  = HAS_SOME_BITS( iflags, SDL_HWSURFACE );
        pflags->async_blit  = HAS_SOME_BITS( iflags, SDL_ASYNCBLIT );
        pflags->any_format  = HAS_SOME_BITS( iflags, SDL_ANYFORMAT );
        pflags->hw_palette  = HAS_SOME_BITS( iflags, SDL_HWPALETTE );
        pflags->double_buf  = HAS_SOME_BITS( iflags, SDL_DOUBLEBUF );
        pflags->full_screen = HAS_SOME_BITS( iflags, SDL_FULLSCREEN );
        pflags->opengl      = HAS_SOME_BITS( iflags, SDL_OPENGL );
        pflags->opengl_blit = HAS_SOME_BITS( iflags, SDL_OPENGLBLIT );
        pflags->resizable   = HAS_SOME_BITS( iflags, SDL_RESIZABLE );
        pflags->no_frame    = HAS_SOME_BITS( iflags, SDL_NOFRAME );

        // "read only"
        pflags->use_hwaccel     = HAS_SOME_BITS( iflags, SDL_HWACCEL );
        pflags->has_srccolorkey = HAS_SOME_BITS( iflags, SDL_SRCCOLORKEY );
        pflags->use_rleaccelok  = HAS_SOME_BITS( iflags, SDL_RLEACCELOK );
        pflags->use_rleaccel    = HAS_SOME_BITS( iflags, SDL_RLEACCEL );
        pflags->use_srcalpha    = HAS_SOME_BITS( iflags, SDL_SRCALPHA );
        pflags->is_prealloc     = HAS_SOME_BITS( iflags, SDL_PREALLOC );
    }
}