terom@25: terom@25: #include "Graphics.hh" saiam@86: #include "GameState.hh" saiam@108: #include terom@25: terom@25: Graphics::Graphics (Engine &engine, GameState &state) : terom@233: CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), terom@25: engine(engine), terom@25: state(state), terom@25: update_timer(GRAPHICS_UPDATE_INTERVAL_MS), terom@235: input(get_ic()->get_keyboard()), terom@233: simple_font("Font2", engine.getResourceManager()) terom@233: { saiam@86: terom@25: // connect timer signal terom@205: slots.connect(update_timer.sig_tick(), this, &Graphics::on_update); terom@25: terom@25: // enable terom@205: update_timer.start(); terom@25: } terom@25: terom@25: void Graphics::check_input (void) { terom@25: LocalPlayer *player; terom@221: PlayerInput input_mask = 0; terom@25: terom@233: // update gui flags terom@235: this->flags = input.readGuiInput(); terom@233: terom@233: // quit? terom@233: if (flags & GUI_INPUT_QUIT) { saiam@108: engine.stop(); terom@25: saiam@108: return; terom@25: } terom@25: terom@233: // stop here if we don't have a local player terom@25: if ((player = state.getLocalPlayer()) == NULL) terom@25: return; terom@25: terom@221: // dump debug info on stderr terom@233: if (flags & GUI_INPUT_DEBUG_PLAYER) terom@221: player->printDebugInfo(); ekku@180: terom@230: // build input_mask terom@235: input_mask = input.readPlayerInput(); terom@221: terom@233: // apply input if there was any terom@221: if (input_mask) terom@221: player->handleInput(input_mask); terom@25: } terom@25: terom@25: void Graphics::do_redraw (void) { terom@233: CL_GraphicContext *gc = get_gc(); terom@25: saiam@162: // White background nireco@248: gc->clear(CL_Color::black); terom@25: terom@233: // Draw the game terom@233: state.draw(this, flags & GUI_INPUT_DISPLAY_WEAPON); ekku@180: terom@184: // Flip window buffer, sync terom@233: flip(1); terom@25: } terom@25: terom@205: void Graphics::on_update (TimeMS tick_length) { terom@25: // check keyboard input terom@25: check_input(); terom@25: terom@25: // redraw display terom@25: do_redraw(); terom@25: }