コード例 #1
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));
}
コード例 #2
0
ファイル: r_data.c プロジェクト: mdgunn/doomretro
void R_InitColormaps(void)
{
    dboolean    COLORMAP = (W_CheckMultipleLumps("COLORMAP") > 1);
    int         i;
    byte        *palsrc, *palette;
    wad_file_t  *colormapwad;

    if (W_CheckNumForName("C_START") >= 0 && W_CheckNumForName("C_END") >= 0)
    {
        firstcolormaplump = W_GetNumForName("C_START");
        lastcolormaplump = W_GetNumForName("C_END");
        numcolormaps = lastcolormaplump - firstcolormaplump;

        colormaps = Z_Malloc(sizeof(*colormaps) * numcolormaps, PU_STATIC, NULL);

        colormaps[0] = W_CacheLumpName("COLORMAP", PU_STATIC);

        for (i = 1; i < numcolormaps; i++)
            colormaps[i] = W_CacheLumpNum(i + firstcolormaplump, PU_STATIC);
    }
    else
    {
        colormaps = Z_Malloc(sizeof(*colormaps), PU_STATIC, NULL);
        colormaps[0] = W_CacheLumpName("COLORMAP", PU_STATIC);
    }
    colormapwad = lumpinfo[W_CheckNumForName("COLORMAP")]->wad_file;
    C_Output("Using the COLORMAP lump in %s file %s.",
        (colormapwad->type == IWAD ? "IWAD" : "PWAD"), uppercase(colormapwad->path));

    // [BH] There's a typo in dcolors.c, the source code of the utility Id
    // Software used to construct the palettes and colormaps for DOOM (see
    // http://www.doomworld.com/idgames/?id=16644). When constructing colormap
    // 32, which is used for the invulnerability powerup, the traditional
    // Y luminance values are used (see http://en.wikipedia.org/wiki/YIQ), but a
    // value of 0.144 is used when it should be 0.114. So I've grabbed the
    // offending code from dcolor.c, corrected it, put it here, and now colormap
    // 32 is manually calculated rather than grabbing it from the colormap lump.
    // The resulting differences are minor.
    palsrc = palette = W_CacheLumpName("PLAYPAL", PU_CACHE);

    for (i = 0; i < 255; i++)
    {
        float       red = *palsrc++ / 256.0f;
        float       green = *palsrc++ / 256.0f;
        float       blue = *palsrc++ / 256.0f;
        float       gray = red * 0.299f + green * 0.587f + blue * 0.114f/*0.144f*/;

        grays[i] = FindNearestColor(palette, (int)(gray * 255.0f),
            (int)(gray * 255.0f), (int)(gray * 255.0f));

        if (!COLORMAP)
        {
            gray = (1.0f - gray) * 255.0f;
            colormaps[0][32 * 256 + i] = FindNearestColor(palette, (int)gray, (int)gray, (int)gray);
        }
    }
}
コード例 #3
0
ファイル: i_gamepad.c プロジェクト: bradharding/doomretro
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
ファイル: m_config.c プロジェクト: bradharding/doomretro
//
// M_LoadCVARs
//
void M_LoadCVARs(char *filename)
{
    int     bindcount = 0;
    int     cvarcount = 0;
    int     statcount = 0;

    // read the file in, overriding any set defaults
    FILE    *file = fopen(filename, "r");

    if (!file)
    {
        M_CheckCVARs();
        M_SaveCVARs();
        C_Output("Created <b>%s</b>.", filename);
        cvarsloaded = true;
        return;
    }

    for (int i = 0; i < MAXALIASES; i++)
    {
        aliases[i].name[0] = '\0';
        aliases[i].string[0] = '\0';
    }

    // Clear all default controls before reading them from config file
    if (!togglingvanilla && M_StringEndsWith(filename, PACKAGE_CONFIG))
    {
        for (int i = 0; *actions[i].action; i++)
        {
            if (actions[i].keyboard1)
                *(int *)actions[i].keyboard1 = 0;

            if (actions[i].keyboard2)
                *(int *)actions[i].keyboard2 = 0;

            if (actions[i].mouse1)
                *(int *)actions[i].mouse1 = -1;

            if (actions[i].gamepad1)
                *(int *)actions[i].gamepad1 = 0;

            if (actions[i].gamepad2)
                *(int *)actions[i].gamepad2 = 0;
        }

        for (int i = 0; i < NUMKEYS; i++)
            keyactionlist[i][0] = '\0';
    }

    while (!feof(file))
    {
        char    cvar[64] = "";
        char    value[256] = "";

        if (fscanf(file, "%63s %255[^\n]\n", cvar, value) != 2)
            continue;

        if (cvar[0] == ';')
            continue;

        if (M_StringCompare(cvar, "bind"))
        {
            bind_cmd_func2("bind", value);
            bindcount++;
            continue;
        }
        else if (M_StringCompare(cvar, "alias"))
        {
            if (!togglingvanilla)
                alias_cmd_func2("alias", value);

            continue;
        }

        // Strip off trailing non-printable characters (\r characters from DOS text files)
        while (*value && !isprint((unsigned char)value[strlen(value) - 1]))
            value[strlen(value) - 1] = '\0';

        if (togglingvanilla)
        {
            char    *value_free = uncommify(value);

            C_ValidateInput(M_StringJoin(cvar, " ", value_free, NULL));
            free(value_free);
            continue;
        }

        // Find the setting in the list
        for (int i = 0; i < arrlen(cvars); i++)
        {
            char    *s;

            if (!M_StringCompare(cvar, cvars[i].name))
                continue;       // not this one

            if (M_StringStartsWith(cvar, "stat_"))
                statcount++;
            else
                cvarcount++;

            // parameter found
            switch (cvars[i].type)
            {
                case DEFAULT_STRING:
                    s = M_StringDuplicate(value + 1);
                    s[strlen(s) - 1] = '\0';
                    *(char **)cvars[i].location = s;
                    break;

                case DEFAULT_INT:
                {
                    char    *value_free = uncommify(value);

                    M_StringCopy(value, value_free, sizeof(value));
                    *(int *)cvars[i].location = ParseIntParameter(value, cvars[i].valuealiastype);
                    free(value_free);
                    break;
                }

                case DEFAULT_INT_UNSIGNED:
                {
                    char    *value_free = uncommify(value);

                    M_StringCopy(value, value_free, sizeof(value));
                    sscanf(value, "%10u", (unsigned int *)cvars[i].location);
                    free(value_free);
                    break;
                }

                case DEFAULT_INT_PERCENT:
                {
                    char    *value_free = uncommify(value);

                    M_StringCopy(value, value_free, sizeof(value));
                    s = M_StringDuplicate(value);

                    if (*s && s[strlen(s) - 1] == '%')
                        s[strlen(s) - 1] = '\0';

                    *(int *)cvars[i].location = ParseIntParameter(s, cvars[i].valuealiastype);
                    free(value_free);
                    break;
                }

                case DEFAULT_FLOAT:
                {
                    char    *value_free = uncommify(value);

                    M_StringCopy(value, value_free, sizeof(value));
                    *(float *)cvars[i].location = ParseFloatParameter(value, cvars[i].valuealiastype);
                    free(value_free);
                    break;
                }

                case DEFAULT_FLOAT_PERCENT:
                {
                    char    *value_free = uncommify(value);

                    M_StringCopy(value, value_free, sizeof(value));
                    s = M_StringDuplicate(value);

                    if (*s && s[strlen(s) - 1] == '%')
                        s[strlen(s) - 1] = '\0';

                    *(float *)cvars[i].location = ParseFloatParameter(s, cvars[i].valuealiastype);
                    free(value_free);
                    break;
                }

                case DEFAULT_OTHER:
                    *(char **)cvars[i].location = M_StringDuplicate(value);
                    break;
            }

            // finish
            break;
        }
    }

    fclose(file);

    if (!togglingvanilla)
    {
        char    *cvarcount_str = commify(cvarcount);
        char    *statcount_str = commify(statcount);
        char    *bindcount_str = commify(bindcount);

        C_Output("Loaded %s CVARs and %s player stats from <b>%s</b>.", cvarcount_str, statcount_str, filename);
        C_Output("Bound %s actions to the keyboard, mouse and gamepad.", bindcount_str);
        M_CheckCVARs();
        cvarsloaded = true;

        free(cvarcount_str);
        free(statcount_str);
        free(bindcount_str);
    }
}
コード例 #5
0
ファイル: w_wad.c プロジェクト: mdgunn/doomretro
//
// W_AddFile
// All files are optional, but at least one file must be
//  found (PWAD, if all required lumps are present).
// Files with a .wad extension are wadlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
wad_file_t *W_AddFile(char *filename, dboolean automatic)
{
    wadinfo_t   header;
    lumpindex_t i;
    int         startlump;
    filelump_t  *fileinfo;
    filelump_t  *filerover;
    lumpinfo_t  *filelumps;
    int         numfilelumps;

    // open the file and add to directory
    wad_file_t  *wad_file = W_OpenFile(filename);

    if (!wad_file)
        return NULL;

    M_StringCopy(wad_file->path, filename, sizeof(wad_file->path));

    wad_file->freedoom = IsFreedoom(filename);

    if (!M_StringCompare(filename + strlen(filename) - 3, "wad"))
    {
        // single lump file

        // fraggle: Swap the filepos and size here. The WAD directory
        // parsing code expects a little-endian directory, so will swap
        // them back. Effectively we're constructing a "fake WAD directory"
        // here, as it would appear on disk.
        fileinfo = Z_Malloc(sizeof(filelump_t), PU_STATIC, NULL);
        fileinfo->filepos = LONG(0);
        fileinfo->size = LONG(wad_file->length);

        // Name the lump after the base of the filename (without the
        // extension).
        ExtractFileBase(filename, fileinfo->name);
        numfilelumps = 1;
    }
    else
    {
        int     length;

        // WAD file
        W_Read(wad_file, 0, &header, sizeof(header));

        // Homebrew levels?
        if (strncmp(header.identification, "IWAD", 4)
            && strncmp(header.identification, "PWAD", 4))
            I_Error("Wad file %s doesn't have IWAD or PWAD id\n", filename);

        wad_file->type = (!strncmp(header.identification, "IWAD", 4) ? IWAD : PWAD);

        header.numlumps = LONG(header.numlumps);
        header.infotableofs = LONG(header.infotableofs);
        length = header.numlumps * sizeof(filelump_t);
        fileinfo = Z_Malloc(length, PU_STATIC, NULL);

        W_Read(wad_file, header.infotableofs, fileinfo, length);
        numfilelumps = header.numlumps;
    }

    // Increase size of numlumps array to accommodate the new file.
    filelumps = calloc(numfilelumps, sizeof(lumpinfo_t));
    if (!filelumps)
        I_Error("Failed to allocate array for lumps from new file.");

    startlump = numlumps;
    numlumps += numfilelumps;
    lumpinfo = Z_Realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *));
    if (!lumpinfo)
        I_Error("Failed to increase lumpinfo[] array size.");

    filerover = fileinfo;

    for (i = startlump; i < numlumps; ++i)
    {
        lumpinfo_t      *lump_p = &filelumps[i - startlump];

        lump_p->wad_file = wad_file;
        lump_p->position = LONG(filerover->filepos);
        lump_p->size = LONG(filerover->size);
        lump_p->cache = NULL;
        strncpy(lump_p->name, filerover->name, 8);
        lumpinfo[i] = lump_p;

        ++filerover;
    }

    Z_Free(fileinfo);

    if (lumphash)
    {
        Z_Free(lumphash);
        lumphash = NULL;
    }

    C_Output("%s %s lump%s from %.4s file %s.", (automatic ? "Automatically added" : "Added"),
        commify(numlumps - startlump), (numlumps - startlump == 1 ? "" : "s"),
        header.identification, uppercase(filename));

    return wad_file;
}
コード例 #6
0
ファイル: i_gamepad.c プロジェクト: mdgunn/doomretro
void I_InitGamepad(void)
{
    gamepadfunc = I_PollDirectInputGamepad;
    gamepadthumbsfunc = (gp_swapthumbsticks ? I_PollThumbs_DirectInput_LeftHanded :
        I_PollThumbs_DirectInput_RightHanded);

    if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
        return;
    else
    {
        int     i;
        int     numgamepads = SDL_NumJoysticks();

        for (i = 0; i < numgamepads; ++i)
        {
            gamepad = SDL_JoystickOpen(i);
            if (gamepad)
                break;
        }

        if (!gamepad)
        {
            SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
            return;
        }
        else
        {
#if defined(WIN32)
            char        *XInputDLL = malloc(16);
            static int  initcount;

            if ((pXInputDLL = LoadLibrary("XInput1_4.dll")))
                M_StringCopy(XInputDLL, "XINPUT1_4.DLL", 16);
            else if ((pXInputDLL = LoadLibrary("XInput9_1_0.dll")))
                M_StringCopy(XInputDLL, "XINPUT9_1_0.DLL", 16);
            else if ((pXInputDLL = LoadLibrary("XInput1_3.dll")))
                M_StringCopy(XInputDLL, "XINPUT1_3.DLL", 16);

            ++initcount;

            if (pXInputDLL)
            {
                pXInputGetState = (XINPUTGETSTATE)GetProcAddress(pXInputDLL, "XInputGetState");
                pXInputSetState = (XINPUTSETSTATE)GetProcAddress(pXInputDLL, "XInputSetState");

                if (pXInputGetState && pXInputSetState)
                {
                    XINPUT_STATE        state;

                    ZeroMemory(&state, sizeof(XINPUT_STATE));

                    if (pXInputGetState(0, &state) == ERROR_SUCCESS)
                    {
                        gamepadfunc = I_PollXInputGamepad;
                        gamepadthumbsfunc = (gp_swapthumbsticks ? I_PollThumbs_XInput_LeftHanded :
                            I_PollThumbs_XInput_RightHanded);
                        if (initcount == 1)
                            C_Output("XInput gamepad detected. Using %s.", XInputDLL);
                    }
                }
                else
                    FreeLibrary(pXInputDLL);
            }
            else if (initcount == 1)
                C_Output("DirectInput gamepad \"%s\" detected.", SDL_JoystickName(gamepad));

            free(XInputDLL);
#else
            C_Output("DirectInput gamepad \"%s\" detected.", SDL_JoystickName(gamepad));
#endif

            SDL_JoystickEventState(SDL_ENABLE);
        }
    }
}