2008-11-25 20:32:12 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-10-15 19:41:06 +02:00
|
|
|
/**
|
|
|
|
* @file allegro_v.cpp Implementation of the Allegro video driver.
|
|
|
|
* @note Implementing threaded pushing of data to the display is
|
|
|
|
* not faster (it's a few percent slower) in contrast to the
|
|
|
|
* results gained with threading it for SDL.
|
|
|
|
*/
|
2008-11-25 20:32:12 +01:00
|
|
|
|
|
|
|
#ifdef WITH_ALLEGRO
|
|
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
|
#include "../openttd.h"
|
|
|
|
#include "../gfx_func.h"
|
|
|
|
#include "../rev.h"
|
|
|
|
#include "../blitter/factory.hpp"
|
|
|
|
#include "../network/network.h"
|
|
|
|
#include "../core/random_func.hpp"
|
2011-02-07 23:49:38 +01:00
|
|
|
#include "../core/math_func.hpp"
|
2018-07-19 21:17:07 +02:00
|
|
|
#include "../framerate_type.h"
|
2019-03-17 11:05:53 +01:00
|
|
|
#include "../thread.h"
|
2008-11-25 20:32:12 +01:00
|
|
|
#include "allegro_v.h"
|
|
|
|
#include <allegro.h>
|
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2008-11-29 02:28:13 +01:00
|
|
|
#ifdef _DEBUG
|
|
|
|
/* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
|
2013-01-08 23:46:42 +01:00
|
|
|
* be triggered, so rereplace the signals and make the debugger useful. */
|
2008-11-29 02:28:13 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
static FVideoDriver_Allegro iFVideoDriver_Allegro;
|
|
|
|
|
|
|
|
static BITMAP *_allegro_screen;
|
|
|
|
|
|
|
|
#define MAX_DIRTY_RECTS 100
|
|
|
|
static PointDimension _dirty_rects[MAX_DIRTY_RECTS];
|
|
|
|
static int _num_dirty_rects;
|
|
|
|
|
|
|
|
void VideoDriver_Allegro::MakeDirty(int left, int top, int width, int height)
|
|
|
|
{
|
|
|
|
if (_num_dirty_rects < MAX_DIRTY_RECTS) {
|
|
|
|
_dirty_rects[_num_dirty_rects].x = left;
|
|
|
|
_dirty_rects[_num_dirty_rects].y = top;
|
|
|
|
_dirty_rects[_num_dirty_rects].width = width;
|
|
|
|
_dirty_rects[_num_dirty_rects].height = height;
|
|
|
|
}
|
|
|
|
_num_dirty_rects++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawSurfaceToScreen()
|
|
|
|
{
|
2018-07-19 21:17:07 +02:00
|
|
|
PerformanceMeasurer framerate(PFE_VIDEO);
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
int n = _num_dirty_rects;
|
|
|
|
if (n == 0) return;
|
|
|
|
|
|
|
|
_num_dirty_rects = 0;
|
|
|
|
if (n > MAX_DIRTY_RECTS) {
|
|
|
|
blit(_allegro_screen, screen, 0, 0, 0, 0, _allegro_screen->w, _allegro_screen->h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
blit(_allegro_screen, screen, _dirty_rects[i].x, _dirty_rects[i].y, _dirty_rects[i].x, _dirty_rects[i].y, _dirty_rects[i].width, _dirty_rects[i].height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void UpdatePalette(uint start, uint count)
|
|
|
|
{
|
|
|
|
static PALETTE pal;
|
|
|
|
|
|
|
|
uint end = start + count;
|
|
|
|
for (uint i = start; i != end; i++) {
|
2011-12-08 19:13:29 +01:00
|
|
|
pal[i].r = _cur_palette.palette[i].r / 4;
|
|
|
|
pal[i].g = _cur_palette.palette[i].g / 4;
|
|
|
|
pal[i].b = _cur_palette.palette[i].b / 4;
|
2008-11-25 20:32:12 +01:00
|
|
|
pal[i].filler = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_palette_range(pal, start, end - 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitPalette()
|
|
|
|
{
|
|
|
|
UpdatePalette(0, 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CheckPaletteAnim()
|
|
|
|
{
|
2011-12-08 19:13:29 +01:00
|
|
|
if (_cur_palette.count_dirty != 0) {
|
2014-01-02 23:41:58 +01:00
|
|
|
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
|
2008-11-25 20:32:12 +01:00
|
|
|
|
|
|
|
switch (blitter->UsePaletteAnimation()) {
|
|
|
|
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
|
2011-12-08 19:13:29 +01:00
|
|
|
UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
|
2008-11-25 20:32:12 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Blitter::PALETTE_ANIMATION_BLITTER:
|
2011-12-08 20:37:33 +01:00
|
|
|
blitter->PaletteAnimate(_cur_palette);
|
2008-11-25 20:32:12 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Blitter::PALETTE_ANIMATION_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
2011-12-08 19:13:29 +01:00
|
|
|
_cur_palette.count_dirty = 0;
|
2008-11-25 20:32:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Dimension default_resolutions[] = {
|
|
|
|
{ 640, 480},
|
|
|
|
{ 800, 600},
|
|
|
|
{1024, 768},
|
|
|
|
{1152, 864},
|
|
|
|
{1280, 800},
|
|
|
|
{1280, 960},
|
|
|
|
{1280, 1024},
|
|
|
|
{1400, 1050},
|
|
|
|
{1600, 1200},
|
|
|
|
{1680, 1050},
|
|
|
|
{1920, 1200}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void GetVideoModes()
|
|
|
|
{
|
|
|
|
/* Need to set a gfx_mode as there is NO other way to autodetect for
|
|
|
|
* cards ourselves... and we need a card to get the modes. */
|
|
|
|
set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
|
|
|
|
|
|
|
|
GFX_MODE_LIST *mode_list = get_gfx_mode_list(gfx_driver->id);
|
2019-04-10 23:07:06 +02:00
|
|
|
if (mode_list == nullptr) {
|
2008-11-25 20:32:12 +01:00
|
|
|
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
|
|
|
|
_num_resolutions = lengthof(default_resolutions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GFX_MODE *modes = mode_list->mode;
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
for (int i = 0; modes[i].bpp != 0; i++) {
|
2009-06-27 22:53:45 +02:00
|
|
|
uint w = modes[i].width;
|
|
|
|
uint h = modes[i].height;
|
2008-11-25 20:32:12 +01:00
|
|
|
if (w >= 640 && h >= 480) {
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
if (_resolutions[j].width == w && _resolutions[j].height == h) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == n) {
|
|
|
|
_resolutions[j].width = w;
|
|
|
|
_resolutions[j].height = h;
|
|
|
|
if (++n == lengthof(_resolutions)) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_num_resolutions = n;
|
|
|
|
SortResolutions(_num_resolutions);
|
|
|
|
|
|
|
|
destroy_gfx_mode_list(mode_list);
|
|
|
|
}
|
|
|
|
|
2009-06-27 22:53:45 +02:00
|
|
|
static void GetAvailableVideoMode(uint *w, uint *h)
|
2008-11-25 20:32:12 +01:00
|
|
|
{
|
2008-11-29 02:28:13 +01:00
|
|
|
/* No video modes, so just try it and see where it ends */
|
|
|
|
if (_num_resolutions == 0) return;
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
/* is the wanted mode among the available modes? */
|
|
|
|
for (int i = 0; i != _num_resolutions; i++) {
|
|
|
|
if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use the closest possible resolution */
|
|
|
|
int best = 0;
|
2009-06-27 22:53:45 +02:00
|
|
|
uint delta = Delta(_resolutions[0].width, *w) * Delta(_resolutions[0].height, *h);
|
2008-11-25 20:32:12 +01:00
|
|
|
for (int i = 1; i != _num_resolutions; ++i) {
|
2009-06-27 22:53:45 +02:00
|
|
|
uint newdelta = Delta(_resolutions[i].width, *w) * Delta(_resolutions[i].height, *h);
|
2008-11-25 20:32:12 +01:00
|
|
|
if (newdelta < delta) {
|
|
|
|
best = i;
|
|
|
|
delta = newdelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*w = _resolutions[best].width;
|
|
|
|
*h = _resolutions[best].height;
|
|
|
|
}
|
|
|
|
|
2009-06-27 22:53:45 +02:00
|
|
|
static bool CreateMainSurface(uint w, uint h)
|
2008-11-25 20:32:12 +01:00
|
|
|
{
|
2014-01-02 23:41:58 +01:00
|
|
|
int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
|
2008-11-25 20:32:12 +01:00
|
|
|
if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
|
|
|
|
set_color_depth(bpp);
|
|
|
|
|
|
|
|
GetAvailableVideoMode(&w, &h);
|
2008-11-29 02:28:13 +01:00
|
|
|
if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) {
|
2009-10-17 16:39:43 +02:00
|
|
|
DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on '%s'", allegro_error);
|
2008-11-29 02:28:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
2008-11-25 20:32:12 +01:00
|
|
|
|
2008-11-29 02:28:13 +01:00
|
|
|
/* The size of the screen might be bigger than the part we can actually draw on!
|
|
|
|
* So calculate the size based on the top, bottom, left and right */
|
|
|
|
_allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct);
|
|
|
|
_screen.width = _allegro_screen->w;
|
|
|
|
_screen.height = _allegro_screen->h;
|
|
|
|
_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8);
|
2009-12-19 19:46:40 +01:00
|
|
|
_screen.dst_ptr = _allegro_screen->line[0];
|
2008-11-25 20:32:12 +01:00
|
|
|
|
2008-11-29 02:28:13 +01:00
|
|
|
/* Initialise the screen so we don't blit garbage to the screen */
|
2009-12-19 19:46:40 +01:00
|
|
|
memset(_screen.dst_ptr, 0, _screen.height * _screen.pitch);
|
2008-11-29 02:28:13 +01:00
|
|
|
|
|
|
|
/* Set the mouse at the place where we expect it */
|
2008-11-25 20:32:12 +01:00
|
|
|
poll_mouse();
|
|
|
|
_cursor.pos.x = mouse_x;
|
|
|
|
_cursor.pos.y = mouse_y;
|
|
|
|
|
2014-01-02 23:41:58 +01:00
|
|
|
BlitterFactory::GetCurrentBlitter()->PostResize();
|
2010-01-04 03:32:36 +01:00
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
InitPalette();
|
|
|
|
|
|
|
|
char caption[32];
|
2014-04-23 23:12:09 +02:00
|
|
|
seprintf(caption, lastof(caption), "OpenTTD %s", _openttd_revision);
|
2008-11-25 20:32:12 +01:00
|
|
|
set_window_title(caption);
|
|
|
|
|
2011-11-17 22:09:08 +01:00
|
|
|
enable_hardware_cursor();
|
|
|
|
select_mouse_cursor(MOUSE_CURSOR_ARROW);
|
|
|
|
show_mouse(_allegro_screen);
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
GameSizeChanged();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-17 22:09:08 +01:00
|
|
|
bool VideoDriver_Allegro::ClaimMousePointer()
|
|
|
|
{
|
|
|
|
select_mouse_cursor(MOUSE_CURSOR_NONE);
|
2019-04-10 23:07:06 +02:00
|
|
|
show_mouse(nullptr);
|
2011-11-17 22:09:08 +01:00
|
|
|
disable_hardware_cursor();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
struct VkMapping {
|
|
|
|
uint16 vk_from;
|
|
|
|
byte vk_count;
|
|
|
|
byte map_to;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define AS(x, z) {x, 0, z}
|
|
|
|
#define AM(x, y, z, w) {x, y - x, z}
|
|
|
|
|
|
|
|
static const VkMapping _vk_mapping[] = {
|
|
|
|
/* Pageup stuff + up/down */
|
|
|
|
AM(KEY_PGUP, KEY_PGDN, WKC_PAGEUP, WKC_PAGEDOWN),
|
|
|
|
AS(KEY_UP, WKC_UP),
|
|
|
|
AS(KEY_DOWN, WKC_DOWN),
|
|
|
|
AS(KEY_LEFT, WKC_LEFT),
|
|
|
|
AS(KEY_RIGHT, WKC_RIGHT),
|
|
|
|
|
|
|
|
AS(KEY_HOME, WKC_HOME),
|
|
|
|
AS(KEY_END, WKC_END),
|
|
|
|
|
|
|
|
AS(KEY_INSERT, WKC_INSERT),
|
|
|
|
AS(KEY_DEL, WKC_DELETE),
|
|
|
|
|
|
|
|
/* Map letters & digits */
|
|
|
|
AM(KEY_A, KEY_Z, 'A', 'Z'),
|
|
|
|
AM(KEY_0, KEY_9, '0', '9'),
|
|
|
|
|
|
|
|
AS(KEY_ESC, WKC_ESC),
|
|
|
|
AS(KEY_PAUSE, WKC_PAUSE),
|
|
|
|
AS(KEY_BACKSPACE, WKC_BACKSPACE),
|
|
|
|
|
|
|
|
AS(KEY_SPACE, WKC_SPACE),
|
|
|
|
AS(KEY_ENTER, WKC_RETURN),
|
|
|
|
AS(KEY_TAB, WKC_TAB),
|
|
|
|
|
|
|
|
/* Function keys */
|
|
|
|
AM(KEY_F1, KEY_F12, WKC_F1, WKC_F12),
|
|
|
|
|
|
|
|
/* Numeric part. */
|
|
|
|
AM(KEY_0_PAD, KEY_9_PAD, '0', '9'),
|
|
|
|
AS(KEY_SLASH_PAD, WKC_NUM_DIV),
|
|
|
|
AS(KEY_ASTERISK, WKC_NUM_MUL),
|
|
|
|
AS(KEY_MINUS_PAD, WKC_NUM_MINUS),
|
|
|
|
AS(KEY_PLUS_PAD, WKC_NUM_PLUS),
|
|
|
|
AS(KEY_ENTER_PAD, WKC_NUM_ENTER),
|
|
|
|
AS(KEY_DEL_PAD, WKC_DELETE),
|
|
|
|
|
|
|
|
/* Other non-letter keys */
|
|
|
|
AS(KEY_SLASH, WKC_SLASH),
|
|
|
|
AS(KEY_SEMICOLON, WKC_SEMICOLON),
|
|
|
|
AS(KEY_EQUALS, WKC_EQUALS),
|
|
|
|
AS(KEY_OPENBRACE, WKC_L_BRACKET),
|
|
|
|
AS(KEY_BACKSLASH, WKC_BACKSLASH),
|
|
|
|
AS(KEY_CLOSEBRACE, WKC_R_BRACKET),
|
|
|
|
|
|
|
|
AS(KEY_QUOTE, WKC_SINGLEQUOTE),
|
|
|
|
AS(KEY_COMMA, WKC_COMMA),
|
|
|
|
AS(KEY_MINUS, WKC_MINUS),
|
|
|
|
AS(KEY_STOP, WKC_PERIOD),
|
|
|
|
AS(KEY_TILDE, WKC_BACKQUOTE),
|
|
|
|
};
|
|
|
|
|
2013-08-05 22:36:36 +02:00
|
|
|
static uint32 ConvertAllegroKeyIntoMy(WChar *character)
|
2008-11-25 20:32:12 +01:00
|
|
|
{
|
|
|
|
int scancode;
|
|
|
|
int unicode = ureadkey(&scancode);
|
|
|
|
|
|
|
|
const VkMapping *map;
|
|
|
|
uint key = 0;
|
|
|
|
|
|
|
|
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
|
|
|
|
if ((uint)(scancode - map->vk_from) <= map->vk_count) {
|
|
|
|
key = scancode - map->vk_from + map->map_to;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key_shifts & KB_SHIFT_FLAG) key |= WKC_SHIFT;
|
|
|
|
if (key_shifts & KB_CTRL_FLAG) key |= WKC_CTRL;
|
|
|
|
if (key_shifts & KB_ALT_FLAG) key |= WKC_ALT;
|
|
|
|
#if 0
|
|
|
|
DEBUG(driver, 0, "Scancode character pressed %u", scancode);
|
|
|
|
DEBUG(driver, 0, "Unicode character pressed %u", unicode);
|
|
|
|
#endif
|
2013-08-05 22:36:36 +02:00
|
|
|
|
|
|
|
*character = unicode;
|
|
|
|
return key;
|
2008-11-25 20:32:12 +01:00
|
|
|
}
|
|
|
|
|
2010-05-13 12:14:29 +02:00
|
|
|
static const uint LEFT_BUTTON = 0;
|
|
|
|
static const uint RIGHT_BUTTON = 1;
|
2008-11-25 20:32:12 +01:00
|
|
|
|
|
|
|
static void PollEvent()
|
|
|
|
{
|
|
|
|
poll_mouse();
|
|
|
|
|
|
|
|
bool mouse_action = false;
|
|
|
|
|
|
|
|
/* Mouse buttons */
|
|
|
|
static int prev_button_state;
|
|
|
|
if (prev_button_state != mouse_b) {
|
|
|
|
uint diff = prev_button_state ^ mouse_b;
|
|
|
|
while (diff != 0) {
|
2010-05-19 20:38:18 +02:00
|
|
|
uint button = FindFirstBit(diff);
|
2008-11-25 20:32:12 +01:00
|
|
|
ClrBit(diff, button);
|
|
|
|
if (HasBit(mouse_b, button)) {
|
|
|
|
/* Pressed mouse button */
|
2009-06-01 13:43:36 +02:00
|
|
|
if (_rightclick_emulate && (key_shifts & KB_CTRL_FLAG)) {
|
2008-11-25 20:32:12 +01:00
|
|
|
button = RIGHT_BUTTON;
|
|
|
|
ClrBit(diff, RIGHT_BUTTON);
|
|
|
|
}
|
|
|
|
switch (button) {
|
|
|
|
case LEFT_BUTTON:
|
|
|
|
_left_button_down = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIGHT_BUTTON:
|
|
|
|
_right_button_down = true;
|
|
|
|
_right_button_clicked = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* ignore rest */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Released mouse button */
|
|
|
|
if (_rightclick_emulate) {
|
|
|
|
_right_button_down = false;
|
|
|
|
_left_button_down = false;
|
|
|
|
_left_button_clicked = false;
|
|
|
|
} else if (button == LEFT_BUTTON) {
|
|
|
|
_left_button_down = false;
|
|
|
|
_left_button_clicked = false;
|
|
|
|
} else if (button == RIGHT_BUTTON) {
|
|
|
|
_right_button_down = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prev_button_state = mouse_b;
|
|
|
|
mouse_action = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mouse movement */
|
2015-02-23 00:06:45 +01:00
|
|
|
if (_cursor.UpdateCursorPosition(mouse_x, mouse_y, false)) {
|
|
|
|
position_mouse(_cursor.pos.x, _cursor.pos.y);
|
2008-11-25 20:32:12 +01:00
|
|
|
}
|
2015-02-23 00:06:45 +01:00
|
|
|
if (_cursor.delta.x != 0 || _cursor.delta.y) mouse_action = true;
|
2008-11-25 20:32:12 +01:00
|
|
|
|
2009-01-19 23:27:43 +01:00
|
|
|
static int prev_mouse_z = 0;
|
|
|
|
if (prev_mouse_z != mouse_z) {
|
|
|
|
_cursor.wheel = (prev_mouse_z - mouse_z) < 0 ? -1 : 1;
|
|
|
|
prev_mouse_z = mouse_z;
|
|
|
|
mouse_action = true;
|
|
|
|
}
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
if (mouse_action) HandleMouseEvents();
|
|
|
|
|
|
|
|
poll_keyboard();
|
2009-06-01 13:43:36 +02:00
|
|
|
if ((key_shifts & KB_ALT_FLAG) && (key[KEY_ENTER] || key[KEY_F])) {
|
2008-11-25 20:32:12 +01:00
|
|
|
ToggleFullScreen(!_fullscreen);
|
|
|
|
} else if (keypressed()) {
|
2013-08-05 22:36:36 +02:00
|
|
|
WChar character;
|
|
|
|
uint keycode = ConvertAllegroKeyIntoMy(&character);
|
|
|
|
HandleKeypress(keycode, character);
|
2008-11-25 20:32:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* There are multiple modules that might be using Allegro and
|
2010-08-01 21:44:49 +02:00
|
|
|
* Allegro can only be initiated once.
|
|
|
|
*/
|
2008-11-26 00:21:58 +01:00
|
|
|
int _allegro_instance_count = 0;
|
2008-11-25 22:09:00 +01:00
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
const char *VideoDriver_Allegro::Start(const char * const *parm)
|
|
|
|
{
|
2019-04-10 23:07:06 +02:00
|
|
|
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
|
2009-10-17 16:39:43 +02:00
|
|
|
DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
|
|
|
|
return "Failed to set up Allegro";
|
|
|
|
}
|
2008-11-26 00:21:58 +01:00
|
|
|
_allegro_instance_count++;
|
2008-11-25 20:32:12 +01:00
|
|
|
|
|
|
|
install_timer();
|
|
|
|
install_mouse();
|
|
|
|
install_keyboard();
|
|
|
|
|
2008-11-29 02:28:13 +01:00
|
|
|
#if defined _DEBUG
|
|
|
|
/* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
|
2013-01-08 23:46:42 +01:00
|
|
|
* be triggered, so rereplace the signals and make the debugger useful. */
|
2019-04-10 23:07:06 +02:00
|
|
|
signal(SIGABRT, nullptr);
|
|
|
|
signal(SIGSEGV, nullptr);
|
2008-11-29 02:28:13 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GetVideoModes();
|
2009-06-30 14:38:18 +02:00
|
|
|
if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) {
|
|
|
|
return "Failed to set up Allegro video";
|
|
|
|
}
|
2008-11-25 20:32:12 +01:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
set_close_button_callback(HandleExitGameRequest);
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
return nullptr;
|
2008-11-25 20:32:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoDriver_Allegro::Stop()
|
|
|
|
{
|
2008-11-26 00:21:58 +01:00
|
|
|
if (--_allegro_instance_count == 0) allegro_exit();
|
2008-11-25 20:32:12 +01:00
|
|
|
}
|
|
|
|
|
Remove: DOS support
In 10 years there was no active development on DOS. Although it
turned out to still work, the FPS was very bad. There is little
interest in the current community to look into this.
Further more, we like to switch to c++11 functions for threads,
which are not implemented by DJGPP, the only current compiler
for DOS.
Additionally, DOS is the only platform which does not support
networking. It is the reason we have tons of #ifdefs to support
disabling networking.
By removing DOS support, we can both use c++11 functions for threads,
and remove all the code related to disabling network. Sadly, this
means we have to see DOS go.
Of course, if you feel up for the task, simply revert this commit,
and implement stub c++11 functions for threads and stub functions
for networking. We are more than happy to accept such Pull Request.
2019-03-19 22:23:09 +01:00
|
|
|
#if defined(UNIX) || defined(__OS2__)
|
2008-11-25 20:32:12 +01:00
|
|
|
# include <sys/time.h> /* gettimeofday */
|
|
|
|
|
|
|
|
static uint32 GetTime()
|
|
|
|
{
|
|
|
|
struct timeval tim;
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
gettimeofday(&tim, nullptr);
|
2008-11-25 20:32:12 +01:00
|
|
|
return tim.tv_usec / 1000 + tim.tv_sec * 1000;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static uint32 GetTime()
|
|
|
|
{
|
|
|
|
return GetTickCount();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void VideoDriver_Allegro::MainLoop()
|
|
|
|
{
|
|
|
|
uint32 cur_ticks = GetTime();
|
|
|
|
uint32 last_cur_ticks = cur_ticks;
|
2010-11-19 11:35:59 +01:00
|
|
|
uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
|
2011-12-08 20:37:33 +01:00
|
|
|
|
|
|
|
CheckPaletteAnim();
|
2008-11-25 20:32:12 +01:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
|
|
|
|
InteractiveRandom(); // randomness
|
|
|
|
|
|
|
|
PollEvent();
|
|
|
|
if (_exit_game) return;
|
|
|
|
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
if (_shift_pressed)
|
|
|
|
#else
|
|
|
|
/* Speedup when pressing tab, except when using ALT+TAB
|
|
|
|
* to switch to another application */
|
2008-11-25 22:09:00 +01:00
|
|
|
if (key[KEY_TAB] && (key_shifts & KB_ALT_FLAG) == 0)
|
2008-11-25 20:32:12 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
|
|
} else if (_fast_forward & 2) {
|
|
|
|
_fast_forward = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_ticks = GetTime();
|
2009-05-06 17:06:57 +02:00
|
|
|
if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
|
2008-11-25 20:32:12 +01:00
|
|
|
_realtime_tick += cur_ticks - last_cur_ticks;
|
|
|
|
last_cur_ticks = cur_ticks;
|
2010-11-19 11:35:59 +01:00
|
|
|
next_tick = cur_ticks + MILLISECONDS_PER_TICK;
|
2008-11-25 20:32:12 +01:00
|
|
|
|
|
|
|
bool old_ctrl_pressed = _ctrl_pressed;
|
|
|
|
|
|
|
|
_ctrl_pressed = !!(key_shifts & KB_CTRL_FLAG);
|
|
|
|
_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG);
|
|
|
|
|
|
|
|
/* determine which directional keys are down */
|
|
|
|
_dirkeys =
|
|
|
|
(key[KEY_LEFT] ? 1 : 0) |
|
|
|
|
(key[KEY_UP] ? 2 : 0) |
|
|
|
|
(key[KEY_RIGHT] ? 4 : 0) |
|
|
|
|
(key[KEY_DOWN] ? 8 : 0);
|
|
|
|
|
|
|
|
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
|
|
|
|
|
|
|
|
GameLoop();
|
|
|
|
|
|
|
|
UpdateWindows();
|
2011-12-08 20:37:33 +01:00
|
|
|
CheckPaletteAnim();
|
2008-11-25 20:32:12 +01:00
|
|
|
DrawSurfaceToScreen();
|
|
|
|
} else {
|
|
|
|
CSleep(1);
|
|
|
|
NetworkDrawChatMessage();
|
|
|
|
DrawMouseCursor();
|
|
|
|
DrawSurfaceToScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoDriver_Allegro::ChangeResolution(int w, int h)
|
|
|
|
{
|
|
|
|
return CreateMainSurface(w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoDriver_Allegro::ToggleFullscreen(bool fullscreen)
|
|
|
|
{
|
|
|
|
_fullscreen = fullscreen;
|
|
|
|
GetVideoModes(); // get the list of available video modes
|
|
|
|
if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) {
|
|
|
|
/* switching resolution failed, put back full_screen to original status */
|
|
|
|
_fullscreen ^= true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-04 23:35:40 +02:00
|
|
|
bool VideoDriver_Allegro::AfterBlitterChange()
|
|
|
|
{
|
|
|
|
return CreateMainSurface(_screen.width, _screen.height);
|
|
|
|
}
|
|
|
|
|
2008-11-25 20:32:12 +01:00
|
|
|
#endif /* WITH_ALLEGRO */
|