Changeset - r13815:8cc0cdaaf624
[Not reviewed]
master
0 5 0
rubidium - 15 years ago 2009-11-30 11:29:52
rubidium@openttd.org
(svn r18351) -Fix [FS#3333]: endianness issue with saving the zoom level
5 files changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/saveload/misc_sl.cpp
Show inline comments
 
@@ -8,71 +8,72 @@
 
 */
 

	
 
/** @file misc_sl.cpp Saving and loading of things that didn't fit anywhere else */
 

	
 
#include "../stdafx.h"
 
#include "../date_func.h"
 
#include "../variables.h"
 
#include "../openttd.h"
 
#include "../zoom_func.h"
 
#include "../vehicle_func.h"
 
#include "../window_gui.h"
 
#include "../window_func.h"
 
#include "../viewport_func.h"
 
#include "../gfx_func.h"
 
#include "../company_base.h"
 
#include "../town.h"
 

	
 
#include "saveload.h"
 

	
 
extern TileIndex _cur_tileloop_tile;
 

	
 
/* Keep track of current game position */
 
int _saved_scrollpos_x;
 
int _saved_scrollpos_y;
 
ZoomLevelByte _saved_scrollpos_zoom;
 

	
 
void SaveViewportBeforeSaveGame()
 
{
 
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 

	
 
	if (w != NULL) {
 
		_saved_scrollpos_x = w->viewport->scrollpos_x;
 
		_saved_scrollpos_y = w->viewport->scrollpos_y;
 
		_saved_scrollpos_zoom = w->viewport->zoom;
 
	}
 
}
 

	
 
void ResetViewportAfterLoadGame()
 
{
 
	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 

	
 
	w->viewport->scrollpos_x = _saved_scrollpos_x;
 
	w->viewport->scrollpos_y = _saved_scrollpos_y;
 
	w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
 
	w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
 

	
 
	ViewPort *vp = w->viewport;
 
	vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
 
	vp->zoom = min<ZoomLevel>(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
 
	vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
 
	vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
 

	
 
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
 
	MarkWholeScreenDirty();
 
}
 

	
 

	
 
static const SaveLoadGlobVarList _date_desc[] = {
 
	SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
 
	SLEG_CONDVAR(_date,                   SLE_INT32,                  31, SL_MAX_VERSION),
 
	    SLEG_VAR(_date_fract,             SLE_UINT16),
 
	    SLEG_VAR(_tick_counter,           SLE_UINT16),
 
	    SLEG_VAR(_vehicle_id_ctr_day,     SLE_UINT16),
 
	    SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
 
	SLE_CONDNULL(1, 0, 45),
 
	SLEG_CONDVAR(_cur_tileloop_tile,      SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
 
	SLEG_CONDVAR(_cur_tileloop_tile,      SLE_UINT32,                  6, SL_MAX_VERSION),
 
	    SLEG_VAR(_disaster_delay,         SLE_UINT16),
 
	SLE_CONDNULL(2, 0, 119),
 
	    SLEG_VAR(_random.state[0],        SLE_UINT32),
 
	    SLEG_VAR(_random.state[1],        SLE_UINT32),
 
	SLE_CONDNULL(1,  0,   9),
 
	SLE_CONDNULL(4, 10, 119),
src/saveload/saveload_internal.h
Show inline comments
 
@@ -24,33 +24,34 @@ char *CopyFromOldName(StringID id);
 
void ResetOldNames();
 

	
 
void MoveBuoysToWaypoints();
 
void MoveWaypointsToBaseStations();
 
const SaveLoad *GetBaseStationDescription();
 

	
 
void AfterLoadVehicles(bool part_of_load);
 
void AfterLoadStations();
 
void AfterLoadLabelMaps();
 
void UpdateHousesAndTowns();
 

	
 
void UpdateOldAircraft();
 

	
 
void SaveViewportBeforeSaveGame();
 
void ResetViewportAfterLoadGame();
 

	
 
void ConvertOldMultiheadToNew();
 
void ConnectMultiheadedTrains();
 

	
 
Engine *GetTempDataEngine(EngineID index);
 
void CopyTempEngineData();
 

	
 
extern int32 _saved_scrollpos_x;
 
extern int32 _saved_scrollpos_y;
 
extern ZoomLevelByte _saved_scrollpos_zoom;
 

	
 
extern SavegameType _savegame_type;
 
extern uint32 _ttdp_version;
 

	
 
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face);
 

	
 
Order UnpackOldOrder(uint16 packed);
 

	
 
#endif /* SAVELOAD_INTERNAL_H */
src/viewport.cpp
Show inline comments
 
@@ -32,49 +32,48 @@
 
#include "station_base.h"
 
#include "waypoint_base.h"
 
#include "town.h"
 
#include "signs_base.h"
 
#include "signs_func.h"
 
#include "variables.h"
 
#include "vehicle_base.h"
 
#include "vehicle_gui.h"
 
#include "blitter/factory.hpp"
 
#include "transparency.h"
 
#include "strings_func.h"
 
#include "zoom_func.h"
 
#include "vehicle_func.h"
 
#include "company_func.h"
 
#include "waypoint_func.h"
 
#include "window_func.h"
 
#include "tilehighlight_func.h"
 
#include "window_gui.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
PlaceProc *_place_proc;
 
Point _tile_fract_coords;
 
ZoomLevel _saved_scrollpos_zoom;
 

	
 
struct StringSpriteToDraw {
 
	StringID string;
 
	Colours colour;
 
	int32 x;
 
	int32 y;
 
	uint64 params[2];
 
	uint16 width;
 
};
 

	
 
struct TileSpriteToDraw {
 
	SpriteID image;
 
	SpriteID pal;
 
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
 
	int32 x;                        ///< screen X coordinate of sprite
 
	int32 y;                        ///< screen Y coordinate of sprite
 
};
 

	
 
struct ChildScreenSpriteToDraw {
 
	SpriteID image;
 
	SpriteID pal;
 
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
 
	int32 x;
 
	int32 y;
src/zoom_func.h
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * 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/>.
 
 */
 

	
 
/** @file zoom_func.h Functions related to zooming. */
 

	
 
#ifndef ZOOM_FUNC_H
 
#define ZOOM_FUNC_H
 

	
 
#include "zoom_type.h"
 

	
 
extern ZoomLevel _saved_scrollpos_zoom;
 

	
 
/**
 
 * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL)
 
 * When shifting right, value is rounded up
 
 * @param value value to shift
 
 * @param zoom  zoom level to shift to
 
 * @return shifted value
 
 */
 
static inline int ScaleByZoom(int value, ZoomLevel zoom)
 
{
 
	if (zoom == ZOOM_LVL_NORMAL) return value;
 
	int izoom = zoom - ZOOM_LVL_NORMAL;
 
	return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom;
 
}
 

	
 
/**
 
 * Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL)
 
 * When shifting right, value is rounded up
 
 * @param value value to shift
 
 * @param zoom  zoom level to shift to
 
 * @return shifted value
 
 */
 
static inline int UnScaleByZoom(int value, ZoomLevel zoom)
 
{
 
	if (zoom == ZOOM_LVL_NORMAL) return value;
src/zoom_type.h
Show inline comments
 
@@ -23,25 +23,27 @@ enum ZoomLevel {
 
	ZOOM_LVL_OUT_8X,
 
	ZOOM_LVL_END,
 

	
 
	/* Number of zoom levels */
 
	ZOOM_LVL_COUNT = ZOOM_LVL_END - ZOOM_LVL_BEGIN,
 

	
 
	/* Here we define in which zoom viewports are */
 
	ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_NEWS     = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_INDUSTRY = ZOOM_LVL_OUT_2X,
 
	ZOOM_LVL_TOWN     = ZOOM_LVL_OUT_2X,
 
	ZOOM_LVL_AIRCRAFT = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_SHIP     = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_TRAIN    = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_ROADVEH  = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_WORLD_SCREENSHOT = ZOOM_LVL_NORMAL,
 

	
 
	ZOOM_LVL_DETAIL   = ZOOM_LVL_OUT_2X, ///< All zoomlevels below or equal to this, will result in details on the screen, like road-work, ...
 

	
 
	ZOOM_LVL_MIN      = ZOOM_LVL_NORMAL,
 
	ZOOM_LVL_MAX      = ZOOM_LVL_OUT_8X,
 
};
 
DECLARE_POSTFIX_INCREMENT(ZoomLevel)
 

	
 
typedef SimpleTinyEnumT<ZoomLevel, byte> ZoomLevelByte;
 

	
 
#endif /* ZOOM_TYPE_H */
0 comments (0 inline, 0 general)