source: abuse/branches/lol/src/sdlport/video.cpp @ 732

Last change on this file since 732 was 732, checked in by Sam Hocevar, 9 years ago

build: SDL2 compilation fixes.

File size: 3.0 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au>
[724]4 *  Copyright (c) 2005-2013 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This program is free software; you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation; either version 2 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software Foundation,
18 *  Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 */
[2]20
[732]21#if HAVE_CONFIG_H
[555]22#   include "config.h"
23#endif
[56]24
[724]25#include "common.h"
[134]26
[724]27#include "imlib/filter.h"
28#include "imlib/video.h"
29#include "imlib/image.h"
[134]30
[2]31#include "setup.h"
32
[729]33array<uint8_t> g_screen;
[701]34
[709]35AImage *main_screen = NULL;
[700]36int mouse_xscale, mouse_yscale;
[162]37int xres, yres;
[142]38
[694]39extern Palette *lastl;
[2]40extern flags_struct flags;
41
42//
[700]43// CreateScreen()
[2]44// Set the video mode
45//
[700]46void CreateScreen(int argc, char **argv)
[2]47{
[700]48    mouse_xscale = 1 << 16;
49    mouse_yscale = 1 << 16;
[2]50
[701]51    /* Temporary screen buffer */
52    g_screen.Resize(xres * yres);
[699]53
[124]54    // Create the screen image
[709]55    main_screen = new AImage(ivec2(xres, yres), 2);
[700]56    if (main_screen == NULL)
[124]57    {
58        // Our screen image is no good, we have to bail.
[134]59        printf("Video : Unable to create screen image.\n");
60        exit(1);
[124]61    }
[643]62    main_screen->clear();
[2]63
[643]64    update_dirty(main_screen);
[2]65}
66
67//
[700]68// DestroyScreen()
[2]69// Shutdown the video mode
70//
[700]71void DestroyScreen()
[2]72{
[700]73    if (lastl)
[124]74        delete lastl;
75    lastl = NULL;
[688]76
[643]77    delete main_screen;
[2]78}
79
80// put_part_image()
[701]81// Draw only dirty parts of the image to screen
[2]82//
[709]83void put_part_image(AImage *im, int x, int y, int x1, int y1, int x2, int y2)
[2]84{
[124]85    int xe, ye;
[700]86    int srcx, srcy;
[688]87    uint8_t *dpixel;
[2]88
[700]89    if (y > yres || x > xres)
[124]90        return;
[2]91
[687]92    ASSERT(x1 >= 0);
93    ASSERT(x2 >= x1);
94    ASSERT(y1 >= 0);
95    ASSERT(y2 >= y1);
[134]96
[124]97    // Adjust if we are trying to draw off the screen
[700]98    if (x < 0)
[124]99    {
100        x1 += -x;
101        x = 0;
102    }
[700]103    srcx = x1;
104    if (x + (x2 - x1) >= xres)
[124]105        xe = xres - x + x1 - 1;
106    else
107        xe = x2;
[134]108
[700]109    if (y < 0)
[124]110    {
111        y1 += -y;
112        y = 0;
113    }
[700]114    srcy = y1;
115    if (y + (y2 - y1) >= yres)
[124]116        ye = yres - y + y1 - 1;
117    else
118        ye = y2;
[134]119
[700]120    if (srcx >= xe || srcy >= ye)
[124]121        return;
[2]122
[700]123    int w = xe - srcx;
124    int h = ye - srcy;
[2]125
[701]126    dpixel = g_screen.Data() + x + y * xres;
[2]127
[124]128    // Update surface part
[700]129    for (int i = 0; i < h; i++)
[124]130    {
[700]131        memcpy(dpixel, im->scan_line(srcy) + srcx , w);
[701]132        dpixel += xres;
[700]133        srcy++;
[124]134    }
[2]135}
136
137// ---- support functions ----
138
[700]139void UpdateScreen()
[2]140{
[701]141    /* FIXME: synchronisation */
[2]142}
143
Note: See TracBrowser for help on using the repository browser.