src/Graphics.cc
author terom
Sat, 06 Dec 2008 23:29:06 +0000
changeset 235 0a0c729365ee
parent 233 ff4ecea83cf5
child 248 e40ef56dc62c
permissions -rw-r--r--
code cleanup
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
     1
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
     2
#include "Graphics.hh"
86
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 60
diff changeset
     3
#include "GameState.hh"
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
     4
#include <cmath>
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
     5
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
     6
Graphics::Graphics (Engine &engine, GameState &state) :
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
     7
    CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
     8
    engine(engine), 
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
     9
    state(state), 
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    10
    update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    11
    input(get_ic()->get_keyboard()),
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    12
    simple_font("Font2", engine.getResourceManager()) 
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    13
{
86
ed31ece6f340 Segfault <3 (mik? oli odotettavaa)
saiam
parents: 60
diff changeset
    14
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    15
    // connect timer signal
205
905028e58ed1 implement a new tick-timer that doesn't suck
terom
parents: 199
diff changeset
    16
    slots.connect(update_timer.sig_tick(), this, &Graphics::on_update);
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    17
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    18
    // enable
205
905028e58ed1 implement a new tick-timer that doesn't suck
terom
parents: 199
diff changeset
    19
    update_timer.start();
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    20
}
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    21
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    22
void Graphics::check_input (void) {
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    23
    LocalPlayer *player;
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    24
    PlayerInput input_mask = 0;
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    25
    
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    26
    // update gui flags
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    27
    this->flags = input.readGuiInput();
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    28
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    29
    // quit?
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    30
    if (flags & GUI_INPUT_QUIT) {
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    31
        engine.stop();
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    32
108
1b93045a5b0a T?ht?in lis?tty, tosin se piirret??n tosi rumasti.
saiam
parents: 96
diff changeset
    33
        return;
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    34
    }
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    35
     
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    36
    // stop here if we don't have a local player
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    37
    if ((player = state.getLocalPlayer()) == NULL)
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    38
        return;
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    39
    
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    40
    // dump debug info on stderr
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    41
    if (flags & GUI_INPUT_DEBUG_PLAYER)
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    42
        player->printDebugInfo();
180
bfe1077edab3 Ammuksia f:lla
ekku
parents: 162
diff changeset
    43
    
230
78cf0cd69af4 better input handling
terom
parents: 222
diff changeset
    44
    // build input_mask
235
0a0c729365ee code cleanup
terom
parents: 233
diff changeset
    45
    input_mask = input.readPlayerInput();
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    46
    
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    47
    // apply input if there was any
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    48
    if (input_mask)
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 212
diff changeset
    49
        player->handleInput(input_mask);
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    50
}
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    51
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    52
void Graphics::do_redraw (void) {
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    53
    CL_GraphicContext *gc = get_gc();
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    54
    
162
f760591b7481 Removed unnecessary variables (factoFoo) from do_redraw. Renamed
saiam
parents: 161
diff changeset
    55
    // White background
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    56
    gc->clear(CL_Color::white);
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    57
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    58
    // Draw the game
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    59
    state.draw(this, flags & GUI_INPUT_DISPLAY_WEAPON);
180
bfe1077edab3 Ammuksia f:lla
ekku
parents: 162
diff changeset
    60
184
561892e2a30e try and sync graphics flip
terom
parents: 182
diff changeset
    61
    // Flip window buffer, sync
233
ff4ecea83cf5 start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents: 230
diff changeset
    62
    flip(1);
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    63
}
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    64
205
905028e58ed1 implement a new tick-timer that doesn't suck
terom
parents: 199
diff changeset
    65
void Graphics::on_update (TimeMS tick_length) {
25
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    66
    // check keyboard input
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    67
    check_input();
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    68
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    69
    // redraw display
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    70
    do_redraw();
af75a1894a32 simple proto *almost* works
terom
parents:
diff changeset
    71
}