1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
* Copyright (c) 1997 - 2001 Hansjrg Malthaner
*
* This file is part of the Simutrans project under the artistic license.
* (see license.txt)
*/
#include <stdio.h>
#include <string.h>
#include "simdebug.h"
#include "simsys.h"
#include "simintr.h"
#include "simwin.h"
#include "player/simplay.h"
#include "simworld.h"
#include "simview.h"
#include "boden/wasser.h"
static karte_t *welt_modell = NULL;
static karte_ansicht_t *welt_ansicht = NULL;
static long last_time;
static bool enabled = false;
#define FRAME_TIME_MULTI (16)
// pause between two frames
static long frame_time = 36*FRAME_TIME_MULTI;
bool reduce_frame_time()
{
if(frame_time > 25*FRAME_TIME_MULTI) {
frame_time -= 1;
if( frame_time>150*FRAME_TIME_MULTI ) {
frame_time -= 8;
}
return true;
}
else {
frame_time = 25*FRAME_TIME_MULTI;
return false;
}
}
bool increase_frame_time()
{
if(frame_time < 255*FRAME_TIME_MULTI) {
frame_time ++;
return true;
} else {
return false;
}
}
long get_frame_time()
{
return frame_time/FRAME_TIME_MULTI;
}
void set_frame_time(long time)
{
frame_time = clamp( time, 10, 250 )*FRAME_TIME_MULTI;
}
void intr_refresh_display(bool dirty)
{
wasser_t::prepare_for_refresh();
dr_prepare_flush();
welt_ansicht->display( dirty );
win_display_flush(welt_modell->get_active_player()->get_konto_als_double());
dr_flush();
}
void interrupt_check()
{
interrupt_check( "0" );
}
// debug version with caller information
void interrupt_check(const char* caller_info)
{
DBG_DEBUG4("interrupt_check", "called from (%s)", caller_info);
if(enabled) {
static uint32 last_ms = 0;
if( !welt_modell->is_fast_forward() || welt_modell->get_zeit_ms() != last_ms ) {
const long now = dr_time();
if((now-last_time)*FRAME_TIME_MULTI < frame_time) {
return;
}
const long diff = ((now - last_time)*welt_modell->get_time_multiplier())/16;
if(diff>0) {
enabled = false;
last_time = now;
welt_modell->sync_step( diff, !welt_modell->is_fast_forward(), true );
enabled = true;
}
}
last_ms = welt_modell->get_zeit_ms();
}
(void)caller_info;
}
void intr_set(karte_t *welt, karte_ansicht_t *view)
{
welt_modell = welt;
welt_ansicht = view;
last_time = dr_time();
enabled = true;
}
/**
* currently only used by the pause tool. Use with care!
* @author Hj. Malthaner
*/
void intr_set_last_time(long time)
{
last_time = time;
}
long intr_get_last_time()
{
return last_time;
}
void intr_disable()
{
enabled = false;
}
void intr_enable()
{
enabled = true;
}
|