Esempio n. 1
0
void Engine_Start()
{
#if defined(__MACOSX__)
    FindConfigFile();
#endif

    // Set defaults parameters and load config file.
    Engine_InitConfig("config.lua");

    // Primary initialization.
    Engine_Init_Pre();

    // Init generic SDL interfaces.
    Engine_InitSDLControls();
    Engine_InitSDLVideo();

#if !defined(__MACOSX__)
    Engine_InitSDLImage();
#endif

    // Additional OpenGL initialization.
    Engine_InitGL();
    renderer.doShaders();

    // Secondary (deferred) initialization.
    Engine_Init_Post();

    // Initial window resize.
    Engine_Resize(screen_info.w, screen_info.h, screen_info.w, screen_info.h);

    // OpenAL initialization.
    Engine_InitAL();

    ConsoleInfo::instance().addLine("Engine inited!", FONTSTYLE_CONSOLE_EVENT);

    // Clearing up memory for initial level loading.
    engine_world.prepare();

#ifdef NDEBUG
    // Setting up mouse.
    SDL_SetRelativeMouseMode(SDL_TRUE);
    SDL_WarpMouseInWindow(sdl_window, screen_info.w/2, screen_info.h/2);
    SDL_ShowCursor(0);
#endif

    // Make splash screen.
    Gui_FadeAssignPic(FADER_LOADSCREEN, "resource/graphics/legal.png");
    Gui_FadeStart(FADER_LOADSCREEN, GUI_FADER_DIR_OUT);

    luaL_dofile(engine_lua.getState(), "autoexec.lua");
}
Esempio n. 2
0
void Controls_PollSDLInput()
{
    SDL_Event event;
    static int mouse_setup = 0;

    while(SDL_PollEvent(&event))
    {
        switch(event.type)
        {
            case SDL_MOUSEMOTION:
                if(!ConsoleInfo::instance().isVisible() && control_states.mouse_look &&
                   ((event.motion.x != (screen_info.w / 2)) ||
                    (event.motion.y != (screen_info.h / 2))))
                {
                    if(mouse_setup)                                             // it is not perfect way, but cursor
                    {                                                           // every engine start is in one place
                        control_states.look_axis_x = event.motion.xrel * control_mapper.mouse_sensitivity * 0.01f;
                        control_states.look_axis_y = event.motion.yrel * control_mapper.mouse_sensitivity * 0.01f;
                    }

                    if((event.motion.x < ((screen_info.w / 2) - (screen_info.w / 4))) ||
                       (event.motion.x >((screen_info.w / 2) + (screen_info.w / 4))) ||
                       (event.motion.y < ((screen_info.h / 2) - (screen_info.h / 4))) ||
                       (event.motion.y >((screen_info.h / 2) + (screen_info.h / 4))))
                    {
                        SDL_WarpMouseInWindow(sdl_window, screen_info.w / 2, screen_info.h / 2);
                    }
                }
                mouse_setup = 1;
                break;

            case SDL_MOUSEBUTTONDOWN:
                if(event.button.button == 1) //LM = 1, MM = 2, RM = 3
                {
                    Controls_PrimaryMouseDown();
                }
                else if(event.button.button == 3)
                {
                    Controls_SecondaryMouseDown();
                }
                break;

                // Controller events are only invoked when joystick is initialized as
                // game controller, otherwise, generic joystick event will be used.
            case SDL_CONTROLLERAXISMOTION:
                Controls_WrapGameControllerAxis(event.caxis.axis, event.caxis.value);
                break;

            case SDL_CONTROLLERBUTTONDOWN:
            case SDL_CONTROLLERBUTTONUP:
                Controls_WrapGameControllerKey(event.cbutton.button, event.cbutton.state == SDL_PRESSED);
                break;

                // Joystick events are still invoked, even if joystick is initialized as game
                // controller - that's why we need sdl_joystick checking - to filter out
                // duplicate event calls.

            case SDL_JOYAXISMOTION:
                if(sdl_joystick)
                    Controls_JoyAxis(event.jaxis.axis, event.jaxis.value);
                break;

            case SDL_JOYHATMOTION:
                if(sdl_joystick)
                    Controls_JoyHat(event.jhat.value);
                break;

            case SDL_JOYBUTTONDOWN:
            case SDL_JOYBUTTONUP:
                // NOTE: Joystick button numbers are passed with added JOY_BUTTON_MASK (1000).
                if(sdl_joystick)
                    Controls_Key((event.jbutton.button + JOY_BUTTON_MASK), event.jbutton.state == SDL_PRESSED);
                break;

            case SDL_TEXTINPUT:
            case SDL_TEXTEDITING:
                if(ConsoleInfo::instance().isVisible() && event.key.state)
                {
                    ConsoleInfo::instance().filter(event.text.text);
                    return;
                }
                break;

            case SDL_KEYUP:
            case SDL_KEYDOWN:
                if((event.key.keysym.sym == SDLK_F4) &&
                   (event.key.state == SDL_PRESSED) &&
                   (event.key.keysym.mod & KMOD_ALT))
                {
                    done = true;
                    break;
                }

                if(ConsoleInfo::instance().isVisible() && event.key.state)
                {
                    switch(event.key.keysym.sym)
                    {
                        case SDLK_RETURN:
                        case SDLK_UP:
                        case SDLK_DOWN:
                        case SDLK_LEFT:
                        case SDLK_RIGHT:
                        case SDLK_HOME:
                        case SDLK_END:
                        case SDLK_BACKSPACE:
                        case SDLK_DELETE:
                            ConsoleInfo::instance().edit(event.key.keysym.sym);
                            break;
                        default:
                            break;
                    }
                    return;
                }
                else
                {
                    Controls_Key(event.key.keysym.sym, event.key.state == SDL_PRESSED);
                    // DEBUG KEYBOARD COMMANDS
                    Controls_DebugKeys(event.key.keysym.sym, event.key.state);
                }
                break;

            case SDL_QUIT:
                done = true;
                break;

            case SDL_WINDOWEVENT:
                if(event.window.event == SDL_WINDOWEVENT_RESIZED)
                {
                    Engine_Resize(event.window.data1, event.window.data2, event.window.data1, event.window.data2);
                }
                break;

            default:
                break;
        }
    }
}