예제 #1
0
//
// P_InitSwitchList()
//
// Only called at game initialization in order to list the set of switches
// and buttons known to the engine. This enables their texture to change
// when activated, and in the case of buttons, change back after a timeout.
//
// This routine modified to read its data from a predefined lump or
// PWAD lump called SWITCHES rather than a static table in this module to
// allow wad designers to insert or modify switches.
//
// Lump format is an array of byte packed switchlist_t structures, terminated
// by a structure with episode == -0. The lump can be generated from a
// text source file using SWANTBLS.EXE, distributed with the BOOM utils.
// The standard list of switches and animations is contained in the example
// source text file DEFSWANI.DAT also in the BOOM util distribution.
//
// Rewritten by Lee Killough to remove limit 2/8/98
//
void P_InitSwitchList(void)
{
    int                 i;
    int                 index = 0;
    int                 episode = (gamemode == registered || gamemode == retail ? 2 :
                            (gamemode == commercial ? 3 : 1));
    switchlist_t        *alphSwitchList;                // jff 3/23/98 pointer to switch table
    int                 lump = W_GetNumForName2("SWITCHES");    // cph - new wad lump handling

    // jff 3/23/98 read the switch table from a predefined lump
    alphSwitchList = (switchlist_t *)W_CacheLumpNum(lump, PU_STATIC);

    for (i = 0;; ++i)
    {
        if (index + 1 >= max_numswitches)
            switchlist = Z_Realloc(switchlist, sizeof(*switchlist)
                * (max_numswitches = max_numswitches ? max_numswitches * 2 : 8));
        if (SHORT(alphSwitchList[i].episode) <= episode)        // jff 5/11/98 endianess
        {
            int texture1;
            int texture2;

            if (!SHORT(alphSwitchList[i].episode))
                break;

            // Ignore switches referencing unknown texture names, instead of exiting.
            // Warn if either one is missing, but only add if both are valid.
            texture1 = R_CheckTextureNumForName(alphSwitchList[i].name1);
            if (texture1 == -1)
                C_Warning("Switch %i in SWITCHES lump has an unknown texture of %s.", i,
                    alphSwitchList[i].name1);
            texture2 = R_CheckTextureNumForName(alphSwitchList[i].name2);
            if (texture2 == -1)
                C_Warning("Switch %i in SWITCHES lump has an unknown texture of %s.", i,
                    alphSwitchList[i].name2);
            if (texture1 != -1 && texture2 != -1)
            {
                switchlist[index++] = texture1;
                switchlist[index++] = texture2;
            }
        }
    }

    numswitches = index / 2;
    switchlist[index] = -1;
    W_ReleaseLumpNum(lump);
}
예제 #2
0
파일: i_music.c 프로젝트: mdgunn/doomretro
void CheckTimidityConfig(void)
{
    if (*s_timiditycfgpath)
        if (M_FileExists(s_timiditycfgpath))
            C_Output("Using TiMidity configuration file %s.", uppercase(s_timiditycfgpath));
        else
            C_Warning("Can't find TiMidity configuration file %s.", uppercase(s_timiditycfgpath));
}
예제 #3
0
void I_InitGamepad(void)
{
    if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) < 0)
        C_Warning("Gamepad support couldn't be initialized.");
    else
    {
        int numjoysticks = SDL_NumJoysticks();

        for (int i = 0; i < numjoysticks; i++)
            if ((joystick = SDL_JoystickOpen(i)))
                if (SDL_IsGameController(i))
                {
                    gamecontroller = SDL_GameControllerOpen(i);
                    break;
                }

        if (!gamecontroller)
            SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
        else
        {
            const char  *name = SDL_GameControllerName(gamecontroller);

            if (*name)
            {
                if (M_StrCaseStr(name, "xinput"))
                    C_Output("An <i><b>XInput</b></i> gamepad is connected.");
                else
                    C_Output("A <i><b>DirectInput</b></i> gamepad called \"%s\" is connected.", name);
            }
            else
                C_Output("A gamepad is connected.");

            if (!(haptic = SDL_HapticOpenFromJoystick(joystick)) || SDL_HapticRumbleInit(haptic) < 0)
                C_Warning("This gamepad doesn't support vibration.");
        }
    }

    gamepadbuttons = 0;
    gamepadthumbLX = 0;
    gamepadthumbLY = 0;
    gamepadthumbRX = 0;
    gamepadthumbRY = 0;
}
예제 #4
0
파일: r_data.c 프로젝트: mdgunn/doomretro
//
// R_TextureNumForName
// Calls R_CheckTextureNumForName,
//  aborts with error message.
//
int R_TextureNumForName(char *name)
{
    int i = R_CheckTextureNumForName(name);

    if (i == -1)
    {
        C_Warning("The %.8s texture can't be found.", uppercase(name));
        return 0;
    }
    return i;
}
예제 #5
0
파일: r_data.c 프로젝트: mdgunn/doomretro
//
// R_FlatNumForName
// Retrieval, get a flat number for a flat name.
//
int R_FlatNumForName(char *name)
{
    int  i;

    i = W_RangeCheckNumForName(firstflat, lastflat, name);

    if (i == -1)
    {
        C_Warning("The %.8s flat can't be found.", uppercase(name));
        return skyflatnum;
    }
    return (i - firstflat);
}
예제 #6
0
//
// Read the header for a savegame
//
dboolean P_ReadSaveGameHeader(char *description)
{
    byte    a, b, c;
    char    vcheck[VERSIONSIZE];
    char    read_vcheck[VERSIONSIZE];

    for (int i = 0; i < SAVESTRINGSIZE; i++)
        description[i] = saveg_read8();

    for (int i = 0; i < VERSIONSIZE; i++)
        read_vcheck[i] = saveg_read8();

    memset(vcheck, 0, sizeof(vcheck));
    strcpy(vcheck, PACKAGE_SAVEGAMEVERSIONSTRING);

    if (strcmp(read_vcheck, vcheck))
    {
        menuactive = false;
        C_ShowConsole();
        C_Warning("This savegame requires <i>%s</i>.", read_vcheck);
        return false;   // bad version
    }

    gameskill = (skill_t)saveg_read8();
    gameepisode = saveg_read8();
    gamemap = saveg_read8();

    if (gamemode != commercial)
    {
        if (gamemap == 10)
        {
            gamemap = 4;
            M_StringCopy(speciallumpname, "E1M4B", 6);
        }
        else if (gamemap == 11)
        {
            gamemap = 8;
            M_StringCopy(speciallumpname, "E1M8B", 6);
        }
    }

    saveg_read8();

    // get the times
    a = saveg_read8();
    b = saveg_read8();
    c = saveg_read8();
    leveltime = (a << 16) + (b << 8) + c;

    return true;
}
예제 #7
0
static boolean I_SDL_InitSound(void)
{
    int i;

    // No sounds yet
    for (i = 0; i < NUMSFX; ++i)
        sound_chunks[i].abuf = NULL;

    for (i = 0; i < NUM_CHANNELS; ++i)
        channels_playing[i] = sfx_None;

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
        return false;

#if defined(SDL20)
    {
        const SDL_version       *linked = Mix_Linked_Version();

        if (linked->major != MIX_MAJOR_VERSION || linked->minor != MIX_MINOR_VERSION)
            I_Error("The wrong version of SDL2_MIXER.DLL was found. "PACKAGE_NAME" requires "
                "v%d.%d.%d, not v%d.%d.%d.", linked->major, linked->minor, linked->patch,
                MIX_MAJOR_VERSION, MIX_MINOR_VERSION, MIX_PATCHLEVEL);

        if (linked->patch != MIX_PATCHLEVEL)
            C_Warning("The wrong version of SDL2_MIXER.DLL was found. "PACKAGE_NAME" requires "
                "v%d.%d.%d, not v%d.%d.%d.", linked->major, linked->minor, linked->patch,
                MIX_MAJOR_VERSION, MIX_MINOR_VERSION, MIX_PATCHLEVEL);
    }
#endif

    if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, GetSliceSize()) < 0)
        return false;

    Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels);

    // precache sounds to avoid slowdown inside game
    for (i = 0; i < NUMSFX; i++)
        CacheSFX_SDL(i);

    Mix_AllocateChannels(NUM_CHANNELS);

    SDL_PauseAudio(0);

    sound_initialized = true;

    return true;
}
예제 #8
0
dboolean I_SDL_InitSound(void)
{
    int i;

    // No sounds yet
    for (i = 0; i < NUM_CHANNELS; ++i)
        channels_playing[i] = NULL;

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
        return false;

    {
        const SDL_version       *linked = Mix_Linked_Version();

        if (linked->major != MIX_MAJOR_VERSION || linked->minor != MIX_MINOR_VERSION)
            I_Error("The wrong version of SDL2_MIXER.DLL was found. "PACKAGE_NAME" requires "
                "v%d.%d.%d, not v%d.%d.%d.", linked->major, linked->minor, linked->patch,
                MIX_MAJOR_VERSION, MIX_MINOR_VERSION, MIX_PATCHLEVEL);

        if (linked->patch != MIX_PATCHLEVEL)
            C_Warning("The wrong version of SDL2_MIXER.DLL was found. "PACKAGE_NAME" requires "
                "v%d.%d.%d, not v%d.%d.%d.", linked->major, linked->minor, linked->patch,
                MIX_MAJOR_VERSION, MIX_MINOR_VERSION, MIX_PATCHLEVEL);
    }

    if (Mix_OpenAudio(snd_samplerate, AUDIO_S16SYS, 2, GetSliceSize()) < 0)
        return false;

    Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels);

    Mix_AllocateChannels(NUM_CHANNELS);

    SDL_PauseAudio(0);

    sound_initialized = true;

    return true;
}
예제 #9
0
파일: r_data.c 프로젝트: mdgunn/doomretro
//
// R_InitTextures
// Initializes the texture list
//  with the textures from the world map.
//
void R_InitTextures(void)
{
    const maptexture_t  *mtexture;
    texture_t           *texture;
    int                 i, j;
    int                 maptex_lump[2] = { -1, -1 };
    const int           *maptex1;
    const int           *maptex2;
    char                name[9];
    int                 names_lump; // cph - new wad lump handling
    const char          *names; // cph -
    const char          *name_p;// const*'s
    int                 *patchlookup;
    int                 nummappatches;
    int                 maxoff, maxoff2;
    int                 numtextures1, numtextures2;
    const int           *directory;

    // Load the patch names from pnames.lmp.
    name[8] = '\0';
    names = W_CacheLumpNum(names_lump = W_GetNumForName("PNAMES"), PU_STATIC);
    nummappatches = LONG(*((const int *)names));
    name_p = names + 4;
    patchlookup = malloc(nummappatches * sizeof(*patchlookup));   // killough

    for (i = 0; i < nummappatches; i++)
    {
        strncpy(name, name_p + i * 8, 8);
        patchlookup[i] = W_CheckNumForName(name);
    }
    W_ReleaseLumpNum(names_lump);       // cph - release the lump

    // Load the map texture definitions from textures.lmp.
    // The data is contained in one or two lumps,
    //  TEXTURE1 for shareware, plus TEXTURE2 for commercial.
    maptex_lump[0] = W_GetNumForName("TEXTURE1");
    maptex1 = W_CacheLumpNum(maptex_lump[0], PU_STATIC);
    numtextures1 = LONG(*maptex1);
    maxoff = W_LumpLength(maptex_lump[0]);
    directory = maptex1 + 1;

    if (W_CheckNumForName("TEXTURE2") != -1)
    {
        maptex_lump[1] = W_GetNumForName("TEXTURE2");
        maptex2 = W_CacheLumpNum(maptex_lump[1], PU_STATIC);
        numtextures2 = LONG(*maptex2);
        maxoff2 = W_LumpLength(maptex_lump[1]);
    }
    else
    {
        maptex2 = NULL;
        numtextures2 = 0;
        maxoff2 = 0;
    }
    numtextures = numtextures1 + numtextures2;

    // killough 4/9/98: make column offsets 32-bit;
    // clean up malloc-ing to use sizeof
    textures = Z_Malloc(numtextures * sizeof(*textures), PU_STATIC, 0);
    textureheight = Z_Malloc(numtextures * sizeof(*textureheight), PU_STATIC, 0);

    for (i = 0; i < numtextures; ++i, ++directory)
    {
        const mappatch_t        *mpatch;
        texpatch_t              *patch;
        int                     offset;

        if (i == numtextures1)
        {
            // Start looking in second texture file.
            maptex1 = maptex2;
            maxoff = maxoff2;
            directory = maptex1 + 1;
        }

        offset = LONG(*directory);

        if (offset > maxoff)
            I_Error("R_InitTextures: Bad texture directory");

        mtexture = (const maptexture_t *)((const byte *)maptex1 + offset);

        texture = textures[i] = Z_Malloc(sizeof(texture_t) + sizeof(texpatch_t)
            * (SHORT(mtexture->patchcount) - 1), PU_STATIC, 0);

        texture->width = SHORT(mtexture->width);
        texture->height = SHORT(mtexture->height);
        texture->patchcount = SHORT(mtexture->patchcount);

        {
            size_t      j;

            for (j = 0; j < sizeof(texture->name); ++j)
                texture->name[j] = mtexture->name[j];
        }

        mpatch = mtexture->patches;
        patch = texture->patches;

        for (j = 0; j < texture->patchcount; ++j, ++mpatch, ++patch)
        {
            patch->originx = SHORT(mpatch->originx);
            patch->originy = SHORT(mpatch->originy);
            patch->patch = patchlookup[SHORT(mpatch->patch)];
            if (patch->patch == -1)
                C_Warning("Patch %d is missing in the %.8s texture.", SHORT(mpatch->patch),
                    texture->name);     // killough 4/17/98
        }

        for (j = 1; j * 2 <= texture->width; j <<= 1);
        texture->widthmask = j - 1;
        textureheight[i] = texture->height << FRACBITS;
    }

    free(patchlookup);          // killough

    for (i = 0; i < 2; ++i)     // cph - release the TEXTUREx lumps
        if (maptex_lump[i] != -1)
            W_ReleaseLumpNum(maptex_lump[i]);

    // Create translation table for global animation.
    // killough 4/9/98: make column offsets 32-bit;
    // clean up malloc-ing to use sizeof
    texturetranslation = Z_Malloc((numtextures + 1) * sizeof(*texturetranslation), PU_STATIC, 0);

    for (i = 0; i < numtextures; ++i)
        texturetranslation[i] = i;

    // killough 1/31/98: Initialize texture hash table
    for (i = 0; i < numtextures; ++i)
        textures[i]->index = -1;
    while (--i >= 0)
    {
        int     j = W_LumpNameHash(textures[i]->name) % (unsigned int)numtextures;

        textures[i]->next = textures[j]->index; // Prepend to chain
        textures[j]->index = i;
    }

    // [BH] Initialize partially fullbright textures.
    texturefullbright = Z_Malloc(numtextures * sizeof(*texturefullbright), PU_STATIC, 0);

    memset(texturefullbright, 0, numtextures * sizeof(*texturefullbright));
    if (r_brightmaps)
    {
        i = 0;
        while (fullbright[i].colormask)
        {
            if (fullbright[i].texture)
            {
                int num = R_CheckTextureNumForName(fullbright[i].texture);

                if (num != -1)
                    texturefullbright[num] = fullbright[i].colormask;
                i++;
            }
        }
    }
}
예제 #10
0
// Perform the merge.
//
// The merge code creates a new lumpinfo list, adding entries from the
// IWAD first followed by the PWAD.
//
// For the IWAD:
//  * Flats are added. If a flat with the same name is in the PWAD,
//    it is ignored (deleted). At the end of the section, all flats in the
//    PWAD are inserted. This is consistent with the behavior of
//    deutex/deusf.
//  * Sprites are added. The "replace list" is generated before the merge
//    from the list of sprites in the PWAD. Any sprites in the IWAD found
//    to match the replace list are removed. At the end of the section,
//    the sprites from the PWAD are inserted.
//
// For the PWAD:
//  * All Sprites and Flats are ignored, with the assumption they have
//    already been merged into the IWAD's sections.
static void DoMerge(void)
{
    section_t   current_section;
    lumpinfo_t  **newlumps;
    int         num_newlumps;
    int         lumpindex;

    // Can't ever have more lumps than we already have
    newlumps = calloc(numlumps, sizeof(lumpinfo_t *));
    num_newlumps = 0;

    // Add IWAD lumps
    current_section = SECTION_NORMAL;

    for (int i = 0; i < iwad.numlumps; i++)
    {
        lumpinfo_t  *lump = iwad.lumps[i];

        switch (current_section)
        {
            case SECTION_NORMAL:
                if (!strncasecmp(lump->name, "F_START", 8))
                    current_section = SECTION_FLATS;
                else if (!strncasecmp(lump->name, "S_START", 8))
                    current_section = SECTION_SPRITES;

                newlumps[num_newlumps++] = lump;
                break;

            case SECTION_FLATS:
                // Have we reached the end of the section?
                if (!strncasecmp(lump->name, "F_END", 8))
                {
                    // Add all new flats from the PWAD to the end
                    // of the section
                    for (int n = 0; n < pwad_flats.numlumps; n++)
                        newlumps[num_newlumps++] = pwad_flats.lumps[n];

                    newlumps[num_newlumps++] = lump;

                    // back to normal reading
                    current_section = SECTION_NORMAL;
                }
                else
                {
                    // If there is a flat in the PWAD with the same name,
                    // do not add it now. All PWAD flats are added to the
                    // end of the section. Otherwise, if it is only in the
                    // IWAD, add it now
                    lumpindex = FindInList(&pwad_flats, lump->name);

                    if (lumpindex < 0)
                        newlumps[num_newlumps++] = lump;
                }

                break;

            case SECTION_SPRITES:
                // Have we reached the end of the section?
                if (!strncasecmp(lump->name, "S_END", 8))
                {
                    // add all the PWAD sprites
                    for (int n = 0; n < pwad_sprites.numlumps; n++)
                        if (SpriteLumpNeeded(pwad_sprites.lumps[n]))
                            newlumps[num_newlumps++] = pwad_sprites.lumps[n];

                    // copy the ending
                    newlumps[num_newlumps++] = lump;

                    // back to normal reading
                    current_section = SECTION_NORMAL;
                }
                else
                {
                    // Is this lump holding a sprite to be replaced in the
                    // PWAD? If so, wait until the end to add it.
                    if (SpriteLumpNeeded(lump))
                        newlumps[num_newlumps++] = lump;
                }

                break;

            case SECTION_HIDEF:
                break;
        }
    }

    // Add PWAD lumps
    current_section = SECTION_NORMAL;

    for (int i = 0, histart; i < pwad.numlumps; i++)
    {
        lumpinfo_t  *lump = pwad.lumps[i];

        switch (current_section)
        {
            case SECTION_NORMAL:
                if (!strncasecmp(lump->name, "F_START", 8) || !strncasecmp(lump->name, "FF_START", 8))
                    current_section = SECTION_FLATS;
                else if (!strncasecmp(lump->name, "S_START", 8) || !strncasecmp(lump->name, "SS_START", 8))
                    current_section = SECTION_SPRITES;
                else if (!strncasecmp(lump->name, "HI_START", 8))
                {
                    current_section = SECTION_HIDEF;
                    histart = i;
                }
                else
                    // Don't include the headers of sections
                    newlumps[num_newlumps++] = lump;

                break;

            case SECTION_FLATS:
                // PWAD flats are ignored (already merged)
                if (!strncasecmp(lump->name, "FF_END", 8) || !strncasecmp(lump->name, "F_END", 8))
                    // end of section
                    current_section = SECTION_NORMAL;

                break;

            case SECTION_SPRITES:
                // PWAD sprites are ignored (already merged)
                if (!strncasecmp(lump->name, "SS_END", 8) || !strncasecmp(lump->name, "S_END", 8))
                    // end of section
                    current_section = SECTION_NORMAL;

                break;

            case SECTION_HIDEF:
                if (!strncasecmp(lump->name, "HI_END", 8))
                {
                    int hiend = i - histart - 1;

                    current_section = SECTION_NORMAL;

                    if (hiend)
                    {
                        if (hiend == 1)
                            C_Warning("The patch between the <b>HI_START</b> and <b>HI_END</b> markers will be ignored.");
                        else
                            C_Warning("The %s patches between the <b>HI_START</b> and <b>HI_END</b> markers will be ignored.",
                                commify(hiend));

                    }
                }

                break;
        }
    }

    // Switch to the new lumpinfo, and free the old one
    free(lumpinfo);
    lumpinfo = newlumps;
    numlumps = num_newlumps;
}