// (c) 1995-2014 by Artsoft Entertainment
// Holger Schemel
// info@artsoft.org
-// http://www.artsoft.org/
+// https://www.artsoft.org/
// ----------------------------------------------------------------------------
// tools.c
// ============================================================================
return s;
}
-int correctLevelPosX_EM(int lx)
-{
- lx -= 1;
- lx -= (BorderElement != EL_EMPTY ? 1 : 0);
-
- return lx;
-}
-
-int correctLevelPosY_EM(int ly)
-{
- ly -= 1;
- ly -= (BorderElement != EL_EMPTY ? 1 : 0);
-
- return ly;
-}
-
int getFieldbufferOffsetX_RND(int dir, int pos)
{
int full_lev_fieldx = lev_fieldx + (BorderElement != EL_EMPTY ? 2 : 0);
int px = sx - SX;
int lx = LEVELX((px + dx) / TILESIZE_VAR);
- lx = correctLevelPosX_EM(lx);
-
return lx;
}
int py = sy - SY;
int ly = LEVELY((py + dy) / TILESIZE_VAR);
- ly = correctLevelPosY_EM(ly);
-
return ly;
}
return;
}
- token_name = element_info[Feld[x][y]].token_name;
+ token_name = element_info[Tile[x][y]].token_name;
- printf(" Feld: %d\t['%s']\n", Feld[x][y], token_name);
+ printf(" Tile: %d\t['%s']\n", Tile[x][y], token_name);
printf(" Back: %s\n", print_if_not_empty(Back[x][y]));
printf(" Store: %s\n", print_if_not_empty(Store[x][y]));
printf(" Store2: %s\n", print_if_not_empty(Store2[x][y]));
diff_bar[pos++] = '\0';
- Error(ERR_INFO, "%06d [%02d] [%c%02d] %s",
+ Debug("time:frame", "%06d [%02d] [%c%02d] %s",
counter,
diff_1,
(diff_2 < 0 ? '-' : diff_2 > 0 ? '+' : ' '), ABS(diff_2),
height = WIN_YSIZE;
}
- if (!setup.fade_screens ||
- fade_delay == 0 ||
- fading.fade_mode == FADE_MODE_NONE)
- {
- if (fade_mode == FADE_MODE_FADE_OUT)
- return;
-
- BlitBitmap(backbuffer, window, x, y, width, height, x, y);
-
- redraw_mask &= ~fade_mask;
+ // when switching screens without fading, set fade delay to zero
+ if (!setup.fade_screens || fading.fade_mode == FADE_MODE_NONE)
+ fade_delay = 0;
+ // do not display black frame when fading out without fade delay
+ if (fade_mode == FADE_MODE_FADE_OUT && fade_delay == 0)
return;
- }
FadeRectangle(x, y, width, height, fade_mode, fade_delay, post_delay,
draw_border_function);
global.anim_status = global.anim_status_next;
// store backbuffer with all animations that will be started after fading in
- if (fade_type_skip != FADE_MODE_SKIP_FADE_IN)
- PrepareFadeBitmap(DRAW_TO_FADE_TARGET);
+ PrepareFadeBitmap(DRAW_TO_FADE_TARGET);
// set screen mode for animations back to fading
global.anim_status = GAME_MODE_PSEUDO_FADING;
global.anim_status = GAME_MODE_PSEUDO_FADING;
// store backbuffer with all animations that will be stopped for fading out
- if (fade_type_skip != FADE_MODE_SKIP_FADE_OUT)
- PrepareFadeBitmap(DRAW_TO_FADE_SOURCE);
+ PrepareFadeBitmap(DRAW_TO_FADE_SOURCE);
}
static void SetScreenStates_AfterFadingOut(void)
BorderElement = EL_EMPTY;
- // the MM game engine does not use a visible border element
- if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
+ // only the R'n'D game engine may use an additional steelwall border
+ if (level.game_engine_type != GAME_ENGINE_TYPE_RND)
return;
for (y = 0; y < lev_fieldy && BorderElement == EL_EMPTY; y++)
{
for (x = 0; x < lev_fieldx; x++)
{
- if (!IS_INDESTRUCTIBLE(Feld[x][y]))
+ if (!IS_INDESTRUCTIBLE(Tile[x][y]))
BorderElement = EL_STEELWALL;
if (y != 0 && y != lev_fieldy - 1 && x != lev_fieldx - 1)
{
boolean left_stopped = FALSE, right_stopped = FALSE;
- if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Feld[lx - 1][ly]))
+ if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Tile[lx - 1][ly]))
left_stopped = TRUE;
- if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Feld[lx + 1][ly]))
+ if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Tile[lx + 1][ly]))
right_stopped = TRUE;
if (left_stopped && right_stopped)
void DrawLevelFieldThruMask(int x, int y)
{
- DrawLevelElementExt(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING);
+ DrawLevelElementExt(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING);
}
// !!! implementation of quicksand is totally broken !!!
continue;
// do not crumble fields that are being digged or snapped
- if (Feld[xx][yy] == EL_EMPTY ||
- Feld[xx][yy] == EL_ELEMENT_SNAPPING)
+ if (Tile[xx][yy] == EL_EMPTY ||
+ Tile[xx][yy] == EL_ELEMENT_SNAPPING)
continue;
element = TILE_GFX_ELEMENT(xx, yy);
!IN_SCR_FIELD(sxx, syy))
continue;
- if (Feld[xx][yy] == EL_ELEMENT_SNAPPING)
+ if (Tile[xx][yy] == EL_ELEMENT_SNAPPING)
continue;
element = TILE_GFX_ELEMENT(xx, yy);
if (!IN_LEV_FIELD(x, y))
return;
- if (Feld[x][y] == EL_ELEMENT_SNAPPING &&
+ if (Tile[x][y] == EL_ELEMENT_SNAPPING &&
GfxElement[x][y] != EL_UNDEFINED &&
GFX_CRUMBLED(GfxElement[x][y]))
{
if (!IN_LEV_FIELD(xx, yy) ||
!IN_SCR_FIELD(sxx, syy) ||
- !GFX_CRUMBLED(Feld[xx][yy]) ||
+ !GFX_CRUMBLED(Tile[xx][yy]) ||
IS_MOVING(xx, yy))
continue;
if (!IN_LEV_FIELD(xx, yy) ||
!IN_SCR_FIELD(sxx, syy) ||
- !GFX_CRUMBLED(Feld[xx][yy]) ||
+ !GFX_CRUMBLED(Tile[xx][yy]) ||
IS_MOVING(xx, yy))
continue;
return;
}
- element = Feld[lx][ly];
+ element = Tile[lx][ly];
content = Store[lx][ly];
if (IS_MOVING(lx, ly))
horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
MovDir[oldx][oldy] == MV_RIGHT);
- element_old = Feld[oldx][oldy];
+ element_old = Tile[oldx][oldy];
content_old = Store[oldx][oldy];
if (element_old == EL_QUICKSAND_EMPTYING ||
if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
DrawSizedElement(sx, sy, EL_EMPTY, tilesize);
else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
- DrawSizedElement(sx, sy, Feld[x][y], tilesize);
+ DrawSizedElement(sx, sy, Tile[x][y], tilesize);
else
DrawSizedGraphic(sx, sy, el2edimg(getBorderElement(x, y)), 0, tilesize);
}
if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
DrawMiniElement(sx, sy, EL_EMPTY);
else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
- DrawMiniElement(sx, sy, Feld[x][y]);
+ DrawMiniElement(sx, sy, Tile[x][y]);
else
DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y)));
}
if (GFX_CRUMBLED(TILE_GFX_ELEMENT(x, y)))
DrawLevelFieldCrumbled(x, y);
#else
- if (GFX_CRUMBLED(Feld[x][y]))
+ if (GFX_CRUMBLED(Tile[x][y]))
DrawLevelFieldCrumbled(x, y);
#endif
}
int sy = SCREENY(jy);
int sxx = (move_dir == MV_LEFT || move_dir == MV_RIGHT ? player->GfxPos : 0);
int syy = (move_dir == MV_UP || move_dir == MV_DOWN ? player->GfxPos : 0);
- int element = Feld[jx][jy];
- int last_element = Feld[last_jx][last_jy];
+ int element = Tile[jx][jy];
+ int last_element = Tile[last_jx][last_jy];
int action = (player->is_pushing ? ACTION_PUSHING :
player->is_digging ? ACTION_DIGGING :
player->is_collecting ? ACTION_COLLECTING :
if (!IS_MOVING(jx, jy)) // push movement already finished
{
- element = Feld[next_jx][next_jy];
+ element = Tile[next_jx][next_jy];
gfx_frame = GfxFrame[next_jx][next_jy];
}
// do not draw (EM style) pushing animation when pushing is finished
// (two-tile animations usually do not contain start and end frame)
if (graphic_info[graphic].double_movement && !IS_MOVING(jx, jy))
- DrawLevelElement(next_jx, next_jy, Feld[next_jx][next_jy]);
+ DrawLevelElement(next_jx, next_jy, Tile[next_jx][next_jy]);
else
DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING);
#else
int action;
int direction;
}
-em_object_mapping_list[TILE_MAX + 1] =
+em_object_mapping_list[GAME_TILE_MAX + 1] =
{
{
Zborder, FALSE, FALSE,
EL_SPRING, -1, -1
},
{
- Xspring_e, FALSE, FALSE,
- EL_SPRING, -1, -1
+ Xspring_e, TRUE, FALSE,
+ EL_SPRING_RIGHT, -1, -1
},
{
- Xspring_w, FALSE, FALSE,
- EL_SPRING, -1, -1
+ Xspring_w, TRUE, FALSE,
+ EL_SPRING_LEFT, -1, -1
},
{
Xspring_fall, FALSE, FALSE,
},
{
Xpush_spring_e, FALSE, FALSE,
- EL_SPRING, -1, MV_BIT_RIGHT
+ EL_SPRING_RIGHT, -1, MV_BIT_RIGHT
},
{
Xpush_spring_w, FALSE, FALSE,
- EL_SPRING, -1, MV_BIT_LEFT
+ EL_SPRING_LEFT, -1, MV_BIT_LEFT
},
{
},
{
- Xdrip, FALSE, FALSE,
+ Xdrip, TRUE, FALSE,
EL_AMOEBA_DROP, ACTION_GROWING, -1
},
{
- Xdrip_fall, TRUE, FALSE,
+ Xdrip_fall, FALSE, FALSE,
EL_AMOEBA_DROP, -1, -1
},
{
mapping_initialized = TRUE;
}
- if (element_rnd >= 0 && element_rnd < NUM_FILE_ELEMENTS)
- return map_em_element_X_to_C(mapping_RND_to_EM[element_rnd]);
+ if (element_rnd < 0 || element_rnd >= NUM_FILE_ELEMENTS)
+ {
+ Warn("invalid RND level element %d", element_rnd);
- Error(ERR_WARN, "invalid RND level element %d", element_rnd);
+ return EL_UNKNOWN;
+ }
- return EL_UNKNOWN;
+ return map_em_element_X_to_C(mapping_RND_to_EM[element_rnd]);
}
int map_element_EM_to_RND_cave(int element_em_cave)
{
- static unsigned short mapping_EM_to_RND[TILE_MAX];
+ static unsigned short mapping_EM_to_RND[GAME_TILE_MAX];
static boolean mapping_initialized = FALSE;
if (!mapping_initialized)
int i;
// return "EL_UNKNOWN" for all undefined elements in mapping array
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
mapping_EM_to_RND[i] = EL_UNKNOWN;
for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
mapping_initialized = TRUE;
}
- if (element_em_cave >= 0 && element_em_cave < CAVE_TILE_MAX)
- return mapping_EM_to_RND[map_em_element_C_to_X(element_em_cave)];
+ if (element_em_cave < 0 || element_em_cave >= CAVE_TILE_MAX)
+ {
+ Warn("invalid EM cave element %d", element_em_cave);
- Error(ERR_WARN, "invalid EM cave element %d", element_em_cave);
+ return EL_UNKNOWN;
+ }
- return EL_UNKNOWN;
+ return mapping_EM_to_RND[map_em_element_C_to_X(element_em_cave)];
}
int map_element_EM_to_RND_game(int element_em_game)
{
- static unsigned short mapping_EM_to_RND[TILE_MAX];
+ static unsigned short mapping_EM_to_RND[GAME_TILE_MAX];
static boolean mapping_initialized = FALSE;
if (!mapping_initialized)
int i;
// return "EL_UNKNOWN" for all undefined elements in mapping array
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
mapping_EM_to_RND[i] = EL_UNKNOWN;
for (i = 0; em_object_mapping_list[i].element_em != -1; i++)
mapping_initialized = TRUE;
}
- if (element_em_game >= 0 && element_em_game < TILE_MAX)
- return mapping_EM_to_RND[element_em_game];
+ if (element_em_game < 0 || element_em_game >= GAME_TILE_MAX)
+ {
+ Warn("invalid EM game element %d", element_em_game);
- Error(ERR_WARN, "invalid EM game element %d", element_em_game);
+ return EL_UNKNOWN;
+ }
- return EL_UNKNOWN;
+ return mapping_EM_to_RND[element_em_game];
}
void map_android_clone_elements_RND_to_EM(struct LevelInfo *level)
struct CAVE *cav = level_em->cav;
int i, j;
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
cav->android_array[i] = Cblank;
for (i = 0; i < level->num_android_clone_elements; i++)
level->num_android_clone_elements = 0;
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
{
int element_em_cave = cav->android_array[i];
int element_rnd;
return getBeltSwitchElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr);
}
+boolean swapTiles_EM(boolean is_pre_emc_cave)
+{
+ return is_pre_emc_cave && leveldir_current->use_emc_tiles;
+}
+
boolean getTeamMode_EM(void)
{
return game.team_mode || network_playing;
}
+boolean isActivePlayer_EM(int player_nr)
+{
+ return stored_player[player_nr].active;
+}
+
unsigned int InitRND(int seed)
{
if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
return InitEngineRandom_RND(seed);
}
-static struct Mapping_EM_to_RND_object object_mapping[TILE_MAX];
+static struct Mapping_EM_to_RND_object object_mapping[GAME_TILE_MAX];
static struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][PLY_MAX];
static int get_effective_element_EM(int tile, int frame_em)
int i, j, p;
// always start with reliable default values
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
{
object_mapping[i].element_rnd = EL_UNKNOWN;
object_mapping[i].is_backside = FALSE;
MV_DIR_FROM_BIT(em_player_mapping_list[i].direction);
}
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
{
int element = object_mapping[i].element_rnd;
int action = object_mapping[i].action;
}
}
- for (i = 0; i < TILE_MAX; i++)
+ for (i = 0; i < GAME_TILE_MAX; i++)
{
for (j = 0; j < 8; j++)
{
boolean any_player_snapping,
boolean any_player_dropping)
{
- if (frame == 0 && !any_player_dropping)
+ if (frame == 7 && !any_player_dropping)
{
if (!local_player->was_waiting)
{
boolean any_player_dropping)
{
if (tape.single_step && tape.recording && !tape.pausing)
- if (frame == 0 && !any_player_dropping)
+ if (frame == 7 && !any_player_dropping)
TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
CheckSaveEngineSnapshot_EM(action, frame, any_player_moving,
#endif
}
-void ToggleFullscreenOrChangeWindowScalingIfNeeded(void)
+void ToggleFullscreenIfNeeded(void)
{
- boolean change_fullscreen = (setup.fullscreen !=
- video.fullscreen_enabled);
- boolean change_window_scaling_percent = (!video.fullscreen_enabled &&
- setup.window_scaling_percent !=
- video.window_scaling_percent);
-
- if (change_window_scaling_percent && video.fullscreen_enabled)
+ // if setup and video fullscreen state are already matching, nothing do do
+ if (setup.fullscreen == video.fullscreen_enabled ||
+ !video.fullscreen_available)
return;
- if (!change_window_scaling_percent && !video.fullscreen_available)
- return;
+ SDLSetWindowFullscreen(setup.fullscreen);
- if (change_window_scaling_percent)
- {
- SDLSetWindowScaling(setup.window_scaling_percent);
+ // set setup value according to successfully changed fullscreen mode
+ setup.fullscreen = video.fullscreen_enabled;
+}
+void ChangeWindowScalingIfNeeded(void)
+{
+ // if setup and video window scaling are already matching, nothing do do
+ if (setup.window_scaling_percent == video.window_scaling_percent ||
+ video.fullscreen_enabled)
return;
- }
- else if (change_fullscreen)
- {
- SDLSetWindowFullscreen(setup.fullscreen);
- // set setup value according to successfully changed fullscreen mode
- setup.fullscreen = video.fullscreen_enabled;
+ SDLSetWindowScaling(setup.window_scaling_percent);
+ // set setup value according to successfully changed window scaling
+ setup.window_scaling_percent = video.window_scaling_percent;
+}
+
+void ChangeVsyncModeIfNeeded(void)
+{
+ int setup_vsync_mode = VSYNC_MODE_STR_TO_INT(setup.vsync_mode);
+ int video_vsync_mode = video.vsync_mode;
+
+ // if setup and video vsync mode are already matching, nothing do do
+ if (setup_vsync_mode == video_vsync_mode)
return;
- }
- if (change_fullscreen ||
- change_window_scaling_percent)
+ // if renderer is using OpenGL, vsync mode can directly be changed
+ SDLSetScreenVsyncMode(setup.vsync_mode);
+
+ // if vsync mode unchanged, try re-creating renderer to set vsync mode
+ if (video.vsync_mode == video_vsync_mode)
{
Bitmap *tmp_backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
- // save backbuffer content which gets lost when toggling fullscreen mode
+ // save backbuffer content which gets lost when re-creating screen
BlitBitmap(backbuffer, tmp_backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
- if (change_window_scaling_percent)
- {
- // keep window mode, but change window scaling
- video.fullscreen_enabled = TRUE; // force new window scaling
- }
+ // force re-creating screen and renderer to set new vsync mode
+ video.fullscreen_enabled = !setup.fullscreen;
+
+ // when creating new renderer, destroy textures linked to old renderer
+ FreeAllImageTextures(); // needs old renderer to free the textures
- // toggle fullscreen
+ // re-create screen and renderer (including change of vsync mode)
ChangeVideoModeIfNeeded(setup.fullscreen);
// set setup value according to successfully changed fullscreen mode
// restore backbuffer content from temporary backbuffer backup bitmap
BlitBitmap(tmp_backbuffer, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
-
FreeBitmap(tmp_backbuffer);
// update visible window/screen
BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+
+ // when changing vsync mode, re-create textures for new renderer
+ InitImageTextures();
}
+
+ // set setup value according to successfully changed vsync mode
+ setup.vsync_mode = VSYNC_MODE_INT_TO_STR(video.vsync_mode);
}
static void JoinRectangles(int *x, int *y, int *width, int *height,
if (init_em_graphics)
{
- InitGraphicInfo_EM();
+ InitGraphicInfo_EM();
}
}