Adding of _t to (u)int types, and WChar to char32_t

See: eaae0bb5e
mapgen-water-desert-removal-circular
Jonathan G Rennison 4 months ago
parent 55d78a23be
commit 97e6f3062e

@ -60,7 +60,7 @@
#include "../../safeguards.h"
#define T_MASK ((uint32)~0)
#define T_MASK ((uint32_t)~0)
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
#define T3 0x242070db
@ -126,31 +126,31 @@
#define T63 0x2ad7d2bb
#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
static inline void Md5Set1(const uint32 *X, uint32 *a, const uint32 *b, const uint32 *c, const uint32 *d, const uint8 k, const uint8 s, const uint32 Ti)
static inline void Md5Set1(const uint32_t *X, uint32_t *a, const uint32_t *b, const uint32_t *c, const uint32_t *d, const uint8_t k, const uint8_t s, const uint32_t Ti)
{
uint32 t = (*b & *c) | (~*b & *d);
uint32_t t = (*b & *c) | (~*b & *d);
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
}
static inline void Md5Set2(const uint32 *X, uint32 *a, const uint32 *b, const uint32 *c, const uint32 *d, const uint8 k, const uint8 s, const uint32 Ti)
static inline void Md5Set2(const uint32_t *X, uint32_t *a, const uint32_t *b, const uint32_t *c, const uint32_t *d, const uint8_t k, const uint8_t s, const uint32_t Ti)
{
uint32 t = (*b & *d) | (*c & ~*d);
uint32_t t = (*b & *d) | (*c & ~*d);
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
}
static inline void Md5Set3(const uint32 *X, uint32 *a, const uint32 *b, const uint32 *c, const uint32 *d, const uint8 k, const uint8 s, const uint32 Ti)
static inline void Md5Set3(const uint32_t *X, uint32_t *a, const uint32_t *b, const uint32_t *c, const uint32_t *d, const uint8_t k, const uint8_t s, const uint32_t Ti)
{
uint32 t = *b ^ *c ^ *d;
uint32_t t = *b ^ *c ^ *d;
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
}
static inline void Md5Set4(const uint32 *X, uint32 *a, const uint32 *b, const uint32 *c, const uint32 *d, const uint8 k, const uint8 s, const uint32 Ti)
static inline void Md5Set4(const uint32_t *X, uint32_t *a, const uint32_t *b, const uint32_t *c, const uint32_t *d, const uint8_t k, const uint8_t s, const uint32_t Ti)
{
uint32 t = *c ^ (*b | ~*d);
uint32_t t = *c ^ (*b | ~*d);
t += *a + X[k] + Ti;
*a = ROL(t, s) + *b;
}
@ -165,17 +165,17 @@ Md5::Md5()
abcd[3] = 0x10325476;
}
void Md5::Process(const uint8 *data /*[64]*/)
void Md5::Process(const uint8_t *data /*[64]*/)
{
uint32 a = this->abcd[0];
uint32 b = this->abcd[1];
uint32 c = this->abcd[2];
uint32 d = this->abcd[3];
uint32_t a = this->abcd[0];
uint32_t b = this->abcd[1];
uint32_t c = this->abcd[2];
uint32_t d = this->abcd[3];
uint32 X[16];
uint32_t X[16];
/* Convert the uint8 data to uint32 LE */
const uint32 *px = (const uint32 *)data;
/* Convert the uint8_t data to uint32_t LE */
const uint32_t *px = (const uint32_t *)data;
for (uint i = 0; i < 16; i++) {
X[i] = TO_LE32(*px);
px++;
@ -264,15 +264,15 @@ void Md5::Process(const uint8 *data /*[64]*/)
void Md5::Append(const void *data, const size_t nbytes)
{
const uint8 *p = (const uint8 *)data;
const uint8_t *p = (const uint8_t *)data;
size_t left = nbytes;
const size_t offset = (this->count[0] >> 3) & 63;
const uint32 nbits = (uint32)(nbytes << 3);
const uint32_t nbits = (uint32_t)(nbytes << 3);
if (nbytes <= 0) return;
/* Update the message length. */
this->count[1] += (uint32)(nbytes >> 29);
this->count[1] += (uint32_t)(nbytes >> 29);
this->count[0] += nbits;
if (this->count[0] < nbits) this->count[1]++;
@ -299,17 +299,17 @@ void Md5::Append(const void *data, const size_t nbytes)
void Md5::Finish(MD5Hash &digest)
{
static const uint8 pad[64] = {
static const uint8_t pad[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
uint8 data[8];
uint8_t data[8];
/* Save the length before padding. */
for (uint i = 0; i < 8; ++i) {
data[i] = (uint8)(this->count[i >> 2] >> ((i & 3) << 3));
data[i] = (uint8_t)(this->count[i >> 2] >> ((i & 3) << 3));
}
/* Pad to 56 bytes mod 64. */
@ -318,6 +318,6 @@ void Md5::Finish(MD5Hash &digest)
this->Append(data, 8);
for (uint i = 0; i < 16; ++i) {
digest[i] = (uint8)(this->abcd[i >> 2] >> ((i & 3) << 3));
digest[i] = (uint8_t)(this->abcd[i >> 2] >> ((i & 3) << 3));
}
}

@ -78,11 +78,11 @@ char *md5sumToString(char *buf, const char *last, const MD5Hash &md5sum);
struct Md5 {
private:
uint32 count[2]; ///< message length in bits, lsw first
uint32 abcd[4]; ///< digest buffer
uint8 buf[64]; ///< accumulate block
uint32_t count[2]; ///< message length in bits, lsw first
uint32_t abcd[4]; ///< digest buffer
uint8_t buf[64]; ///< accumulate block
void Process(const uint8 *data);
void Process(const uint8_t *data);
public:
Md5();

@ -179,7 +179,7 @@ typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
typedef WChar (*SQLEXREADFUNC)(SQUserPointer);
typedef char32_t (*SQLEXREADFUNC)(SQUserPointer);
typedef struct tagSQRegFunction{
const SQChar *name;

@ -1258,9 +1258,9 @@ struct BufState{
SQInteger size;
};
WChar buf_lexfeed(SQUserPointer file)
char32_t buf_lexfeed(SQUserPointer file)
{
/* Convert an UTF-8 character into a WChar */
/* Convert an UTF-8 character into a char32_t */
BufState *buf = (BufState *)file;
const char *p = &buf->buf[buf->ptr];
@ -1278,7 +1278,7 @@ WChar buf_lexfeed(SQUserPointer file)
buf->ptr += len;
/* Convert the character, and when definitely invalid, bail out as well. */
WChar c;
char32_t c;
if (Utf8Decode(&c, p) != len) return -1;
return c;

@ -26,7 +26,7 @@ SQLexer::~SQLexer()
_keywords->Release();
}
void SQLexer::APPEND_CHAR(WChar c)
void SQLexer::APPEND_CHAR(char32_t c)
{
char buf[4];
size_t chars = Utf8Encode(buf, c);
@ -101,7 +101,7 @@ NORETURN void SQLexer::Error(const SQChar *err)
void SQLexer::Next()
{
WChar t = _readf(_up);
char32_t t = _readf(_up);
if(t > MAX_CHAR) Error("Invalid character");
if(t != 0) {
_currdata = t;
@ -287,7 +287,7 @@ SQInteger SQLexer::GetIDType(SQChar *s)
}
SQInteger SQLexer::ReadString(WChar ndelim,bool verbatim)
SQInteger SQLexer::ReadString(char32_t ndelim,bool verbatim)
{
INIT_TEMP_STRING();
NEXT();

@ -11,7 +11,7 @@ struct SQLexer
const SQChar *Tok2Str(SQInteger tok);
private:
SQInteger GetIDType(SQChar *s);
SQInteger ReadString(WChar ndelim,bool verbatim);
SQInteger ReadString(char32_t ndelim,bool verbatim);
SQInteger ReadNumber();
void LexBlockComment();
SQInteger ReadID();
@ -19,7 +19,7 @@ private:
SQInteger _curtoken;
SQTable *_keywords;
void INIT_TEMP_STRING() { _longstr.resize(0); }
void APPEND_CHAR(WChar c);
void APPEND_CHAR(char32_t c);
void TERMINATE_BUFFER() { _longstr.push_back('\0'); }
public:
@ -32,7 +32,7 @@ public:
SQFloat _fvalue;
SQLEXREADFUNC _readf;
SQUserPointer _up;
WChar _currdata;
char32_t _currdata;
SQSharedState *_sharedstate;
sqvector<SQChar> _longstr;
CompilerErrorFunc _errfunc;

@ -100,7 +100,7 @@ ScriptInfo *AIInstance::FindLibrary(const std::string &library, int version)
* @param p2 p2 as given to DoCommandPInternal.
* @param cmd cmd as given to DoCommandPInternal.
*/
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
void CcAI(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
{
/*
* The company might not exist anymore. Check for this.

@ -65,8 +65,8 @@ int GetAircraftFlightLevel(T *v, bool takeoff = false);
/** Variables that are cached to improve performance and such. */
struct AircraftCache {
uint32 cached_max_range_sqr; ///< Cached squared maximum range.
uint16 cached_max_range; ///< Cached maximum range.
uint32_t cached_max_range_sqr; ///< Cached squared maximum range.
uint16_t cached_max_range; ///< Cached maximum range.
byte image_movement_state; ///< Cached image aircraft movement state
};
@ -74,7 +74,7 @@ struct AircraftCache {
* Aircraft, helicopters, rotors and their shadows belong to this class.
*/
struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
uint16 crashed_counter; ///< Timer for handling crash animations.
uint16_t crashed_counter; ///< Timer for handling crash animations.
byte pos; ///< Next desired position of the aircraft.
byte previous_pos; ///< Previous desired position of the aircraft.
StationID targetairport; ///< Airport to go to next.
@ -134,7 +134,7 @@ struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
* Get the range of this aircraft.
* @return Range in tiles or 0 if unlimited range.
*/
uint16 GetRange() const
uint16_t GetRange() const
{
return this->acache.cached_max_range;
}

@ -100,7 +100,7 @@ static const SpriteID _aircraft_sprite[] = {
};
template <>
bool IsValidImageIndex<VEH_AIRCRAFT>(uint8 image_index)
bool IsValidImageIndex<VEH_AIRCRAFT>(uint8_t image_index)
{
return image_index < lengthof(_aircraft_sprite);
}
@ -188,7 +188,7 @@ void Aircraft::GetImage(Direction direction, EngineImageType image_type, Vehicle
return;
}
uint8 spritenum = this->spritenum;
uint8_t spritenum = this->spritenum;
if (is_custom_sprite(spritenum)) {
GetCustomVehicleSprite(this, direction, image_type, result);
@ -218,7 +218,7 @@ void GetRotorImage(const Aircraft *v, EngineImageType image_type, VehicleSpriteS
static void GetAircraftIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
{
const Engine *e = Engine::Get(engine);
uint8 spritenum = e->u.air.image_index;
uint8_t spritenum = e->u.air.image_index;
if (is_custom_sprite(spritenum)) {
GetCustomVehicleIcon(engine, DIR_W, image_type, result);
@ -1270,7 +1270,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
}
if (v->crashed_counter < 650) {
uint32 r;
uint32_t r;
if (Chance16R(1, 32, r)) {
static const DirDiff delta[] = {
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
@ -1314,8 +1314,8 @@ static bool HandleCrashedAircraft(Aircraft *v)
static void HandleAircraftSmoke(Aircraft *v, bool mode)
{
static const struct {
int8 x;
int8 y;
int8_t x;
int8_t y;
} smoke_pos[] = {
{ 5, 5 },
{ 6, 0 },
@ -1457,7 +1457,7 @@ static void MaybeCrashAirplane(Aircraft *v)
Station *st = Station::Get(v->targetairport);
uint32 prob;
uint32_t prob;
if ((st->airport.GetFTA()->flags & AirportFTAClass::SHORT_STRIP) &&
(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
!_cheats.no_jetcrash.value) {
@ -1468,7 +1468,7 @@ static void MaybeCrashAirplane(Aircraft *v)
}
if (_settings_game.vehicle.improved_breakdowns && v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_AIRCRAFT_EM_LANDING) {
/* Airplanes that are attempting an emergency landing have a 2% chance to crash */
prob = std::max<uint32>(prob, 0x10000 / 50);
prob = std::max<uint32_t>(prob, 0x10000 / 50);
}
if (GB(Random(), 0, 22) > prob) return;
@ -1769,8 +1769,8 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
/* save speed before, since if AirportHasBlock is false, it resets them to 0
* we don't want that for plane in air
* hack for speed thingie */
uint16 tcur_speed = v->cur_speed;
uint16 tsubspeed = v->subspeed;
uint16_t tcur_speed = v->cur_speed;
uint16_t tsubspeed = v->subspeed;
if (!AirportHasBlock(v, current, apc)) {
v->state = landingtype; // LANDING / HELILANDING
if (v->state == HELILANDING) SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);
@ -1954,7 +1954,7 @@ static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const Ai
/* same block, then of course we can move */
if (apc->layout[current_pos->position].block != next->block) {
const Station *st = Station::Get(v->targetairport);
uint64 airport_flags = next->block;
uint64_t airport_flags = next->block;
/* check additional possible extra blocks */
if (current_pos != reference && current_pos->block != NOTHING_block) {
@ -1984,7 +1984,7 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
/* if the next position is in another block, check it and wait until it is free */
if ((apc->layout[current_pos->position].block & next->block) != next->block) {
uint64 airport_flags = next->block;
uint64_t airport_flags = next->block;
/* search for all all elements in the list with the same state, and blocks != N
* this means more blocks should be checked/set */
const AirportFTA *current = current_pos;
@ -2021,7 +2021,7 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
*/
struct MovementTerminalMapping {
AirportMovementStates state; ///< Aircraft movement state when going to this terminal.
uint64 airport_flag; ///< Bitmask in the airport flags that need to be free for this terminal.
uint64_t airport_flag; ///< Bitmask in the airport flags that need to be free for this terminal.
};
/** A list of all valid terminals and their associated blocks. */
@ -2229,7 +2229,7 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
bool Aircraft::Tick()
{
DEBUG_UPDATESTATECHECKSUM("Aircraft::Tick: v: %u, x: %d, y: %d", this->index, this->x_pos, this->y_pos);
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
UpdateStateChecksum((((uint64_t) this->x_pos) << 32) | this->y_pos);
if (!this->IsNormalAircraft()) return true;
this->tick_counter++;

@ -65,7 +65,7 @@ AIRPORT_GENERIC(dummy, nullptr, 0, AirportFTAClass::ALL, 0)
#include "table/airport_defaults.h"
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA);
static uint16_t AirportGetNofElements(const AirportFTAbuildup *apFA);
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA);
@ -147,9 +147,9 @@ AirportFTAClass::~AirportFTAClass()
* Since it is actually just a big array of AirportFTA types, we only
* know one element from the other by differing 'position' identifiers
*/
static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA)
static uint16_t AirportGetNofElements(const AirportFTAbuildup *apFA)
{
uint16 nofelements = 0;
uint16_t nofelements = 0;
int temp = apFA[0].position;
for (uint i = 0; i < MAX_ELEMENTS; i++) {
@ -171,7 +171,7 @@ static uint16 AirportGetNofElements(const AirportFTAbuildup *apFA)
static AirportFTA *AirportBuildAutomata(uint nofelements, const AirportFTAbuildup *apFA)
{
AirportFTA *FAutomata = MallocT<AirportFTA>(nofelements);
uint16 internalcounter = 0;
uint16_t internalcounter = 0;
for (uint i = 0; i < nofelements; i++) {
AirportFTA *current = &FAutomata[i];

@ -85,7 +85,7 @@ enum AirportMovementStates {
};
/** Movement Blocks on Airports blocks (eg_airport_flags). */
static const uint64
static const uint64_t
TERM1_block = 1ULL << 0, ///< Block belonging to terminal 1.
TERM2_block = 1ULL << 1, ///< Block belonging to terminal 2.
TERM3_block = 1ULL << 2, ///< Block belonging to terminal 3.
@ -129,9 +129,9 @@ static const uint64
/** A single location on an airport where aircraft can move to. */
struct AirportMovingData {
int16 x; ///< x-coordinate of the destination.
int16 y; ///< y-coordinate of the destination.
uint16 flag; ///< special flags when moving towards the destination.
int16_t x; ///< x-coordinate of the destination.
int16_t y; ///< y-coordinate of the destination.
uint16_t flag; ///< special flags when moving towards the destination.
Direction direction; ///< Direction to turn the aircraft after reaching the destination.
};
@ -189,7 +189,7 @@ DECLARE_ENUM_AS_BIT_SET(AirportFTAClass::Flags)
/** Internal structure used in openttd - Finite sTate mAchine --> FTA */
struct AirportFTA {
AirportFTA *next; ///< possible extra movement choices from this position
uint64 block; ///< 64 bit blocks (st->airport.flags), should be enough for the most complex airports
uint64_t block; ///< 64 bit blocks (st->airport.flags), should be enough for the most complex airports
byte position; ///< the position that an airplane is at
byte next_position; ///< next position from this position
byte heading; ///< heading (current orders), guiding an airplane to its target on an airport

@ -42,7 +42,7 @@ static void ShowBuildAirportPicker(Window *parent);
SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout);
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
{
if (result.Failed()) return;
@ -57,10 +57,10 @@ void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32
static void PlaceAirport(TileIndex tile)
{
if (_selected_airport_index == -1) return;
uint32 p2 = _ctrl_pressed;
uint32_t p2 = _ctrl_pressed;
SB(p2, 16, 16, INVALID_STATION); // no station to join
uint32 p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
uint32_t p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
p1 |= _selected_airport_layout << 8;
CommandContainer cmdcont = NewCommandContainerBasic(tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport);
ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));

@ -39,10 +39,10 @@ void DeleteAnimatedTile(TileIndex tile)
static void UpdateAnimatedTileSpeed(TileIndex tile, AnimatedTileInfo &info)
{
extern uint8 GetAnimatedTileSpeed_Town(TileIndex tile);
extern uint8 GetAnimatedTileSpeed_Station(TileIndex tile);
extern uint8 GetAnimatedTileSpeed_Industry(TileIndex tile);
extern uint8 GetNewObjectTileAnimationSpeed(TileIndex tile);
extern uint8_t GetAnimatedTileSpeed_Town(TileIndex tile);
extern uint8_t GetAnimatedTileSpeed_Station(TileIndex tile);
extern uint8_t GetAnimatedTileSpeed_Industry(TileIndex tile);
extern uint8_t GetNewObjectTileAnimationSpeed(TileIndex tile);
switch (GetTileType(tile)) {
case MP_HOUSE:
@ -101,8 +101,8 @@ void AnimateAnimatedTiles()
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
const uint32 ticks = (uint) _scaled_tick_counter;
const uint8 max_speed = (ticks == 0) ? 32 : FindFirstBit(ticks);
const uint32_t ticks = (uint) _scaled_tick_counter;
const uint8_t max_speed = (ticks == 0) ? 32 : FindFirstBit(ticks);
auto iter = _animated_tiles.begin();
while (iter != _animated_tiles.end()) {

@ -14,7 +14,7 @@
#include "3rdparty/cpp-btree/btree_map.h"
struct AnimatedTileInfo {
uint8 speed = 0;
uint8_t speed = 0;
bool pending_deletion = false;
};

@ -44,7 +44,7 @@ static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle
return INVALID_ENGINE;
}
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, index, 0, front_type, front);
uint16_t callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, index, 0, front_type, front);
if (callback == CALLBACK_FAILED) return INVALID_ENGINE;
if (front_engine->GetGRF()->grf_version < 8) {
@ -143,7 +143,7 @@ void GetArticulatedPartsEngineIDs(EngineID engine_type, bool purchase_window, st
* @param cargo_type returns the default cargo type, if needed
* @return capacity
*/
static inline uint16 GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
static inline uint16_t GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
{
const Engine *e = Engine::Get(engine);
CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
@ -183,7 +183,7 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
const Engine *e = Engine::Get(engine);
CargoID cargo_type;
uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;
if (!e->IsArticulatedCallbackVehicleType()) return capacity;
@ -212,7 +212,7 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
const Engine *e = Engine::Get(engine);
CargoID cargo_type;
uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
if (!e->IsArticulatedCallbackVehicleType()) return cargoes;

@ -15,7 +15,7 @@
#include "engine_type.h"
#include "group_type.h"
typedef uint16 EngineRenewID;
typedef uint16_t EngineRenewID;
/**
* Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is

@ -674,7 +674,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
if (old_head->type == VEH_TRAIN) {
/* Store the length of the old vehicle chain, rounded up to whole tiles */
uint16 old_total_length = CeilDiv(Train::From(old_head)->gcache.cached_total_length, TILE_SIZE) * TILE_SIZE;
uint16_t old_total_length = CeilDiv(Train::From(old_head)->gcache.cached_total_length, TILE_SIZE) * TILE_SIZE;
int num_units = 0; ///< Number of units in the chain
for (Train *w = Train::From(old_head); w != nullptr; w = w->GetNextUnit()) num_units++;
@ -895,7 +895,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
Vehicle *v = Vehicle::GetIfValid(p1);
if (v == nullptr) return CMD_ERROR;
@ -990,7 +990,7 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
Company *c = Company::GetIfValid(_current_company);
if (c == nullptr) return CMD_ERROR;

@ -30,7 +30,7 @@
#include "safeguards.h"
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group);
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
{

@ -17,20 +17,20 @@
/** Various front vehicle properties that are preserved when autoreplacing, using order-backup or switching front engines within a consist. */
struct BaseConsist {
TinyString name; ///< Name of vehicle
TinyString name; ///< Name of vehicle
/* Used for timetabling. */
uint32 current_order_time; ///< How many ticks have passed since this order started.
int32 lateness_counter; ///< How many ticks late (or early if negative) this vehicle is.
DateTicksScaled timetable_start; ///< When the vehicle is supposed to start the timetable.
uint32_t current_order_time; ///< How many ticks have passed since this order started.
int32_t lateness_counter; ///< How many ticks late (or early if negative) this vehicle is.
DateTicksScaled timetable_start; ///< When the vehicle is supposed to start the timetable.
uint16 service_interval; ///< The interval for (automatic) servicing; either in days or %.
uint16_t service_interval; ///< The interval for (automatic) servicing; either in days or %.
VehicleOrderID cur_real_order_index;///< The index to the current real (non-implicit) order
VehicleOrderID cur_implicit_order_index;///< The index to the current implicit order
VehicleOrderID cur_timetable_order_index;///< The index to the current real (non-implicit) order used for timetable updates
VehicleOrderID cur_real_order_index; ///< The index to the current real (non-implicit) order
VehicleOrderID cur_implicit_order_index; ///< The index to the current implicit order
VehicleOrderID cur_timetable_order_index; ///< The index to the current real (non-implicit) order used for timetable updates
uint32 vehicle_flags; ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
uint32_t vehicle_flags; ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
virtual ~BaseConsist() = default;

@ -61,8 +61,8 @@ struct BaseSet {
std::string name; ///< The name of the base set
std::string url; ///< URL for information about the base set
TranslatedStrings description; ///< Description of the base set
uint32 shortname; ///< Four letter short variant of the name
uint32 version; ///< The version of this base set
uint32_t shortname; ///< Four letter short variant of the name
uint32_t version; ///< The version of this base set
bool fallback; ///< This set is a fallback set, i.e. it should be used only as last resort
MD5File files[NUM_FILES]; ///< All files part of this set

@ -66,7 +66,7 @@ bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(const IniFile &ini,
fetch_metadata("shortname");
for (uint i = 0; (*item->value)[i] != '\0' && i < 4; i++) {
this->shortname |= ((uint8)(*item->value)[i]) << (i * 8);
this->shortname |= ((uint8_t)(*item->value)[i]) << (i * 8);
}
fetch_metadata("version");

@ -24,20 +24,20 @@ extern StationPool _station_pool;
struct StationSpecList {
const StationSpec *spec;
uint32 grfid; ///< GRF ID of this custom station
uint16 localidx; ///< Station ID within GRF of station
uint32_t grfid; ///< GRF ID of this custom station
uint16_t localidx; ///< Station ID within GRF of station
};
struct RoadStopSpecList {
const RoadStopSpec *spec;
uint32 grfid; ///< GRF ID of this custom road stop
uint16 localidx; ///< Station ID within GRF of road stop
uint32_t grfid; ///< GRF ID of this custom road stop
uint16_t localidx; ///< Station ID within GRF of road stop
};
struct RoadStopTileData {
TileIndex tile;
uint8 random_bits;
uint8 animation_frame;
uint8_t random_bits;
uint8_t animation_frame;
};
/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
@ -82,10 +82,10 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
Date build_date; ///< Date of construction
uint16 random_bits; ///< Random bits assigned to this station
uint16_t random_bits; ///< Random bits assigned to this station
byte waiting_triggers; ///< Waiting triggers (NewGRF) for this station
uint8 cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
uint8 cached_roadstop_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
uint8_t cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
uint8_t cached_roadstop_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing should happen.
CargoTypes cached_cargo_triggers; ///< NOSAVE: Combined cargo trigger bitmask
CargoTypes cached_roadstop_cargo_triggers; ///< NOSAVE: Combined cargo trigger bitmask for road stops
@ -121,7 +121,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
* @param available will return false if ever the variable asked for does not exist
* @return the value stored in the corresponding variable
*/
virtual uint32 GetNewGRFVariable(const struct ResolverObject &object, uint16 variable, byte parameter, bool *available) const = 0;
virtual uint32_t GetNewGRFVariable(const struct ResolverObject &object, uint16_t variable, byte parameter, bool *available) const = 0;
/**
* Update the coordinated of the sign (as shown in the viewport).

@ -33,15 +33,15 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
const BlitterSpriteFlags sprite_flags = src->flags;
const Colour *src_px = (const Colour *)(src->data + src->offset[zoom][0]);
const uint16 *src_n = (const uint16 *)(src->data + src->offset[zoom][1]);
const uint16_t *src_n = (const uint16_t *)(src->data + src->offset[zoom][1]);
for (uint i = bp->skip_top; i != 0; i--) {
src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
src_n = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
src_px = (const Colour *)((const byte *)src_px + *(const uint32_t *)src_px);
src_n = (const uint16_t *)((const byte *)src_n + *(const uint32_t *)src_n);
}
Colour *dst = (Colour *)bp->dst + bp->top * bp->pitch + bp->left;
uint16 *anim = this->anim_buf + this->ScreenToAnimOffset((uint32 *)bp->dst) + bp->top * this->anim_buf_pitch + bp->left;
uint16_t *anim = this->anim_buf + this->ScreenToAnimOffset((uint32_t *)bp->dst) + bp->top * this->anim_buf_pitch + bp->left;
const byte *remap = bp->remap; // store so we don't have to access it via bp every time
const int width = bp->width;
@ -52,12 +52,12 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
for (int y = 0; y < height; y++) {
Colour *dst_ln = dst + pitch;
uint16 *anim_ln = anim + anim_pitch;
uint16_t *anim_ln = anim + anim_pitch;
const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32_t *)src_px);
src_px++;
const uint16 *src_n_ln = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
const uint16_t *src_n_ln = (const uint16_t *)((const byte *)src_n + *(const uint32_t *)src_n);
src_n += 2;
Colour *dst_end = dst;
@ -132,7 +132,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
} else {
uint r = remap[GB(m, 0, 8)];
if (r != 0) {
uint8 brightness = GB(m, 8, 8);
uint8_t brightness = GB(m, 8, 8);
if (mode == BM_COLOUR_REMAP_WITH_BRIGHTNESS) {
brightness = Clamp(brightness + bp->brightness_adjust, 0, 255);
SB(m, 8, 8, brightness);
@ -158,7 +158,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
uint r = remap[GB(m, 0, 8)];
*anim = 0;
if (r != 0) {
uint8 brightness = GB(m, 8, 8);
uint8_t brightness = GB(m, 8, 8);
if (mode == BM_COLOUR_REMAP_WITH_BRIGHTNESS) brightness = Clamp(brightness + bp->brightness_adjust, 0, 255);
*dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), brightness), src_px->a, *dst);
}
@ -176,7 +176,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
do {
uint m = *src_n;
if (m == 0) {
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
uint8_t g = MakeDark(src_px->r, src_px->g, src_px->b);
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
*anim = 0;
} else {
@ -194,7 +194,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
uint m = *src_n;
if (m == 0) {
if (src_px->a != 0) {
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
uint8_t g = MakeDark(src_px->r, src_px->g, src_px->b);
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
*anim = 0;
}
@ -273,7 +273,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
} else if (src_px->a == 255) {
do {
/* Compiler assumes pointer aliasing, can't optimise this on its own */
uint16 mv = *src_n;
uint16_t mv = *src_n;
uint m = GB(mv, 0, 8);
/* Above PALETTE_ANIM_START is palette animation */
if (m >= PALETTE_ANIM_START) {
@ -293,7 +293,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
uint m = GB(*src_n, 0, 8);
*anim++ = 0;
if (m >= PALETTE_ANIM_START) {
uint8 brightness = GB(*src_n, 8, 8);
uint8_t brightness = GB(*src_n, 8, 8);
if (mode == BM_NORMAL_WITH_BRIGHTNESS) brightness = Clamp(brightness + bp->brightness_adjust, 0, 255);
*dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(m), brightness), src_px->a, *dst);
} else {
@ -373,7 +373,7 @@ void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height,
}
Colour *udst = (Colour *)dst;
uint16 *anim = this->anim_buf + this->ScreenToAnimOffset((uint32 *)dst);
uint16_t *anim = this->anim_buf + this->ScreenToAnimOffset((uint32_t *)dst);
if (pal == PALETTE_TO_TRANSPARENT) {
do {
@ -405,25 +405,25 @@ void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height,
DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal);
}
void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8 colour)
void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8_t colour)
{
*((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour);
/* Set the colour in the anim-buffer too, if we are rendering to the screen */
if (_screen_disable_anim) return;
this->anim_buf[this->ScreenToAnimOffset((uint32 *)video) + x + y * this->anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8);
this->anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8);
}
void Blitter_32bppAnim::SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32)
void Blitter_32bppAnim::SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32)
{
*((Colour *)video + x + y * _screen.pitch) = colour32;
/* Set the colour in the anim-buffer too, if we are rendering to the screen */
if (_screen_disable_anim) return;
this->anim_buf[this->ScreenToAnimOffset((uint32 *)video) + x + y * this->anim_buf_pitch] = 0;
this->anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->anim_buf_pitch] = 0;
}
void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash)
{
const Colour c = LookupColourInPalette(colour);
@ -432,8 +432,8 @@ void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int
*((Colour *)video + x + y * _screen.pitch) = c;
});
} else {
uint16 * const offset_anim_buf = this->anim_buf + this->ScreenToAnimOffset((uint32 *)video);
const uint16 anim_colour = colour | (DEFAULT_BRIGHTNESS << 8);
uint16_t * const offset_anim_buf = this->anim_buf + this->ScreenToAnimOffset((uint32_t *)video);
const uint16_t anim_colour = colour | (DEFAULT_BRIGHTNESS << 8);
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](int x, int y) {
*((Colour *)video + x + y * _screen.pitch) = c;
offset_anim_buf[x + y * this->anim_buf_pitch] = anim_colour;
@ -441,7 +441,7 @@ void Blitter_32bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int
}
}
void Blitter_32bppAnim::SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch)
void Blitter_32bppAnim::SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch)
{
Colour *dst = (Colour *)video + x + y * _screen.pitch;
@ -457,7 +457,7 @@ void Blitter_32bppAnim::SetRect(void *video, int x, int y, const uint8 *colours,
colours += pitch - width;
} while (--lines);
} else {
uint16 *dstanim = (uint16 *)(&this->anim_buf[this->ScreenToAnimOffset((uint32 *)video) + x + y * this->anim_buf_pitch]);
uint16_t *dstanim = (uint16_t *)(&this->anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->anim_buf_pitch]);
do {
uint w = width;
do {
@ -474,21 +474,21 @@ void Blitter_32bppAnim::SetRect(void *video, int x, int y, const uint8 *colours,
}
}
void Blitter_32bppAnim::SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch)
void Blitter_32bppAnim::SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch)
{
uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
uint32_t *dst = (uint32_t *)video + x + y * _screen.pitch;
if (_screen_disable_anim) {
do {
memcpy(dst, colours, width * sizeof(uint32));
memcpy(dst, colours, width * sizeof(uint32_t));
dst += _screen.pitch;
colours += pitch;
} while (--lines);
} else {
uint16 *dstanim = (uint16 *)(&this->anim_buf[this->ScreenToAnimOffset((uint32 *)video) + x + y * this->anim_buf_pitch]);
uint16_t *dstanim = (uint16_t *)(&this->anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->anim_buf_pitch]);
do {
memcpy(dst, colours, width * sizeof(uint32));
memset(dstanim, 0, width * sizeof(uint16));
memcpy(dst, colours, width * sizeof(uint32_t));
memset(dstanim, 0, width * sizeof(uint16_t));
dst += _screen.pitch;
dstanim += this->anim_buf_pitch;
colours += pitch;
@ -496,7 +496,7 @@ void Blitter_32bppAnim::SetRect32(void *video, int x, int y, const uint32 *colou
}
}
void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colour)
void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8_t colour)
{
if (_screen_disable_anim) {
/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */
@ -505,11 +505,11 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colou
}
Colour colour32 = LookupColourInPalette(colour);
uint16 *anim_line = this->ScreenToAnimOffset((uint32 *)video) + this->anim_buf;
uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->anim_buf;
do {
Colour *dst = (Colour *)video;
uint16 *anim = anim_line;
uint16_t *anim = anim_line;
for (int i = width; i > 0; i--) {
*dst = colour32;
@ -518,12 +518,12 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colou
dst++;
anim++;
}
video = (uint32 *)video + _screen.pitch;
video = (uint32_t *)video + _screen.pitch;
anim_line += this->anim_buf_pitch;
} while (--height);
}
void Blitter_32bppAnim::DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour)
void Blitter_32bppAnim::DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour)
{
this->Blitter_32bppAnim::DrawRect((Colour *)video + x + y * _screen.pitch, width, height, colour);
}
@ -531,22 +531,22 @@ void Blitter_32bppAnim::DrawRectAt(void *video, int x, int y, int width, int hei
void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, int height)
{
assert(!_screen_disable_anim);
assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
Colour *dst = (Colour *)video;
const uint32 *usrc = (const uint32 *)src;
uint16 *anim_line = this->ScreenToAnimOffset((uint32 *)video) + this->anim_buf;
const uint32_t *usrc = (const uint32_t *)src;
uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->anim_buf;
for (; height > 0; height--) {
/* We need to keep those for palette animation. */
Colour *dst_pal = dst;
uint16 *anim_pal = anim_line;
uint16_t *anim_pal = anim_line;
memcpy(static_cast<void *>(dst), usrc, width * sizeof(uint32));
memcpy(static_cast<void *>(dst), usrc, width * sizeof(uint32_t));
usrc += width;
dst += _screen.pitch;
/* Copy back the anim-buffer */
memcpy(anim_line, usrc, width * sizeof(uint16));
usrc = (const uint32 *)&((const uint16 *)usrc)[width];
memcpy(anim_line, usrc, width * sizeof(uint16_t));
usrc = (const uint32_t *)&((const uint16_t *)usrc)[width];
anim_line += this->anim_buf_pitch;
/* Okay, it is *very* likely that the image we stored is using
@ -571,21 +571,21 @@ void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width,
void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, int height)
{
assert(!_screen_disable_anim);
assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint32 *udst = (uint32 *)dst;
const uint32 *src = (const uint32 *)video;
assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint32_t *udst = (uint32_t *)dst;
const uint32_t *src = (const uint32_t *)video;
if (this->anim_buf == nullptr) return;
const uint16 *anim_line = this->ScreenToAnimOffset((const uint32 *)video) + this->anim_buf;
const uint16_t *anim_line = this->ScreenToAnimOffset((const uint32_t *)video) + this->anim_buf;
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint32));
memcpy(udst, src, width * sizeof(uint32_t));
src += _screen.pitch;
udst += width;
/* Copy the anim-buffer */
memcpy(udst, anim_line, width * sizeof(uint16));
udst = (uint32 *)&((uint16 *)udst)[width];
memcpy(udst, anim_line, width * sizeof(uint16_t));
udst = (uint32_t *)&((uint16_t *)udst)[width];
anim_line += this->anim_buf_pitch;
}
}
@ -593,8 +593,8 @@ void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, in
void Blitter_32bppAnim::ScrollBuffer(void *video, int left, int top, int width, int height, int scroll_x, int scroll_y)
{
assert(!_screen_disable_anim);
assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint16 *dst, *src;
assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint16_t *dst, *src;
/* We need to scroll the anim-buffer too */
if (scroll_y > 0) {
@ -611,7 +611,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int left, int top, int width,
uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
uint th = height - scroll_y;
for (; th > 0; th--) {
memcpy(dst, src, tw * sizeof(uint16));
memcpy(dst, src, tw * sizeof(uint16_t));
src -= this->anim_buf_pitch;
dst -= this->anim_buf_pitch;
}
@ -632,7 +632,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int left, int top, int width,
uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
uint th = height + scroll_y;
for (; th > 0; th--) {
memmove(dst, src, tw * sizeof(uint16));
memmove(dst, src, tw * sizeof(uint16_t));
src += this->anim_buf_pitch;
dst += this->anim_buf_pitch;
}
@ -643,7 +643,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int left, int top, int width,
size_t Blitter_32bppAnim::BufferSize(uint width, uint height)
{
return (sizeof(uint32) + sizeof(uint16)) * width * height;
return (sizeof(uint32_t) + sizeof(uint16_t)) * width * height;
}
void Blitter_32bppAnim::PaletteAnimate(const Palette &palette)
@ -656,7 +656,7 @@ void Blitter_32bppAnim::PaletteAnimate(const Palette &palette)
* Especially when going between toyland and non-toyland. */
assert(this->palette.first_dirty == PALETTE_ANIM_START || this->palette.first_dirty == 0);
const uint16 *anim = this->anim_buf;
const uint16_t *anim = this->anim_buf;
Colour *dst = (Colour *)_screen.dst_ptr;
/* Let's walk the anim buffer and try to find the pixels */
@ -665,8 +665,8 @@ void Blitter_32bppAnim::PaletteAnimate(const Palette &palette)
const int anim_pitch_offset = this->anim_buf_pitch - width;
for (int y = this->anim_buf_height; y != 0 ; y--) {
for (int x = width; x != 0 ; x--) {
uint16 value = *anim;
uint8 colour = GB(value, 0, 8);
uint16_t value = *anim;
uint8_t colour = GB(value, 0, 8);
if (colour >= PALETTE_ANIM_START) {
/* Update this pixel */
*dst = this->AdjustBrightness(LookupColourInPalette(colour), GB(value, 8, 8));
@ -695,9 +695,9 @@ void Blitter_32bppAnim::PostResize()
this->anim_buf_width = _screen.width;
this->anim_buf_height = _screen.height;
this->anim_buf_pitch = (_screen.width + 7) & ~7;
this->anim_alloc = CallocT<uint16>(this->anim_buf_pitch * this->anim_buf_height + 8);
this->anim_alloc = CallocT<uint16_t>(this->anim_buf_pitch * this->anim_buf_height + 8);
/* align buffer to next 16 byte boundary */
this->anim_buf = reinterpret_cast<uint16 *>((reinterpret_cast<uintptr_t>(this->anim_alloc) + 0xF) & (~0xF));
this->anim_buf = reinterpret_cast<uint16_t *>((reinterpret_cast<uintptr_t>(this->anim_alloc) + 0xF) & (~0xF));
}
}

@ -15,7 +15,7 @@
/** The optimised 32 bpp blitter with palette animation. */
class Blitter_32bppAnim : public Blitter_32bppOptimized {
protected:
uint16 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
uint16_t *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
void *anim_alloc; ///< The raw allocated buffer, not necessarily aligned correctly
int anim_buf_width; ///< The width of the animation buffer.
int anim_buf_pitch; ///< The pitch of the animation buffer (width rounded up to 16 byte boundary).
@ -37,13 +37,13 @@ public:
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
void SetPixel(void *video, int x, int y, uint8 colour) override;
void SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch) override;
void SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour) override;
void SetPixel(void *video, int x, int y, uint8_t colour) override;
void SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override;
void SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch) override;
void SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8_t colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void ScrollBuffer(void *video, int left, int top, int width, int height, int scroll_x, int scroll_y) override;
@ -62,9 +62,9 @@ public:
return this->palette.palette[index];
}
inline int ScreenToAnimOffset(const uint32 *video)
inline int ScreenToAnimOffset(const uint32_t *video)
{
int raw_offset = video - (const uint32 *)_screen.dst_ptr;
int raw_offset = video - (const uint32_t *)_screen.dst_ptr;
if (_screen.pitch == this->anim_buf_pitch) return raw_offset;
int lines = raw_offset / _screen.pitch;
int across = raw_offset % _screen.pitch;

@ -30,7 +30,7 @@ void Blitter_32bppSSE2_Anim::PaletteAnimate(const Palette &palette)
* Especially when going between toyland and non-toyland. */
assert(this->palette.first_dirty == PALETTE_ANIM_START || this->palette.first_dirty == 0);
const uint16 *anim = this->anim_buf;
const uint16_t *anim = this->anim_buf;
Colour *dst = (Colour *)_screen.dst_ptr;
bool screen_dirty = false;
@ -44,7 +44,7 @@ void Blitter_32bppSSE2_Anim::PaletteAnimate(const Palette &palette)
__m128i colour_mask = _mm_set1_epi16(0xFF);
for (int y = this->anim_buf_height; y != 0 ; y--) {
Colour *next_dst_ln = dst + screen_pitch;
const uint16 *next_anim_ln = anim + anim_pitch;
const uint16_t *next_anim_ln = anim + anim_pitch;
int x = width;
while (x > 0) {
__m128i data = _mm_load_si128((const __m128i *) anim);
@ -61,7 +61,7 @@ void Blitter_32bppSSE2_Anim::PaletteAnimate(const Palette &palette)
/* slow path: < 8 pixels left or unexpected brightnesses */
for (int z = std::min<int>(x, 8); z != 0 ; z--) {
int value = _mm_extract_epi16(data, 0);
uint8 colour = GB(value, 0, 8);
uint8_t colour = GB(value, 0, 8);
if (colour >= PALETTE_ANIM_START) {
/* Update this pixel */
*dst = AdjustBrightneSSE(LookupColourInPalette(colour), GB(value, 8, 8));

@ -35,7 +35,7 @@ inline void Blitter_32bppSSE4_Anim::Draw(const Blitter::BlitterParams *bp, ZoomL
{
const byte * const remap = bp->remap;
Colour *dst_line = (Colour *) bp->dst + bp->top * bp->pitch + bp->left;
uint16 *anim_line = this->anim_buf + this->ScreenToAnimOffset((uint32 *)bp->dst) + bp->top * this->anim_buf_pitch + bp->left;
uint16_t *anim_line = this->anim_buf + this->ScreenToAnimOffset((uint32_t *)bp->dst) + bp->top * this->anim_buf_pitch + bp->left;
int effective_width = bp->width;
/* Find where to start reading in the source sprite. */
@ -60,7 +60,7 @@ inline void Blitter_32bppSSE4_Anim::Draw(const Blitter::BlitterParams *bp, ZoomL
Colour *dst = dst_line;
const Colour *src = src_rgba_line + META_LENGTH;
if (mode != BM_TRANSPARENT) src_mv = src_mv_line;
uint16 *anim = anim_line;
uint16_t *anim = anim_line;
if (read_mode == RM_WITH_MARGIN) {
assert(bt_last == BT_NONE); // or you must ensure block type is preserved
@ -82,7 +82,7 @@ inline void Blitter_32bppSSE4_Anim::Draw(const Blitter::BlitterParams *bp, ZoomL
for (uint x = (uint) effective_width; x > 0; x--) {
if (src->a) {
if (animated) {
*anim = *(const uint16*) src_mv;
*anim = *(const uint16_t*) src_mv;
*dst = (src_mv->m >= PALETTE_ANIM_START) ? AdjustBrightneSSE(this->LookupColourInPalette(src_mv->m), src_mv->v) : src->data;
} else {
*anim = 0;
@ -98,7 +98,7 @@ inline void Blitter_32bppSSE4_Anim::Draw(const Blitter::BlitterParams *bp, ZoomL
}
for (uint x = (uint) effective_width/2; x != 0; x--) {
uint32 mvX2 = *((uint32 *) const_cast<MapValue *>(src_mv));
uint32_t mvX2 = *((uint32_t *) const_cast<MapValue *>(src_mv));
__m128i srcABCD = _mm_loadl_epi64((const __m128i*) src);
__m128i dstABCD = _mm_loadl_epi64((__m128i*) dst);
@ -118,26 +118,26 @@ inline void Blitter_32bppSSE4_Anim::Draw(const Blitter::BlitterParams *bp, ZoomL
/* Update anim buffer. */
const byte a0 = src[0].a;
const byte a1 = src[1].a;
uint32 anim01 = 0;
uint32_t anim01 = 0;
if (a0 == 255) {
if (a1 == 255) {
*(uint32*) anim = mvX2;
*(uint32_t*) anim = mvX2;
goto bmno_full_opacity;
}
anim01 = (uint16) mvX2;
anim01 = (uint16_t) mvX2;
} else if (a0 == 0) {
if (a1 == 0) {
goto bmno_full_transparency;
} else {
if (a1 == 255) anim[1] = (uint16) (mvX2 >> 16);
if (a1 == 255) anim[1] = (uint16_t) (mvX2 >> 16);
goto bmno_alpha_blend;
}
}
if (a1 > 0) {
if (a1 == 255) anim01 |= mvX2 & 0xFFFF0000;
*(uint32*) anim = anim01;
*(uint32_t*) anim = anim01;
} else {
anim[0] = (uint16) anim01;
anim[0] = (uint16_t) anim01;
}
} else {
if (src[0].a) anim[0] = 0;
@ -160,7 +160,7 @@ bmno_full_transparency:
if (src->a == 0) {
/* Complete transparency. */
} else if (src->a == 255) {
*anim = *(const uint16*) src_mv;
*anim = *(const uint16_t*) src_mv;
*dst = (src_mv->m >= PALETTE_ANIM_START) ? AdjustBrightneSSE(LookupColourInPalette(src_mv->m), src_mv->v) : *src;
} else {
*anim = 0;
@ -180,7 +180,7 @@ bmno_full_transparency:
case BM_COLOUR_REMAP:
for (uint x = (uint) effective_width / 2; x != 0; x--) {
uint32 mvX2 = *((uint32 *) const_cast<MapValue *>(src_mv));
uint32_t mvX2 = *((uint32_t *) const_cast<MapValue *>(src_mv));
__m128i srcABCD = _mm_loadl_epi64((const __m128i*) src);
__m128i dstABCD = _mm_loadl_epi64((__m128i*) dst);
@ -202,14 +202,14 @@ bmno_full_transparency:
m_colour = m != 0 ? m_colour : srcm; \
}
#ifdef POINTER_IS_64BIT
uint64 srcs = _mm_cvtsi128_si64(srcABCD);
uint64 dsts;
uint64_t srcs = _mm_cvtsi128_si64(srcABCD);
uint64_t dsts;
if (animated) dsts = _mm_cvtsi128_si64(dstABCD);
uint64 remapped_src = 0;
uint64_t remapped_src = 0;
CMOV_REMAP(c0, animated ? dsts : 0, srcs, mvX2);
remapped_src = c0.data;
CMOV_REMAP(c1, animated ? dsts >> 32 : 0, srcs >> 32, mvX2 >> 16);
remapped_src |= (uint64) c1.data << 32;
remapped_src |= (uint64_t) c1.data << 32;
srcABCD = _mm_cvtsi64_si128(remapped_src);
#else
Colour remapped_src[2];
@ -227,11 +227,11 @@ bmno_full_transparency:
if (animated) {
const byte a0 = src[0].a;
const byte a1 = src[1].a;
uint32 anim01 = mvX2 & 0xFF00FF00;
uint32_t anim01 = mvX2 & 0xFF00FF00;
if (a0 == 255) {
anim01 |= r0;
if (a1 == 255) {
*(uint32*) anim = anim01 | (r1 << 16);
*(uint32_t*) anim = anim01 | (r1 << 16);
goto bmcr_full_opacity;
}
} else if (a0 == 0) {
@ -246,9 +246,9 @@ bmno_full_transparency:
}
if (a1 > 0) {
if (a1 == 255) anim01 |= r1 << 16;
*(uint32*) anim = anim01;
*(uint32_t*) anim = anim01;
} else {
anim[0] = (uint16) anim01;
anim[0] = (uint16_t) anim01;
}
} else {
if (src[0].a) anim[0] = 0;
@ -273,7 +273,7 @@ bmcr_full_transparency:
if (src->a == 0) break;
if (src_mv->m) {
const uint r = remap[src_mv->m];
*anim = (animated && src->a == 255) ? r | ((uint16) src_mv->v << 8 ) : 0;
*anim = (animated && src->a == 255) ? r | ((uint16_t) src_mv->v << 8 ) : 0;
if (r != 0) {
Colour remapped_colour = AdjustBrightneSSE(this->LookupColourInPalette(r), src_mv->v);
if (src->a == 255) {
@ -337,7 +337,7 @@ bmcr_alpha_blend_single:
for (uint x = (uint) bp->width; x > 0; x--) {
if (src_mv->m == 0) {
if (src->a != 0) {
uint8 g = MakeDark(src->r, src->g, src->b);
uint8_t g = MakeDark(src->r, src->g, src->b);
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
*anim = 0;
}
@ -376,7 +376,7 @@ bmcr_alpha_blend_single:
} else {
*dst = AdjustBrightneSSE(src->data, DEFAULT_BRIGHTNESS + bp->brightness_adjust);
}
*anim = *(const uint16*) &mv;
*anim = *(const uint16_t*) &mv;
} else {
*anim = 0;
__m128i srcABCD;
@ -406,7 +406,7 @@ bmcr_alpha_blend_single:
MapValue mv = *src_mv;
mv.v = Clamp(mv.v + bp->brightness_adjust, 0, 255);
const uint r = remap[mv.m];
*anim = (animated && src->a == 255) ? r | ((uint16) mv.v << 8) : 0;
*anim = (animated && src->a == 255) ? r | ((uint16_t) mv.v << 8) : 0;
if (r != 0) {
Colour remapped_colour = AdjustBrightneSSE(this->LookupColourInPalette(r), mv.v);
if (src->a == 255) {

@ -15,20 +15,20 @@
void *Blitter_32bppBase::MoveTo(void *video, int x, int y)
{
return (uint32 *)video + x + y * _screen.pitch;
return (uint32_t *)video + x + y * _screen.pitch;
}
void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8 colour)
void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8_t colour)
{
*((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour);
}
void Blitter_32bppBase::SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32)
void Blitter_32bppBase::SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32)
{
*((Colour *)video + x + y * _screen.pitch) = colour32;
}
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash)
{
const Colour c = LookupColourInPalette(colour);
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
@ -36,7 +36,7 @@ void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int
});
}
void Blitter_32bppBase::SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch)
void Blitter_32bppBase::SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch)
{
Colour *dst = (Colour *)video + x + y * _screen.pitch;
do {
@ -51,17 +51,17 @@ void Blitter_32bppBase::SetRect(void *video, int x, int y, const uint8 *colours,
} while (--lines);
}
void Blitter_32bppBase::SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch)
void Blitter_32bppBase::SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch)
{
uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
uint32_t *dst = (uint32_t *)video + x + y * _screen.pitch;
do {
memcpy(dst, colours, width * sizeof(uint32));
memcpy(dst, colours, width * sizeof(uint32_t));
dst += _screen.pitch;
colours += pitch;
} while (--lines);
}
void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 colour)
void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8_t colour)
{
Colour colour32 = LookupColourInPalette(colour);
@ -71,22 +71,22 @@ void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 colou
*dst = colour32;
dst++;
}
video = (uint32 *)video + _screen.pitch;
video = (uint32_t *)video + _screen.pitch;
} while (--height);
}
void Blitter_32bppBase::DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour)
void Blitter_32bppBase::DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour)
{
this->Blitter_32bppBase::DrawRect((Colour *)video + x + y * _screen.pitch, width, height, colour);
}
void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
{
uint32 *dst = (uint32 *)video;
const uint32 *usrc = (const uint32 *)src;
uint32_t *dst = (uint32_t *)video;
const uint32_t *usrc = (const uint32_t *)src;
for (; height > 0; height--) {
memcpy(dst, usrc, width * sizeof(uint32));
memcpy(dst, usrc, width * sizeof(uint32_t));
usrc += width;
dst += _screen.pitch;
}
@ -94,11 +94,11 @@ void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width,
void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
{
uint32 *udst = (uint32 *)dst;
const uint32 *src = (const uint32 *)video;
uint32_t *udst = (uint32_t *)dst;
const uint32_t *src = (const uint32_t *)video;
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint32));
memcpy(udst, src, width * sizeof(uint32_t));
src += _screen.pitch;
udst += width;
}
@ -106,11 +106,11 @@ void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, in
void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
{
uint32 *udst = (uint32 *)dst;
const uint32 *src = (const uint32 *)video;
uint32_t *udst = (uint32_t *)dst;
const uint32_t *src = (const uint32_t *)video;
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint32));
memcpy(udst, src, width * sizeof(uint32_t));
src += _screen.pitch;
udst += dst_pitch;
}
@ -118,12 +118,12 @@ void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int widt
void Blitter_32bppBase::ScrollBuffer(void *video, int left, int top, int width, int height, int scroll_x, int scroll_y)
{
const uint32 *src;
uint32 *dst;
const uint32_t *src;
uint32_t *dst;
if (scroll_y > 0) {
/* Calculate pointers */
dst = (uint32 *)video + left + (top + height - 1) * _screen.pitch;
dst = (uint32_t *)video + left + (top + height - 1) * _screen.pitch;
src = dst - scroll_y * _screen.pitch;
/* Decrease height and increase top */
@ -142,13 +142,13 @@ void Blitter_32bppBase::ScrollBuffer(void *video, int left, int top, int width,
}
for (int h = height; h > 0; h--) {
memcpy(dst, src, width * sizeof(uint32));
memcpy(dst, src, width * sizeof(uint32_t));
src -= _screen.pitch;
dst -= _screen.pitch;
}
} else {
/* Calculate pointers */
dst = (uint32 *)video + left + top * _screen.pitch;
dst = (uint32_t *)video + left + top * _screen.pitch;
src = dst - scroll_y * _screen.pitch;
/* Decrease height. (scroll_y is <=0). */
@ -168,7 +168,7 @@ void Blitter_32bppBase::ScrollBuffer(void *video, int left, int top, int width,
/* the y-displacement may be 0 therefore we have to use memmove,
* because source and destination may overlap */
for (int h = height; h > 0; h--) {
memmove(dst, src, width * sizeof(uint32));
memmove(dst, src, width * sizeof(uint32_t));
src += _screen.pitch;
dst += _screen.pitch;
}
@ -177,7 +177,7 @@ void Blitter_32bppBase::ScrollBuffer(void *video, int left, int top, int width,
size_t Blitter_32bppBase::BufferSize(uint width, uint height)
{
return sizeof(uint32) * width * height;
return sizeof(uint32_t) * width * height;
}
void Blitter_32bppBase::PaletteAnimate(const Palette &)
@ -185,22 +185,22 @@ void Blitter_32bppBase::PaletteAnimate(const Palette &)
/* By default, 32bpp doesn't have palette animation */
}
Colour Blitter_32bppBase::ReallyAdjustBrightness(Colour colour, uint8 brightness)
Colour Blitter_32bppBase::ReallyAdjustBrightness(Colour colour, uint8_t brightness)
{
assert(DEFAULT_BRIGHTNESS == 1 << 7);
uint64 combined = (((uint64) colour.r) << 32) | (((uint64) colour.g) << 16) | ((uint64) colour.b);
uint64_t combined = (((uint64_t) colour.r) << 32) | (((uint64_t) colour.g) << 16) | ((uint64_t) colour.b);
combined *= brightness;
uint16 r = GB(combined, 39, 9);
uint16 g = GB(combined, 23, 9);
uint16 b = GB(combined, 7, 9);
uint16_t r = GB(combined, 39, 9);
uint16_t g = GB(combined, 23, 9);
uint16_t b = GB(combined, 7, 9);
if ((combined & 0x800080008000L) == 0L) {
return Colour(r, g, b, colour.a);
}
uint16 ob = 0;
uint16_t ob = 0;
/* Sum overbright */
if (r > 255) ob += r - 255;
if (g > 255) ob += g - 255;

@ -24,13 +24,13 @@ public:
}
void *MoveTo(void *video, int x, int y) override;
void SetPixel(void *video, int x, int y, uint8 colour) override;
void SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch) override;
void SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour) override;
void SetPixel(void *video, int x, int y, uint8_t colour) override;
void SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override;
void SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch) override;
void SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8_t colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override;
@ -125,7 +125,7 @@ public:
* @param b blue component
* @return the brightness value of the new colour, now dark grey.
*/
static inline uint8 MakeDark(uint8 r, uint8 g, uint8 b)
static inline uint8_t MakeDark(uint8_t r, uint8_t g, uint8_t b)
{
/* Magic-numbers are ~66% of those used in MakeGrey() */
return ((r * 13063) + (g * 25647) + (b * 4981)) / 65536;
@ -138,7 +138,7 @@ public:
*/
static inline Colour MakeDark(Colour colour)
{
uint8 d = MakeDark(colour.r, colour.g, colour.b);
uint8_t d = MakeDark(colour.r, colour.g, colour.b);
return Colour(d, d, d);
}
@ -164,9 +164,9 @@ public:
static const int DEFAULT_BRIGHTNESS = 128;
static Colour ReallyAdjustBrightness(Colour colour, uint8 brightness);
static Colour ReallyAdjustBrightness(Colour colour, uint8_t brightness);
static inline Colour AdjustBrightness(Colour colour, uint8 brightness)
static inline Colour AdjustBrightness(Colour colour, uint8_t brightness)
{
/* Shortcut for normal brightness */
if (likely(brightness == DEFAULT_BRIGHTNESS)) return colour;
@ -174,9 +174,9 @@ public:
return ReallyAdjustBrightness(colour, brightness);
}
static inline uint8 GetColourBrightness(Colour colour)
static inline uint8_t GetColourBrightness(Colour colour)
{
uint8 rgb_max = std::max(colour.r, std::max(colour.g, colour.b));
uint8_t rgb_max = std::max(colour.r, std::max(colour.g, colour.b));
/* Black pixel (8bpp or old 32bpp image), so use default value */
if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;

@ -31,18 +31,18 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
{
const SpriteData *src = (const SpriteData *)bp->sprite;
/* src_px : each line begins with uint32 n = 'number of bytes in this line',
/* src_px : each line begins with uint32_t n = 'number of bytes in this line',
* then n times is the Colour struct for this line */
const Colour *src_px = (const Colour *)(src->data + src->offset[zoom][0]);
/* src_n : each line begins with uint32 n = 'number of bytes in this line',
/* src_n : each line begins with uint32_t n = 'number of bytes in this line',
* then interleaved stream of 'm' and 'n' channels. 'm' is remap,
* 'n' is number of bytes with the same alpha channel class */
const uint16 *src_n = (const uint16 *)(src->data + src->offset[zoom][1]);
const uint16_t *src_n = (const uint16_t *)(src->data + src->offset[zoom][1]);
/* skip upper lines in src_px and src_n */
for (uint i = bp->skip_top; i != 0; i--) {
src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
src_n = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
src_px = (const Colour *)((const byte *)src_px + *(const uint32_t *)src_px);
src_n = (const uint16_t *)((const byte *)src_n + *(const uint32_t *)src_n);
}
/* skip lines in dst */
@ -56,11 +56,11 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
Colour *dst_ln = dst + bp->pitch;
/* next src line begins here */
const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32_t *)src_px);
src_px++;
/* next src_n line begins here */
const uint16 *src_n_ln = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
const uint16_t *src_n_ln = (const uint16_t *)((const byte *)src_n + *(const uint32_t *)src_n);
src_n += 2;
/* we will end this line when we reach this point */
@ -153,7 +153,7 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
do {
uint m = *src_n;
if (m == 0) {
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
uint8_t g = MakeDark(src_px->r, src_px->g, src_px->b);
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
} else {
uint r = remap[GB(m, 0, 8)];
@ -168,7 +168,7 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
uint m = *src_n;
if (m == 0) {
if (src_px->a != 0) {
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
uint8_t g = MakeDark(src_px->r, src_px->g, src_px->b);
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
}
} else {
@ -308,14 +308,14 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
*
* it has to be stored in one stream so fewer registers are used -
* x86 has problems with register allocation even with this solution */
uint16 *dst_n_orig[ZOOM_LVL_SPR_COUNT];
uint16_t *dst_n_orig[ZOOM_LVL_SPR_COUNT];
/* lengths of streams */
uint32 lengths[ZOOM_LVL_SPR_COUNT][2];
uint32_t lengths[ZOOM_LVL_SPR_COUNT][2];
ZoomLevel zoom_min;
ZoomLevel zoom_max;
uint8 missing_zoom_levels = 0;
uint8_t missing_zoom_levels = 0;
if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font) {
zoom_min = ZOOM_LVL_NORMAL;
@ -341,17 +341,17 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
}
Colour * const px_buffer = MallocT<Colour>(px_size);
uint16 * const n_buffer = MallocT<uint16>(n_size);
uint16_t * const n_buffer = MallocT<uint16_t>(n_size);
Colour *px_buffer_next = px_buffer;
uint16 *n_buffer_next = n_buffer;
uint16_t *n_buffer_next = n_buffer;
for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
const SpriteLoader::Sprite *src_orig = &sprite[z];
dst_px_orig[z] = px_buffer_next;
dst_n_orig[z] = n_buffer_next;
uint32 *dst_px_ln = (uint32 *)px_buffer_next;
uint32 *dst_n_ln = (uint32 *)n_buffer_next;
uint32_t *dst_px_ln = (uint32_t *)px_buffer_next;
uint32_t *dst_n_ln = (uint32_t *)n_buffer_next;
const SpriteLoader::CommonPixel *src = (const SpriteLoader::CommonPixel *)src_orig->data;
@ -365,16 +365,16 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
for (uint y = src_orig->height; y > 0; y--) {
/* Index 0 of dst_px and dst_n is left as space to save the length of the row to be filled later. */
Colour *dst_px = (Colour *)&dst_px_ln[1];
uint16 *dst_n = (uint16 *)&dst_n_ln[1];
uint16_t *dst_n = (uint16_t *)&dst_n_ln[1];
uint16 *dst_len = dst_n++;
uint16_t *dst_len = dst_n++;
*dst_len = 0;
uint last = 3;
int len = 0;
for (uint x = src_orig->width; x > 0; x--) {
uint8 a = src->a;
uint8_t a = src->a;
uint t = a > 0 && a < 255 ? 1 : a;
if (last != t || len == 65535) {
@ -396,7 +396,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
*dst_n = 0;
/* Get brightest value */
uint8 rgb_max = std::max({ src->r, src->g, src->b });
uint8_t rgb_max = std::max({ src->r, src->g, src->b });
/* Black pixel (8bpp or old 32bpp image), so use default value */
if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
@ -411,7 +411,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
if (src->m >= PALETTE_ANIM_START) flags &= ~BSF_NO_ANIM;
/* Get brightest value */
uint8 rgb_max = std::max({ src->r, src->g, src->b });
uint8_t rgb_max = std::max({ src->r, src->g, src->b });
/* Black pixel (8bpp or old 32bpp image), so use default value */
if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
@ -450,20 +450,20 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
}
dst_px = (Colour *)AlignPtr(dst_px, 4);
dst_n = (uint16 *)AlignPtr(dst_n, 4);
dst_n = (uint16_t *)AlignPtr(dst_n, 4);
*dst_px_ln = (uint8 *)dst_px - (uint8 *)dst_px_ln;
*dst_n_ln = (uint8 *)dst_n - (uint8 *)dst_n_ln;
*dst_px_ln = (uint8_t *)dst_px - (uint8_t *)dst_px_ln;
*dst_n_ln = (uint8_t *)dst_n - (uint8_t *)dst_n_ln;
dst_px_ln = (uint32 *)dst_px;
dst_n_ln = (uint32 *)dst_n;
dst_px_ln = (uint32_t *)dst_px;
dst_n_ln = (uint32_t *)dst_n;
}
lengths[z][0] = (byte *)dst_px_ln - (byte *)dst_px_orig[z]; // all are aligned to 4B boundary
lengths[z][1] = (byte *)dst_n_ln - (byte *)dst_n_orig[z];
px_buffer_next = (Colour *)dst_px_ln;
n_buffer_next = (uint16 *)dst_n_ln;
n_buffer_next = (uint16_t *)dst_n_ln;
}
uint len = 0; // total length of data
@ -490,7 +490,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
/* Store sprite flags. */
dst->flags = flags;
uint32 next_offset = 0;
uint32_t next_offset = 0;
for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
dst->offset[z][0] = next_offset;
dst->offset[z][1] = lengths[z][0] + next_offset;

@ -18,8 +18,8 @@ public:
/** Data stored about a (single) sprite. */
struct SpriteData {
BlitterSpriteFlags flags;
uint32 offset[ZOOM_LVL_SPR_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
byte data[]; ///< Data, all zoomlevels.
uint32_t offset[ZOOM_LVL_SPR_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
byte data[]; ///< Data, all zoomlevels.
};
Blitter_32bppOptimized()

@ -61,7 +61,7 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
case BM_CRASH_REMAP:
if (src->m == 0) {
if (src->a != 0) {
uint8 g = MakeDark(src->r, src->g, src->b);
uint8_t g = MakeDark(src->r, src->g, src->b);
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
}
} else {
@ -159,7 +159,7 @@ Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite
dst[i].v = 0;
} else {
/* Get brightest value */
uint8 rgb_max = std::max({src->r, src->g, src->b});
uint8_t rgb_max = std::max({src->r, src->g, src->b});
/* Black pixel (8bpp or old 32bpp image), so use default value */
if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;

@ -16,12 +16,12 @@
/** The most trivial 32 bpp blitter (without palette animation). */
class Blitter_32bppSimple : public Blitter_32bppBase {
struct Pixel {
uint8 r; ///< Red-channel
uint8 g; ///< Green-channel
uint8 b; ///< Blue-channel
uint8 a; ///< Alpha-channel
uint8 m; ///< Remap-channel
uint8 v; ///< Brightness-channel
uint8_t r; ///< Red-channel
uint8_t g; ///< Green-channel
uint8_t b; ///< Blue-channel
uint8_t a; ///< Alpha-channel
uint8_t m; ///< Remap-channel
uint8_t v; ///< Brightness-channel
};
public:
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;

@ -22,13 +22,13 @@ static FBlitter_32bppSSE2 iFBlitter_32bppSSE2;
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
/* First uint32 of a line = the number of transparent pixels from the left.
* Second uint32 of a line = the number of transparent pixels from the right.
/* First uint32_t of a line = the number of transparent pixels from the left.
* Second uint32_t of a line = the number of transparent pixels from the right.
* Then all RGBA then all MV.
*/
ZoomLevel zoom_min = ZOOM_LVL_NORMAL;
ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
uint8 missing_zoom_levels = 0;
uint8_t missing_zoom_levels = 0;
if (sprite[ZOOM_LVL_NORMAL].type != SpriteType::Font) {
zoom_min = _settings_client.gui.zoom_min;
zoom_max = (ZoomLevel) std::min(_settings_client.gui.zoom_max, ZOOM_LVL_DRAW_SPR);
@ -52,7 +52,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &spri
sd.infos[z].sprite_width = src_sprite->width;
sd.infos[z].sprite_offset = all_sprites_size;
sd.infos[z].sprite_line_size = sizeof(Colour) * src_sprite->width + sizeof(uint32) * META_LENGTH;
sd.infos[z].sprite_line_size = sizeof(Colour) * src_sprite->width + sizeof(uint32_t) * META_LENGTH;
const uint rgba_size = sd.infos[z].sprite_line_size * src_sprite->height;
sd.infos[z].mv_offset = all_sprites_size + rgba_size;
@ -91,7 +91,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &spri
dst_mv->m = src->m;
if (z >= _settings_client.gui.disable_water_animation && src->m >= 245 && src->m <= 254) {
/* Get brightest value */
uint8 rgb_max = std::max({ src->r, src->g, src->b });
uint8_t rgb_max = std::max({ src->r, src->g, src->b });
/* Black pixel (8bpp or old 32bpp image), so use default value */
if (rgb_max == 0) rgb_max = Blitter_32bppBase::DEFAULT_BRIGHTNESS;
@ -108,7 +108,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &spri
if (src->m >= PALETTE_ANIM_START) has_anim = true;
/* Get brightest value (or default brightness if it's a black pixel). */
const uint8 rgb_max = std::max({src->r, src->g, src->b});
const uint8_t rgb_max = std::max({src->r, src->g, src->b});
dst_mv->v = (rgb_max == 0) ? Blitter_32bppBase::DEFAULT_BRIGHTNESS : rgb_max;
/* Pre-convert the mapping channel to a RGB value. */
@ -124,7 +124,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &spri
}
} else {
dst_rgba->data = 0;
*(uint16*) dst_mv = 0;
*(uint16_t*) dst_mv = 0;
}
dst_rgba++;
dst_mv++;
@ -133,7 +133,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &spri
/* Count the number of transparent pixels from the left. */
dst_rgba = dst_rgba_line + META_LENGTH;
uint32 nb_pix_transp = 0;
uint32_t nb_pix_transp = 0;
for (uint x = src_sprite->width; x != 0; x--) {
if (dst_rgba->a == 0) nb_pix_transp++;
else break;

@ -32,8 +32,8 @@ public:
virtual ~Blitter_32bppSSE_Base() = default;
struct MapValue {
uint8 m;
uint8 v;
uint8_t m;
uint8_t v;
};
static_assert(sizeof(MapValue) == 2);
@ -53,10 +53,10 @@ public:
/** Data stored about a (single) sprite. */
struct SpriteInfo {
uint32 sprite_offset; ///< The offset to the sprite data.
uint32 mv_offset; ///< The offset to the map value data.
uint16 sprite_line_size; ///< The size of a single line (pitch).
uint16 sprite_width; ///< The width of the sprite.
uint32_t sprite_offset; ///< The offset to the sprite data.
uint32_t mv_offset; ///< The offset to the map value data.
uint16_t sprite_line_size; ///< The size of a single line (pitch).
uint16_t sprite_width; ///< The width of the sprite.
};
struct SpriteData {
BlitterSpriteFlags flags;

@ -75,7 +75,7 @@ inline __m128i DistributeAlpha(const __m128i from, const __m128i &mask)
GNU_TARGET(SSE_TARGET)
inline __m128i AlphaBlendTwoPixels(__m128i src, __m128i dst, const __m128i &distribution_mask, const __m128i &pack_mask, const __m128i &alpha_mask)
{
__m128i srcAB = _mm_unpacklo_epi8(src, _mm_setzero_si128()); // PUNPCKLBW, expand each uint8 into uint16
__m128i srcAB = _mm_unpacklo_epi8(src, _mm_setzero_si128()); // PUNPCKLBW, expand each uint8_t into uint16
__m128i dstAB = _mm_unpacklo_epi8(dst, _mm_setzero_si128());
__m128i alphaMaskAB = _mm_cmpgt_epi16(srcAB, _mm_setzero_si128()); // PCMPGTW (alpha > 0) ? 0xFFFF : 0
@ -111,19 +111,19 @@ inline __m128i DarkenTwoPixels(__m128i src, __m128i dst, const __m128i &distribu
IGNORE_UNINITIALIZED_WARNING_START
GNU_TARGET(SSE_TARGET)
static Colour ReallyAdjustBrightness(Colour colour, uint8 brightness)
static Colour ReallyAdjustBrightness(Colour colour, uint8_t brightness)
{
uint64 c16 = colour.b | (uint64) colour.g << 16 | (uint64) colour.r << 32;
uint64_t c16 = colour.b | (uint64_t) colour.g << 16 | (uint64_t) colour.r << 32;
c16 *= brightness;
uint64 c16_ob = c16; // Helps out of order execution.
uint64_t c16_ob = c16; // Helps out of order execution.
c16 /= Blitter_32bppBase::DEFAULT_BRIGHTNESS;
c16 &= 0x01FF01FF01FFULL;
/* Sum overbright (maximum for each rgb is 508, 9 bits, -255 is changed in -256 so we just have to take the 8 lower bits into account). */
c16_ob = (((c16_ob >> (8 + 7)) & 0x0100010001ULL) * 0xFF) & c16;
const uint ob = ((uint16) c16_ob + (uint16) (c16_ob >> 16) + (uint16) (c16_ob >> 32)) / 2;
const uint ob = ((uint16_t) c16_ob + (uint16_t) (c16_ob >> 16) + (uint16_t) (c16_ob >> 32)) / 2;
const uint32 alpha32 = colour.data & 0xFF000000;
const uint32_t alpha32 = colour.data & 0xFF000000;
__m128i ret;
LoadUint64(c16, ret);
if (ob != 0) {
@ -224,7 +224,7 @@ inline void Blitter_32bppSSE4::Draw(const Blitter::BlitterParams *bp, ZoomLevel
const MapValue *src_mv_line = (const MapValue *) &sd->data[si->mv_offset] + bp->skip_top * si->sprite_width;
const Colour *src_rgba_line = (const Colour *) ((const byte *) &sd->data[si->sprite_offset] + bp->skip_top * si->sprite_line_size);
uint32 bm_normal_brightness = 0;
uint32_t bm_normal_brightness = 0;
if (mode == BM_NORMAL_WITH_BRIGHTNESS) {
bm_normal_brightness = (DEFAULT_BRIGHTNESS + bp->brightness_adjust) << 8;
bm_normal_brightness |= bm_normal_brightness << 16;
@ -304,7 +304,7 @@ inline void Blitter_32bppSSE4::Draw(const Blitter::BlitterParams *bp, ZoomLevel
for (uint x = (uint) effective_width / 2; x > 0; x--) {
__m128i srcABCD = _mm_loadl_epi64((const __m128i*) src);
__m128i dstABCD = _mm_loadl_epi64((__m128i*) dst);
uint32 mvX2 = *((uint32 *) const_cast<MapValue *>(src_mv));
uint32_t mvX2 = *((uint32_t *) const_cast<MapValue *>(src_mv));
/* Remap colours. */
if (mvX2 & 0x00FF00FF) {
@ -320,12 +320,12 @@ inline void Blitter_32bppSSE4::Draw(const Blitter::BlitterParams *bp, ZoomLevel
m_colour = m != 0 ? m_colour : srcm; \
}
#ifdef POINTER_IS_64BIT
uint64 srcs = _mm_cvtsi128_si64(srcABCD);
uint64 remapped_src = 0;
uint64_t srcs = _mm_cvtsi128_si64(srcABCD);
uint64_t remapped_src = 0;
CMOV_REMAP(c0, 0, srcs, mvX2);
remapped_src = c0.data;
CMOV_REMAP(c1, 0, srcs >> 32, mvX2 >> 16);
remapped_src |= (uint64) c1.data << 32;
remapped_src |= (uint64_t) c1.data << 32;
srcABCD = _mm_cvtsi64_si128(remapped_src);
#else
Colour remapped_src[2];
@ -414,7 +414,7 @@ bmcr_alpha_blend_single:
for (uint x = (uint) bp->width; x > 0; x--) {
if (src_mv->m == 0) {
if (src->a != 0) {
uint8 g = MakeDark(src->r, src->g, src->b);
uint8_t g = MakeDark(src->r, src->g, src->b);
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
}
} else {

@ -21,7 +21,7 @@
#include <smmintrin.h>
#endif
#define META_LENGTH 2 ///< Number of uint32 inserted before each line of pixels in a sprite.
#define META_LENGTH 2 ///< Number of uint32_t inserted before each line of pixels in a sprite.
#define MARGIN_NORMAL_THRESHOLD (zoom == ZOOM_LVL_OUT_32X ? 8 : 4) ///< Minimum width to use margins with BM_NORMAL.
#define MARGIN_REMAP_THRESHOLD 4 ///< Minimum width to use margins with BM_COLOUR_REMAP.
@ -35,10 +35,10 @@
typedef union ALIGN(16) um128i {
__m128i m128i;
uint8 m128i_u8[16];
uint16 m128i_u16[8];
uint32 m128i_u32[4];
uint64 m128i_u64[2];
uint8_t m128i_u8[16];
uint16_t m128i_u16[8];
uint32_t m128i_u32[4];
uint64_t m128i_u64[2];
} um128i;
#define CLEAR_HIGH_BYTE_MASK _mm_setr_epi8(-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0)

@ -24,7 +24,7 @@
static FBlitter_40bppAnim iFBlitter_40bppAnim;
void Blitter_40bppAnim::SetPixel(void *video, int x, int y, uint8 colour)
void Blitter_40bppAnim::SetPixel(void *video, int x, int y, uint8_t colour)
{
if (_screen_disable_anim) {
Blitter_32bppOptimized::SetPixel(video, x, y, colour);
@ -32,11 +32,11 @@ void Blitter_40bppAnim::SetPixel(void *video, int x, int y, uint8 colour)
size_t y_offset = static_cast<size_t>(y) * _screen.pitch;
*((Colour *)video + x + y_offset) = _black_colour;
VideoDriver::GetInstance()->GetAnimBuffer()[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y_offset] = colour;
VideoDriver::GetInstance()->GetAnimBuffer()[((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + x + y_offset] = colour;
}
}
void Blitter_40bppAnim::SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32)
void Blitter_40bppAnim::SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32)
{
if (_screen_disable_anim) {
Blitter_32bppOptimized::SetPixel32(video, x, y, colour, colour32);
@ -44,20 +44,20 @@ void Blitter_40bppAnim::SetPixel32(void *video, int x, int y, uint8 colour, uint
size_t y_offset = static_cast<size_t>(y) * _screen.pitch;
*((Colour *)video + x + y_offset) = colour32;
VideoDriver::GetInstance()->GetAnimBuffer()[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y_offset] = 0;
VideoDriver::GetInstance()->GetAnimBuffer()[((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + x + y_offset] = 0;
}
}
void Blitter_40bppAnim::SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch)
void Blitter_40bppAnim::SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch)
{
if (_screen_disable_anim) {
Blitter_32bppOptimized::SetRect(video, x, y, colours, lines, width, pitch);
} else {
Colour *dst = (Colour *)video + x + y * _screen.pitch;
uint8 *dstanim = ((uint32 *)dst - (uint32 *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *dstanim = ((uint32_t *)dst - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
do {
memset_colour(dst, _black_colour, width);
memcpy(dstanim, colours, width * sizeof(uint8));
memcpy(dstanim, colours, width * sizeof(uint8_t));
dst += _screen.pitch;
dstanim += _screen.pitch;
colours += pitch;
@ -65,16 +65,16 @@ void Blitter_40bppAnim::SetRect(void *video, int x, int y, const uint8 *colours,
}
}
void Blitter_40bppAnim::SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch)
void Blitter_40bppAnim::SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch)
{
if (_screen_disable_anim) {
Blitter_32bppOptimized::SetRect32(video, x, y, colours, lines, width, pitch);
} else {
Colour *dst = (Colour *)video + x + y * _screen.pitch;
uint8 *dstanim = ((uint32 *)dst - (uint32 *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *dstanim = ((uint32_t *)dst - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
do {
memcpy((uint32 *)dst, colours, width * sizeof(uint32));
memset(dstanim, 0, width * sizeof(uint8));
memcpy((uint32_t *)dst, colours, width * sizeof(uint32_t));
memset(dstanim, 0, width * sizeof(uint8_t));
dst += _screen.pitch;
dstanim += _screen.pitch;
colours += pitch;
@ -82,7 +82,7 @@ void Blitter_40bppAnim::SetRect32(void *video, int x, int y, const uint32 *colou
}
}
void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8 colour)
void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8_t colour)
{
if (_screen_disable_anim) {
/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */
@ -91,23 +91,23 @@ void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8 colou
}
assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr);
uint8 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *anim_line = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
do {
memset_colour((Colour *)video, _black_colour, width);
memset(anim_line, colour, width);
video = (uint32 *)video + _screen.pitch;
video = (uint32_t *)video + _screen.pitch;
anim_line += _screen.pitch;
} while (--height);
}
void Blitter_40bppAnim::DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour)
void Blitter_40bppAnim::DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour)
{
this->Blitter_40bppAnim::DrawRect((Colour *)video + x + y * _screen.pitch, width, height, colour);
}
void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash)
{
if (_screen_disable_anim) {
/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */
@ -116,7 +116,7 @@ void Blitter_40bppAnim::DrawLine(void *video, int x, int y, int x2, int y2, int
}
assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr);
uint8 *anim = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *anim = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer();
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
*((Colour *)video + x + y * _screen.pitch) = _black_colour;
@ -136,24 +136,24 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
{
const SpriteData *src = (const SpriteData *)bp->sprite;
/* src_px : each line begins with uint32 n = 'number of bytes in this line',
/* src_px : each line begins with uint32_t n = 'number of bytes in this line',
* then n times is the Colour struct for this line */
const Colour *src_px = (const Colour *)(src->data + src->offset[zoom][0]);
/* src_n : each line begins with uint32 n = 'number of bytes in this line',
/* src_n : each line begins with uint32_t n = 'number of bytes in this line',
* then interleaved stream of 'm' and 'n' channels. 'm' is remap,
* 'n' is number of bytes with the same alpha channel class */
const uint16 *src_n = (const uint16 *)(src->data + src->offset[zoom][1]);
const uint16_t *src_n = (const uint16_t *)(src->data + src->offset[zoom][1]);
/* skip upper lines in src_px and src_n */
for (uint i = bp->skip_top; i != 0; i--) {
src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
src_n = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
src_px = (const Colour *)((const byte *)src_px + *(const uint32_t *)src_px);
src_n = (const uint16_t *)((const byte *)src_n + *(const uint32_t *)src_n);
}
/* skip lines in dst */
Colour *dst = (Colour *)bp->dst + bp->top * bp->pitch + bp->left;
assert(VideoDriver::GetInstance()->GetAnimBuffer() != nullptr);
uint8 *anim = VideoDriver::GetInstance()->GetAnimBuffer() + ((uint32 *)bp->dst - (uint32 *)_screen.dst_ptr) + bp->top * bp->pitch + bp->left;
uint8_t *anim = VideoDriver::GetInstance()->GetAnimBuffer() + ((uint32_t *)bp->dst - (uint32_t *)_screen.dst_ptr) + bp->top * bp->pitch + bp->left;
/* store so we don't have to access it via bp everytime (compiler assumes pointer aliasing) */
const byte *remap = bp->remap;
@ -161,14 +161,14 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
for (int y = 0; y < bp->height; y++) {
/* next dst line begins here */
Colour *dst_ln = dst + bp->pitch;
uint8 *anim_ln = anim + bp->pitch;
uint8_t *anim_ln = anim + bp->pitch;
/* next src line begins here */
const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px);
const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32_t *)src_px);
src_px++;
/* next src_n line begins here */
const uint16 *src_n_ln = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n);
const uint16_t *src_n_ln = (const uint16_t *)((const byte *)src_n + *(const uint32_t *)src_n);
src_n += 2;
/* we will end this line when we reach this point */
@ -228,7 +228,7 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
case BM_COLOUR_REMAP_WITH_BRIGHTNESS:
if (src_px->a == 255) {
do {
uint8 m = GB(*src_n, 0, 8);
uint8_t m = GB(*src_n, 0, 8);
/* In case the m-channel is zero, only apply the crash remap by darkening the RGB colour. */
if (m == 0) {
Colour c = *src_px;
@ -254,7 +254,7 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
} while (--n != 0);
} else {
do {
uint8 m = GB(*src_n, 0, 8);
uint8_t m = GB(*src_n, 0, 8);
Colour b = this->RealizeBlendedColour(*anim, *dst);
if (m == 0) {
Colour c = *src_px;
@ -355,7 +355,7 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
break;
} else {
do {
uint8 m = GB(*src_n, 0, 8);
uint8_t m = GB(*src_n, 0, 8);
Colour b = this->RealizeBlendedColour(*anim, *dst);
if (m == 0) {
@ -425,7 +425,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
}
Colour *udst = (Colour *)dst;
uint8 *anim = VideoDriver::GetInstance()->GetAnimBuffer() + ((uint32 *)dst - (uint32 *)_screen.dst_ptr);
uint8_t *anim = VideoDriver::GetInstance()->GetAnimBuffer() + ((uint32_t *)dst - (uint32_t *)_screen.dst_ptr);
if (pal == PALETTE_TO_TRANSPARENT) {
/* If the anim buffer contains a color value, the image composition will
@ -442,7 +442,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
anim = anim - width + _screen.pitch;
} while (--height);
} else if (pal == PALETTE_NEWSPAPER) {
const uint8 *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
const uint8_t *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
do {
for (int i = 0; i != width; i++) {
if (*anim == 0) *udst = MakeGrey(*udst);
@ -454,7 +454,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
anim = anim - width + _screen.pitch;
} while (--height);
} else {
const uint8 *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
const uint8_t *remap = GetNonSprite(pal, SpriteType::Recolour) + 1;
do {
for (int i = 0; i != width; i++) {
*anim = remap[*anim];
@ -474,21 +474,21 @@ Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::SpriteCollection &sprite,
void Blitter_40bppAnim::CopyFromBuffer(void *video, const void *src, int width, int height)
{
assert(!_screen_disable_anim);
assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint32 *dst = (uint32 *)video;
const uint32 *usrc = (const uint32 *)src;
assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint32_t *dst = (uint32_t *)video;
const uint32_t *usrc = (const uint32_t *)src;
uint8 *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
if (anim_buf == nullptr) return;
uint8 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + anim_buf;
uint8_t *anim_line = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
for (; height > 0; height--) {
memcpy(dst, usrc, width * sizeof(uint32));
memcpy(dst, usrc, width * sizeof(uint32_t));
usrc += width;
dst += _screen.pitch;
/* Copy back the anim-buffer */
memcpy(anim_line, usrc, width * sizeof(uint8));
usrc = (const uint32 *)((const uint8 *)usrc + width);
memcpy(anim_line, usrc, width * sizeof(uint8_t));
usrc = (const uint32_t *)((const uint8_t *)usrc + width);
anim_line += _screen.pitch;
}
}
@ -496,36 +496,36 @@ void Blitter_40bppAnim::CopyFromBuffer(void *video, const void *src, int width,
void Blitter_40bppAnim::CopyToBuffer(const void *video, void *dst, int width, int height)
{
assert(!_screen_disable_anim);
assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint32 *udst = (uint32 *)dst;
const uint32 *src = (const uint32 *)video;
assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint32_t *udst = (uint32_t *)dst;
const uint32_t *src = (const uint32_t *)video;
uint8 *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
if (anim_buf == nullptr) return;
const uint8 *anim_line = ((const uint32 *)video - (uint32 *)_screen.dst_ptr) + anim_buf;
const uint8_t *anim_line = ((const uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint32));
memcpy(udst, src, width * sizeof(uint32_t));
src += _screen.pitch;
udst += width;
/* Copy the anim-buffer */
memcpy(udst, anim_line, width * sizeof(uint8));
udst = (uint32 *)((uint8 *)udst + width);
memcpy(udst, anim_line, width * sizeof(uint8_t));
udst = (uint32_t *)((uint8_t *)udst + width);
anim_line += _screen.pitch;
}
}
void Blitter_40bppAnim::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
{
uint8 *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
if (anim_buf == nullptr) {
Blitter_32bppOptimized::CopyImageToBuffer(video, dst, width, height, dst_pitch);
return;
}
uint32 *udst = (uint32 *)dst;
const uint32 *src = (const uint32 *)video;
const uint8 *anim_line = ((const uint32 *)video - (uint32 *)_screen.dst_ptr) + anim_buf;
uint32_t *udst = (uint32_t *)dst;
const uint32_t *src = (const uint32_t *)video;
const uint8_t *anim_line = ((const uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
for (; height > 0; height--) {
for (int x = 0; x < width; x++) {
@ -540,9 +540,9 @@ void Blitter_40bppAnim::CopyImageToBuffer(const void *video, void *dst, int widt
void Blitter_40bppAnim::ScrollBuffer(void *video, int left, int top, int width, int height, int scroll_x, int scroll_y)
{
assert(!_screen_disable_anim);
assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint8 *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
uint8 *dst, *src;
assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
uint8_t *anim_buf = VideoDriver::GetInstance()->GetAnimBuffer();
uint8_t *dst, *src;
/* We need to scroll the anim-buffer too */
if (scroll_y > 0) {
@ -559,7 +559,7 @@ void Blitter_40bppAnim::ScrollBuffer(void *video, int left, int top, int width,
uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
uint th = height - scroll_y;
for (; th > 0; th--) {
memcpy(dst, src, tw * sizeof(uint8));
memcpy(dst, src, tw * sizeof(uint8_t));
src -= _screen.pitch;
dst -= _screen.pitch;
}
@ -580,7 +580,7 @@ void Blitter_40bppAnim::ScrollBuffer(void *video, int left, int top, int width,
uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
uint th = height + scroll_y;
for (; th > 0; th--) {
memmove(dst, src, tw * sizeof(uint8));
memmove(dst, src, tw * sizeof(uint8_t));
src += _screen.pitch;
dst += _screen.pitch;
}
@ -591,7 +591,7 @@ void Blitter_40bppAnim::ScrollBuffer(void *video, int left, int top, int width,
size_t Blitter_40bppAnim::BufferSize(uint width, uint height)
{
return (sizeof(uint32) + sizeof(uint8)) * width * height;
return (sizeof(uint32_t) + sizeof(uint8_t)) * width * height;
}
Blitter::PaletteAnimation Blitter_40bppAnim::UsePaletteAnimation()

@ -18,13 +18,13 @@
class Blitter_40bppAnim : public Blitter_32bppOptimized {
public:
void SetPixel(void *video, int x, int y, uint8 colour) override;
void SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32) override;
void SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch) override;
void SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetPixel(void *video, int x, int y, uint8_t colour) override;
void SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32) override;
void SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch) override;
void SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8_t colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override;
@ -41,7 +41,7 @@ public:
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
protected:
static inline Colour RealizeBlendedColour(uint8 anim, Colour c)
static inline Colour RealizeBlendedColour(uint8_t anim, Colour c)
{
return anim != 0 ? AdjustBrightness(LookupColourInPalette(anim), GetColourBrightness(c)) : c;
}

@ -16,66 +16,66 @@
void Blitter_8bppBase::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
{
const uint8 *ctab = GetNonSprite(pal, SpriteType::Recolour) + 1;
const uint8_t *ctab = GetNonSprite(pal, SpriteType::Recolour) + 1;
do {
for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
dst = (uint8 *)dst + _screen.pitch;
for (int i = 0; i != width; i++) *((uint8_t *)dst + i) = ctab[((uint8_t *)dst)[i]];
dst = (uint8_t *)dst + _screen.pitch;
} while (--height);
}
void *Blitter_8bppBase::MoveTo(void *video, int x, int y)
{
return (uint8 *)video + x + y * _screen.pitch;
return (uint8_t *)video + x + y * _screen.pitch;
}
void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8 colour)
void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8_t colour)
{
*((uint8 *)video + x + y * _screen.pitch) = colour;
*((uint8_t *)video + x + y * _screen.pitch) = colour;
}
void Blitter_8bppBase::SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32)
void Blitter_8bppBase::SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32)
{
this->Blitter_8bppBase::SetPixel(video, x, y, colour);
}
void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash)
{
this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
*((uint8 *)video + x + y * _screen.pitch) = colour;
*((uint8_t *)video + x + y * _screen.pitch) = colour;
});
}
void Blitter_8bppBase::SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch)
void Blitter_8bppBase::SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch)
{
uint8 *dst = (uint8 *)video + x + y * _screen.pitch;
uint8_t *dst = (uint8_t *)video + x + y * _screen.pitch;
do {
memcpy(dst, colours, width * sizeof(uint8));
memcpy(dst, colours, width * sizeof(uint8_t));
dst += _screen.pitch;
colours += pitch;
} while (--lines);
}
void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8 colour)
void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8_t colour)
{
do {
memset(video, colour, width);
video = (uint8 *)video + _screen.pitch;
video = (uint8_t *)video + _screen.pitch;
} while (--height);
}
void Blitter_8bppBase::DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour)
void Blitter_8bppBase::DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour)
{
this->Blitter_8bppBase::DrawRect((uint8 *)video + x + y * _screen.pitch, width, height, colour);
this->Blitter_8bppBase::DrawRect((uint8_t *)video + x + y * _screen.pitch, width, height, colour);
}
void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
{
uint8 *dst = (uint8 *)video;
const uint8 *usrc = (const uint8 *)src;
uint8_t *dst = (uint8_t *)video;
const uint8_t *usrc = (const uint8_t *)src;
for (; height > 0; height--) {
memcpy(dst, usrc, width * sizeof(uint8));
memcpy(dst, usrc, width * sizeof(uint8_t));
usrc += width;
dst += _screen.pitch;
}
@ -83,11 +83,11 @@ void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, i
void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
{
uint8 *udst = (uint8 *)dst;
const uint8 *src = (const uint8 *)video;
uint8_t *udst = (uint8_t *)dst;
const uint8_t *src = (const uint8_t *)video;
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint8));
memcpy(udst, src, width * sizeof(uint8_t));
src += _screen.pitch;
udst += width;
}
@ -95,11 +95,11 @@ void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int
void Blitter_8bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
{
uint8 *udst = (uint8 *)dst;
const uint8 *src = (const uint8 *)video;
uint8_t *udst = (uint8_t *)dst;
const uint8_t *src = (const uint8_t *)video;
for (; height > 0; height--) {
memcpy(udst, src, width * sizeof(uint8));
memcpy(udst, src, width * sizeof(uint8_t));
src += _screen.pitch;
udst += dst_pitch;
}
@ -107,12 +107,12 @@ void Blitter_8bppBase::CopyImageToBuffer(const void *video, void *dst, int width
void Blitter_8bppBase::ScrollBuffer(void *video, int left, int top, int width, int height, int scroll_x, int scroll_y)
{
const uint8 *src;
uint8 *dst;
const uint8_t *src;
uint8_t *dst;
if (scroll_y > 0) {
/* Calculate pointers */
dst = (uint8 *)video + left + (top + height - 1) * _screen.pitch;
dst = (uint8_t *)video + left + (top + height - 1) * _screen.pitch;
src = dst - scroll_y * _screen.pitch;
/* Decrease height and increase top */
@ -131,13 +131,13 @@ void Blitter_8bppBase::ScrollBuffer(void *video, int left, int top, int width, i
}
for (int h = height; h > 0; h--) {
memcpy(dst, src, width * sizeof(uint8));
memcpy(dst, src, width * sizeof(uint8_t));
src -= _screen.pitch;
dst -= _screen.pitch;
}
} else {
/* Calculate pointers */
dst = (uint8 *)video + left + top * _screen.pitch;
dst = (uint8_t *)video + left + top * _screen.pitch;
src = dst - scroll_y * _screen.pitch;
/* Decrease height. (scroll_y is <=0). */
@ -157,7 +157,7 @@ void Blitter_8bppBase::ScrollBuffer(void *video, int left, int top, int width, i
/* the y-displacement may be 0 therefore we have to use memmove,
* because source and destination may overlap */
for (int h = height; h > 0; h--) {
memmove(dst, src, width * sizeof(uint8));
memmove(dst, src, width * sizeof(uint8_t));
src += _screen.pitch;
dst += _screen.pitch;
}

@ -22,12 +22,12 @@ public:
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
void *MoveTo(void *video, int x, int y) override;
void SetPixel(void *video, int x, int y, uint8 colour) override;
void SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour) override;
void SetPixel(void *video, int x, int y, uint8_t colour) override;
void SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override;
void SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch) override;
void DrawRect(void *video, int width, int height, uint8_t colour) override;
void DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override;

@ -26,8 +26,8 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
uint offset = sprite_src->offset[zoom];
/* Find where to start reading in the source sprite */
const uint8 *src = sprite_src->data + offset;
uint8 *dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
const uint8_t *src = sprite_src->data + offset;
uint8_t *dst_line = (uint8_t *)bp->dst + bp->top * bp->pitch + bp->left;
/* Skip over the top lines in the source image */
for (int y = 0; y < bp->skip_top; y++) {
@ -39,10 +39,10 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
}
}
const uint8 *src_next = src;
const uint8_t *src_next = src;
for (int y = 0; y < bp->height; y++) {
uint8 *dst = dst_line;
uint8_t *dst = dst_line;
dst_line += bp->pitch;
uint skip_left = bp->skip_left;
@ -87,7 +87,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
case BM_COLOUR_REMAP:
case BM_CRASH_REMAP:
case BM_COLOUR_REMAP_WITH_BRIGHTNESS: {
const uint8 *remap = bp->remap;
const uint8_t *remap = bp->remap;
do {
uint m = remap[*src];
if (m != 0) *dst = m;

@ -18,8 +18,8 @@ class Blitter_8bppOptimized FINAL : public Blitter_8bppBase {
public:
/** Data stored about a (single) sprite. */
struct SpriteData {
uint32 offset[ZOOM_LVL_SPR_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
byte data[]; ///< Data, all zoomlevels.
uint32_t offset[ZOOM_LVL_SPR_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
byte data[]; ///< Data, all zoomlevels.
};
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;

@ -18,12 +18,12 @@ static FBlitter_8bppSimple iFBlitter_8bppSimple;
void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
{
const uint8 *src, *src_line;
uint8 *dst, *dst_line;
const uint8_t *src, *src_line;
uint8_t *dst, *dst_line;
/* Find where to start reading in the source sprite */
src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
src_line = (const uint8_t *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
dst_line = (uint8_t *)bp->dst + bp->top * bp->pitch + bp->left;
for (int y = 0; y < bp->height; y++) {
dst = dst_line;

@ -45,10 +45,10 @@ DECLARE_ENUM_AS_BIT_SET(BlitterSpriteFlags);
* How all blitters should look like. Extend this class to make your own.
*/
class Blitter : public SpriteEncoder {
uint8 screen_depth = 0;
uint8_t screen_depth = 0;
protected:
void SetScreenDepth(uint8 depth)
void SetScreenDepth(uint8_t depth)
{
this->screen_depth = depth;
this->SetIs32BppSupported(depth > 8);
@ -85,7 +85,7 @@ public:
* Get the screen depth this blitter works for.
* This is either: 8, 16, 24 or 32.
*/
inline uint8 GetScreenDepth() const
inline uint8_t GetScreenDepth() const
{
return this->screen_depth;
}
@ -123,7 +123,7 @@ public:
* @param y The y position within video-buffer.
* @param colour A 8bpp mapping colour.
*/
virtual void SetPixel(void *video, int x, int y, uint8 colour) = 0;
virtual void SetPixel(void *video, int x, int y, uint8_t colour) = 0;
/**
* Draw a pixel with a given 32bpp colour on the video-buffer.
@ -134,7 +134,7 @@ public:
* @param colour A 8bpp mapping colour.
* @param colour32 A 32bpp colour.
*/
virtual void SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32) = 0;
virtual void SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32) = 0;
/**
* Draw a rectangle of pixels on the video-buffer.
@ -146,7 +146,7 @@ public:
* @param width The length of the lines.
* @param pitch The pitch of the colours buffer
*/
virtual void SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch) = 0;
virtual void SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch) = 0;
/**
* Draw a rectangle of pixels on the video-buffer (no LookupColourInPalette).
@ -158,7 +158,7 @@ public:
* @param width The length of the lines.
* @param pitch The pitch of the colours buffer.
*/
virtual void SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch) { NOT_REACHED(); };
virtual void SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch) { NOT_REACHED(); };
/**
* Make a single horizontal line in a single colour on the video-buffer.
@ -167,7 +167,7 @@ public:
* @param height The height of the line.
* @param colour A 8bpp mapping colour.
*/
virtual void DrawRect(void *video, int width, int height, uint8 colour) = 0;
virtual void DrawRect(void *video, int width, int height, uint8_t colour) = 0;
/**
* Make a single horizontal line in a single colour on the video-buffer.
@ -178,7 +178,7 @@ public:
* @param height The height of the line.
* @param colour A 8bpp mapping colour.
*/
virtual void DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour) = 0;
virtual void DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour) = 0;
/**
* Draw a line with a given colour.
@ -193,7 +193,7 @@ public:
* @param width Line width.
* @param dash Length of dashes for dashed lines. 0 means solid line.
*/
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash = 0) = 0;
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash = 0) = 0;
/**
* Copy from a buffer to the screen.

@ -58,11 +58,11 @@ void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width,
/* compute frac_diff = width * sqrt(dx*dx + dy*dy)
* Start interval:
* max(dx, dy) <= sqrt(dx*dx + dy*dy) <= sqrt(2) * max(dx, dy) <= 3/2 * max(dx, dy) */
int64 frac_sq = ((int64) width) * ((int64) width) * (((int64) dx) * ((int64) dx) + ((int64) dy) * ((int64) dy));
int64_t frac_sq = ((int64_t) width) * ((int64_t) width) * (((int64_t) dx) * ((int64_t) dx) + ((int64_t) dy) * ((int64_t) dy));
int frac_max = 3 * frac_diff / 2;
while (frac_diff < frac_max) {
int frac_test = (frac_diff + frac_max) / 2;
if (((int64) frac_test) * ((int64) frac_test) < frac_sq) {
if (((int64_t) frac_test) * ((int64_t) frac_test) < frac_sq) {
frac_diff = frac_test + 1;
} else {
frac_max = frac_test - 1;
@ -97,8 +97,8 @@ void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width,
if (x1 < 0) {
dash_count = (-x1) % (dash + gap);
auto adjust_frac = [&](int64 frac, int &y_bound) -> int {
frac -= ((int64) dy) * ((int64) x1);
auto adjust_frac = [&](int64_t frac, int &y_bound) -> int {
frac -= ((int64_t) dy) * ((int64_t) x1);
if (frac >= 0) {
int quotient = frac / dx;
int remainder = frac % dx;
@ -159,8 +159,8 @@ void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width,
if (y1 < 0) {
dash_count = (-y1) % (dash + gap);
auto adjust_frac = [&](int64 frac, int &x_bound) -> int {
frac -= ((int64) dx) * ((int64) y1);
auto adjust_frac = [&](int64_t frac, int &x_bound) -> int {
frac -= ((int64_t) dx) * ((int64_t) y1);
if (frac >= 0) {
int quotient = frac / dy;
int remainder = frac % dy;
@ -200,12 +200,12 @@ void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width,
}
}
inline void memset_uint32(uint32 *s, uint32 c, size_t n)
inline void memset_uint32(uint32_t *s, uint32_t c, size_t n)
{
#ifdef __APPLE__
memset_pattern4(static_cast<void *>(s), static_cast<const void *>(&c), n * sizeof(uint32));
memset_pattern4(static_cast<void *>(s), static_cast<const void *>(&c), n * sizeof(uint32_t));
#else
if constexpr (sizeof(wchar_t) == sizeof(uint32)) {
if constexpr (sizeof(wchar_t) == sizeof(uint32_t)) {
wmemset((wchar_t *)s, (wchar_t)c, n);
} else {
for (; n > 0; n--) {
@ -218,7 +218,7 @@ inline void memset_uint32(uint32 *s, uint32 c, size_t n)
inline void memset_colour(Colour *s, Colour c, size_t n)
{
memset_uint32((uint32 *)s, c.data, n);
memset_uint32((uint32_t *)s, c.data, n);
}
#endif /* BLITTER_COMMON_HPP */

@ -25,13 +25,13 @@ public:
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override {};
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
void *MoveTo(void *video, int x, int y) override { return nullptr; };
void SetPixel(void *video, int x, int y, uint8 colour) override {};
void SetPixel32(void *video, int x, int y, uint8 colour, uint32 colour32) override {};
void DrawRect(void *video, int width, int height, uint8 colour) override {};
void DrawRectAt(void *video, int x, int y, int width, int height, uint8 colour) override {};
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override {};
void SetRect(void *video, int x, int y, const uint8 *colours, uint lines, uint width, uint pitch) override {};
void SetRect32(void *video, int x, int y, const uint32 *colours, uint lines, uint width, uint pitch) override {};
void SetPixel(void *video, int x, int y, uint8_t colour) override {};
void SetPixel32(void *video, int x, int y, uint8_t colour, uint32_t colour32) override {};
void DrawRect(void *video, int width, int height, uint8_t colour) override {};
void DrawRectAt(void *video, int x, int y, int width, int height, uint8_t colour) override {};
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override {};
void SetRect(void *video, int x, int y, const uint8_t *colours, uint lines, uint width, uint pitch) override {};
void SetRect32(void *video, int x, int y, const uint32_t *colours, uint lines, uint width, uint pitch) override {};
void CopyFromBuffer(void *video, const void *src, int width, int height) override {};
void CopyToBuffer(const void *video, void *dst, int width, int height) override {};
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override {};

@ -48,15 +48,15 @@ static inline byte ReadByte(BmpBuffer *buffer)
return buffer->data[buffer->pos++];
}
static inline uint16 ReadWord(BmpBuffer *buffer)
static inline uint16_t ReadWord(BmpBuffer *buffer)
{
uint16 var = ReadByte(buffer);
uint16_t var = ReadByte(buffer);
return var | (ReadByte(buffer) << 8);
}
static inline uint32 ReadDword(BmpBuffer *buffer)
static inline uint32_t ReadDword(BmpBuffer *buffer)
{
uint32 var = ReadWord(buffer);
uint32_t var = ReadWord(buffer);
return var | (ReadWord(buffer) << 16);
}
@ -316,7 +316,7 @@ static inline bool BmpRead24(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
*/
bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint32 header_size;
uint32_t header_size;
assert(info != nullptr);
MemSetT(info, 0);

@ -13,13 +13,13 @@
#include "gfx_type.h"
struct BmpInfo {
uint32 offset; ///< offset of bitmap data from .bmp file beginning
uint32 width; ///< bitmap width
uint32 height; ///< bitmap height
bool os2_bmp; ///< true if OS/2 1.x or windows 2.x bitmap
uint16 bpp; ///< bits per pixel
uint32 compression; ///< compression method (0 = none, 1 = 8-bit RLE, 2 = 4-bit RLE)
uint32 palette_size; ///< number of colours in palette
uint32_t offset; ///< offset of bitmap data from .bmp file beginning
uint32_t width; ///< bitmap width
uint32_t height; ///< bitmap height
bool os2_bmp; ///< true if OS/2 1.x or windows 2.x bitmap
uint16_t bpp; ///< bits per pixel
uint32_t compression; ///< compression method (0 = none, 1 = 8-bit RLE, 2 = 4-bit RLE)
uint32_t palette_size; ///< number of colours in palette
};
struct BmpData {

@ -64,9 +64,9 @@ enum BridgeSpecCtrlFlags {
struct BridgeSpec {
Year avail_year; ///< the year where it becomes available
byte min_length; ///< the minimum length (not counting start and end tile)
uint16 max_length; ///< the maximum length (not counting start and end tile)
uint16 price; ///< the price multiplier
uint16 speed; ///< maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
uint16_t max_length; ///< the maximum length (not counting start and end tile)
uint16_t price; ///< the price multiplier
uint16_t speed; ///< maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
SpriteID sprite; ///< the sprite which is used in the GUI
PaletteID pal; ///< the palette which is used in the GUI
StringID material; ///< the string that contains the bridge description

@ -59,7 +59,7 @@ typedef GUIList<BuildBridgeData> GUIBridgeList; ///< List of bridges, used in #B
* - p2 = (bit 15-16) - transport type.
* @param cmd unused
*/
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
{
if (result.Failed()) return;
if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
@ -92,7 +92,7 @@ private:
/* Internal variables */
TileIndex start_tile;
TileIndex end_tile;
uint32 type;
uint32_t type;
GUIBridgeList bridges;
int icon_width; ///< Scaled width of the the bridge icon sprite.
Scrollbar *vscroll;
@ -120,7 +120,7 @@ private:
return (TransportType)(this->type >> 15);
}
void BuildBridge(uint8 i)
void BuildBridge(uint8_t i)
{
switch (this->GetTransportType()) {
case TRANSPORT_RAIL: _last_railbridge_type = this->bridges.at(i).index; break;
@ -162,7 +162,7 @@ private:
}
public:
BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList &&bl) : Window(desc),
BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, uint32_t br_type, GUIBridgeList &&bl) : Window(desc),
start_tile(start),
end_tile(end),
type(br_type),
@ -226,7 +226,7 @@ public:
}
}
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
{
/* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
@ -258,9 +258,9 @@ public:
}
}
EventState OnKeyPress(WChar key, uint16 keycode) override
EventState OnKeyPress(char32_t key, uint16_t keycode) override
{
const uint8 i = keycode - '1';
const uint8_t i = keycode - '1';
if (i < 9 && i < this->bridges.size()) {
/* Build the requested bridge */
this->BuildBridge(i);
@ -381,7 +381,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
* Bit 16,15 = transport type,
* 14..8 = road/rail types,
* 7..0 = type of bridge */
uint32 type = (transport_type << 15) | (road_rail_type << 8);
uint32_t type = (transport_type << 15) | (road_rail_type << 8);
/* The bridge length without ramps. */
const uint bridge_len = GetTunnelBridgeLength(start, end);
@ -457,7 +457,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
item.spec = GetBridgeSpec(brd_type);
/* Add to terraforming & bulldozing costs the cost of the
* bridge itself (not computed with DC_QUERY_COST) */
item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
item.cost = ret.GetCost() + (((int64_t)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
any_available = true;
} else if (type_check.GetErrorMessage() != INVALID_STRING_ID && !query_per_bridge_type) {
type_errmsg = type_check.GetErrorMessage();

@ -82,14 +82,14 @@ int GetBridgeHeight(TileIndex t)
std::unordered_map<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map;
SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 signal)
SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal)
{
const auto it = _long_bridge_signal_sim_map.find(t);
if (it != _long_bridge_signal_sim_map.end()) {
const LongBridgeSignalStorage &lbss = it->second;
uint16 offset = signal - BRIDGE_M2_SIGNAL_STATE_COUNT;
uint16 slot = offset >> 6;
uint16 bit = offset & 0x3F;
uint16_t offset = signal - BRIDGE_M2_SIGNAL_STATE_COUNT;
uint16_t slot = offset >> 6;
uint16_t bit = offset & 0x3F;
if (slot >= lbss.signal_red_bits.size()) return SIGNAL_STATE_GREEN;
return GB(lbss.signal_red_bits[slot], bit, 1) ? SIGNAL_STATE_RED : SIGNAL_STATE_GREEN;
} else {
@ -97,14 +97,14 @@ SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 si
}
}
void SetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 signal, SignalState state)
void SetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal, SignalState state)
{
LongBridgeSignalStorage &lbss = _long_bridge_signal_sim_map[t];
uint16 offset = signal - BRIDGE_M2_SIGNAL_STATE_COUNT;
uint16 slot = offset >> 6;
uint16 bit = offset & 0x3F;
uint16_t offset = signal - BRIDGE_M2_SIGNAL_STATE_COUNT;
uint16_t slot = offset >> 6;
uint16_t bit = offset & 0x3F;
if (slot >= lbss.signal_red_bits.size()) lbss.signal_red_bits.resize(slot + 1);
SB(lbss.signal_red_bits[slot], bit, 1, (uint64) ((state == SIGNAL_STATE_RED) ? 1 : 0));
SB(lbss.signal_red_bits[slot], bit, 1, (uint64_t) ((state == SIGNAL_STATE_RED) ? 1 : 0));
_m[t].m2 |= BRIDGE_M2_SIGNAL_STATE_EXT_FLAG;
}
@ -132,7 +132,7 @@ void ClearBridgeEntranceSimulatedSignalsExtended(TileIndex t)
SB(_m[t].m2, BRIDGE_M2_SIGNAL_STATE_OFFSET, BRIDGE_M2_SIGNAL_STATE_FIELD_SIZE, 0);
}
void ShiftBridgeEntranceSimulatedSignalsExtended(TileIndex t, int shift, uint64 in)
void ShiftBridgeEntranceSimulatedSignalsExtended(TileIndex t, int shift, uint64_t in)
{
if (shift > 0) {
/* shift into array */
@ -147,7 +147,7 @@ void ShiftBridgeEntranceSimulatedSignalsExtended(TileIndex t, int shift, uint64
}
const size_t orig_size = lbss->signal_red_bits.size();
size_t i = orig_size;
auto insert_bits = [&](uint64 bits, size_t pos) {
auto insert_bits = [&](uint64_t bits, size_t pos) {
if (bits) {
if (pos >= lbss->signal_red_bits.size()) lbss->signal_red_bits.resize(pos + 1);
lbss->signal_red_bits[pos] |= bits;
@ -155,7 +155,7 @@ void ShiftBridgeEntranceSimulatedSignalsExtended(TileIndex t, int shift, uint64
};
while (i) {
i--;
uint64 out = GB(lbss->signal_red_bits[i], 64 - shift, shift);
uint64_t out = GB(lbss->signal_red_bits[i], 64 - shift, shift);
lbss->signal_red_bits[i] <<= shift;
insert_bits(out, i + 1);
}
@ -171,11 +171,11 @@ void ClearBridgeSimulatedSignalMapping()
_long_bridge_signal_sim_map.clear();
}
btree::btree_set<uint32> _bridge_signal_style_map;
btree::btree_set<uint32_t> _bridge_signal_style_map;
static_assert(MAX_MAP_TILES_BITS + 4 <= 32);
static_assert(1 << 4 <= MAX_NEW_SIGNAL_STYLES + 1);
void SetBridgeSignalStyle(TileIndex t, uint8 style)
void SetBridgeSignalStyle(TileIndex t, uint8_t style)
{
if (style == 0) {
/* No style allocated before */
@ -192,7 +192,7 @@ void SetBridgeSignalStyle(TileIndex t, uint8 style)
}
}
uint8 GetBridgeSignalStyleExtended(TileIndex t)
uint8_t GetBridgeSignalStyleExtended(TileIndex t)
{
auto iter = _bridge_signal_style_map.lower_bound(t << 4);
if (iter != _bridge_signal_style_map.end() && *iter >> 4 == t) return (*iter) & 0xF;

@ -20,14 +20,14 @@
#include <unordered_map>
struct LongBridgeSignalStorage {
std::vector<uint64> signal_red_bits;
std::vector<uint64_t> signal_red_bits;
};
extern std::unordered_map<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map;
extern btree::btree_set<uint32> _bridge_signal_style_map;
extern btree::btree_set<uint32_t> _bridge_signal_style_map;
SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 signal);
SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal);
enum {
BRIDGE_M2_SIGNAL_STATE_COUNT = 11,
@ -36,7 +36,7 @@ enum {
BRIDGE_M2_SIGNAL_STATE_EXT_FLAG = 0x8000,
};
inline SignalState GetBridgeEntranceSimulatedSignalState(TileIndex t, uint16 signal)
inline SignalState GetBridgeEntranceSimulatedSignalState(TileIndex t, uint16_t signal)
{
if (signal < BRIDGE_M2_SIGNAL_STATE_COUNT) {
return GB(_m[t].m2, signal + BRIDGE_M2_SIGNAL_STATE_OFFSET, 1) ? SIGNAL_STATE_RED : SIGNAL_STATE_GREEN;
@ -45,9 +45,9 @@ inline SignalState GetBridgeEntranceSimulatedSignalState(TileIndex t, uint16 sig
}
}
void SetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 signal, SignalState state);
void SetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal, SignalState state);
inline void SetBridgeEntranceSimulatedSignalState(TileIndex t, uint16 signal, SignalState state)
inline void SetBridgeEntranceSimulatedSignalState(TileIndex t, uint16_t signal, SignalState state)
{
if (signal < BRIDGE_M2_SIGNAL_STATE_COUNT) {
SB(_m[t].m2, signal + BRIDGE_M2_SIGNAL_STATE_OFFSET, 1, (state == SIGNAL_STATE_RED) ? 1 : 0);
@ -82,13 +82,13 @@ inline void ClearBridgeEntranceSimulatedSignals(TileIndex t)
void ClearBridgeSimulatedSignalMapping();
void SetBridgeSignalStyle(TileIndex t, uint8 style);
void SetBridgeSignalStyle(TileIndex t, uint8_t style);
inline uint8 GetBridgeSignalStyle(TileIndex t)
inline uint8_t GetBridgeSignalStyle(TileIndex t)
{
if (likely(!HasBit(_m[t].m3, 7))) return 0;
extern uint8 GetBridgeSignalStyleExtended(TileIndex t);
extern uint8_t GetBridgeSignalStyleExtended(TileIndex t);
return GetBridgeSignalStyleExtended(t);
}

@ -573,7 +573,7 @@ static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngin
const Engine *e_a = Engine::Get(a.engine_id);
const Engine *e_b = Engine::Get(b.engine_id);
uint16 mail_a, mail_b;
uint16_t mail_a, mail_b;
int va = e_a->GetDisplayDefaultCapacity(&mail_a);
int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
int r = va - vb;
@ -601,7 +601,7 @@ static bool AircraftEngineCapacityVsRunningCostSorter(const GUIEngineListItem &a
const Engine *e_a = Engine::Get(a.engine_id);
const Engine *e_b = Engine::Get(b.engine_id);
uint16 mail_a, mail_b;
uint16_t mail_a, mail_b;
int va = e_a->GetDisplayDefaultCapacity(&mail_a);
int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
@ -616,8 +616,8 @@ static bool AircraftEngineCapacityVsRunningCostSorter(const GUIEngineListItem &a
*/
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
{
uint16 r_a = Engine::Get(a.engine_id)->GetRange();
uint16 r_b = Engine::Get(b.engine_id)->GetRange();
uint16_t r_a = Engine::Get(a.engine_id)->GetRange();
uint16_t r_b = Engine::Get(b.engine_id)->GetRange();
int r = r_a - r_b;
@ -904,7 +904,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
y += GetCharacterHeight(FS_NORMAL);
/* Road vehicle weight - (including cargo) */
int16 weight = e->GetDisplayWeight();
int16_t weight = e->GetDisplayWeight();
SetDParam(0, weight);
SetDParam(1, GetCargoWeight(te.all_capacities, VEH_ROAD) + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
@ -1056,7 +1056,7 @@ static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_
y += GetCharacterHeight(FS_NORMAL);
/* Aircraft range, if available. */
uint16 range = e->GetRange();
uint16_t range = e->GetRange();
if (range != 0) {
SetDParam(0, range);
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
@ -1074,7 +1074,7 @@ static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_
*/
static std::optional<std::string> GetNewGRFAdditionalText(EngineID engine)
{
uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
uint16_t callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
if (callback == CALLBACK_FAILED || callback == 0x400) return std::nullopt;
const GRFFile *grffile = Engine::Get(engine)->GetGRF();
assert(grffile != nullptr);
@ -1217,7 +1217,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,
* @param show_count Whether to show the amount of engines or not
* @param selected_group the group to list the engines of
*/
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16_t min, uint16_t max, EngineID selected_id, bool show_count, GroupID selected_group)
{
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
@ -1314,7 +1314,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
*/
void DisplayVehicleSortDropDown(Window *w, const VehicleType vehicle_type, const int selected, const int button)
{
uint32 hidden_mask = 0;
uint32_t hidden_mask = 0;
/* Disable sorting by power or tractive effort when the original acceleration model for road vehicles is being used. */
if (vehicle_type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
SetBit(hidden_mask, 3); // power
@ -1925,7 +1925,7 @@ struct BuildVehicleWindow : BuildVehicleWindowBase {
EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) {
CommandCallback *callback;
uint32 cmd;
uint32_t cmd;
if (this->virtual_train_mode) {
callback = CcAddVirtualEngine;
cmd = CMD_BUILD_VIRTUAL_RAIL_VEHICLE;
@ -2072,7 +2072,7 @@ struct BuildVehicleWindow : BuildVehicleWindowBase {
r,
this->eng_list,
this->vscroll->GetPosition(),
static_cast<uint16>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
static_cast<uint16_t>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
this->sel_engine,
false,
DEFAULT_GROUP
@ -2247,7 +2247,7 @@ static const StringID _sort_listing_wagon[8] = {
*/
void DisplayLocomotiveSortDropDown(Window *w, int selected)
{
uint32 hidden_mask = 0;
uint32_t hidden_mask = 0;
/* Disable sorting by tractive effort when the original acceleration model for trains is being used. */
if (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
SetBit(hidden_mask, 4); // tractive effort
@ -2262,7 +2262,7 @@ void DisplayLocomotiveSortDropDown(Window *w, int selected)
*/
void DisplayWagonSortDropDown(Window *w, int selected)
{
uint32 hidden_mask = 0;
uint32_t hidden_mask = 0;
/* Disable sorting by maximum speed when wagon speed is disabled. */
if (!_settings_game.vehicle.wagon_speed_limits) {
SetBit(hidden_mask, 2); // maximum speed
@ -2700,7 +2700,7 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase {
{
if (selected != INVALID_ENGINE) {
CommandCallback *callback;
uint32 cmd;
uint32_t cmd;
if (this->virtual_train_mode) {
callback = CcAddVirtualEngine;
cmd = CMD_BUILD_VIRTUAL_RAIL_VEHICLE;
@ -3058,8 +3058,8 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase {
case WID_BV_LIST_LOCO: {
DrawEngineList(this->vehicle_type, r,
this->loco.eng_list, this->loco.vscroll->GetPosition(),
std::min<uint16>(this->loco.vscroll->GetPosition() + this->loco.vscroll->GetCapacity(),
static_cast<uint16>(this->loco.eng_list.size())), this->loco.sel_engine, false,
std::min<uint16_t>(this->loco.vscroll->GetPosition() + this->loco.vscroll->GetCapacity(),
static_cast<uint16_t>(this->loco.eng_list.size())), this->loco.sel_engine, false,
DEFAULT_GROUP);
break;
}
@ -3072,8 +3072,8 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase {
case WID_BV_LIST_WAGON: {
DrawEngineList(this->vehicle_type, r,
this->wagon.eng_list, this->wagon.vscroll->GetPosition(),
std::min<uint16>(this->wagon.vscroll->GetPosition() + this->wagon.vscroll->GetCapacity(),
static_cast<uint16>(this->wagon.eng_list.size())), this->wagon.sel_engine, false,
std::min<uint16_t>(this->wagon.vscroll->GetPosition() + this->wagon.vscroll->GetCapacity(),
static_cast<uint16_t>(this->wagon.eng_list.size())), this->wagon.sel_engine, false,
DEFAULT_GROUP);
break;
}
@ -3229,7 +3229,7 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase {
}
};
void CcAddVirtualEngine(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
void CcAddVirtualEngine(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
{
if (result.Failed()) return;
@ -3243,7 +3243,7 @@ void CcAddVirtualEngine(const CommandCost &result, TileIndex tile, uint32 p1, ui
}
}
void CcMoveNewVirtualEngine(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd)
void CcMoveNewVirtualEngine(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd)
{
if (result.Failed()) return;

@ -77,7 +77,7 @@ inline bool IsValidCargoType(CargoType t) { return t != CT_INVALID; }
/** Test whether cargo type is not CT_INVALID */
inline bool IsValidCargoID(CargoID t) { return t != CT_INVALID; }
typedef uint64 CargoTypes;
typedef uint64_t CargoTypes;
static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX;
@ -123,7 +123,7 @@ enum class SourceType : byte {
Headquarters, ///< Source/destination are company headquarters
};
typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
typedef uint16_t SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
#endif /* CARGO_TYPE_H */

@ -66,17 +66,17 @@ void ClearCargoDeliveryMonitoring(CompanyID company)
* @param keep_monitoring After returning from this call, continue monitoring.
* @return Amount collected since last query/activation for the monitored combination.
*/
static int32 GetAmount(CargoMonitorMap &monitor_map, CargoMonitorID monitor, bool keep_monitoring)
static int32_t GetAmount(CargoMonitorMap &monitor_map, CargoMonitorID monitor, bool keep_monitoring)
{
CargoMonitorMap::iterator iter = monitor_map.find(monitor);
if (iter == monitor_map.end()) {
if (keep_monitoring) {
std::pair<CargoMonitorID, uint32> p(monitor, 0);
std::pair<CargoMonitorID, uint32_t> p(monitor, 0);
monitor_map.insert(p);
}
return 0;
} else {
int32 result = iter->second;
int32_t result = iter->second;
iter->second = 0;
if (!keep_monitoring) monitor_map.erase(iter);
return result;
@ -89,7 +89,7 @@ static int32 GetAmount(CargoMonitorMap &monitor_map, CargoMonitorID monitor, boo
* @param keep_monitoring After returning from this call, continue monitoring.
* @return Amount of delivered cargo for the monitored combination.
*/
int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring)
int32_t GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring)
{
return GetAmount(_cargo_deliveries, monitor, keep_monitoring);
}
@ -101,7 +101,7 @@ int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring)
* @return Amount of picked up cargo for the monitored combination.
* @note Cargo pick up is counted on final delivery, to prevent users getting credit for picking up cargo without delivering it.
*/
int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring)
int32_t GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring)
{
return GetAmount(_cargo_pickups, monitor, keep_monitoring);
}
@ -116,7 +116,7 @@ int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring)
* @param st station where the cargo is delivered to.
* @param dest industry index where the cargo is delivered to.
*/
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest)
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32_t amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest)
{
if (amount == 0) return;

@ -26,7 +26,7 @@ struct Station;
* - bits 19-23 Cargo type.
* - bits 24-31 %Company number.
*/
typedef uint32 CargoMonitorID; ///< Type of the cargo monitor number.
typedef uint32_t CargoMonitorID; ///< Type of the cargo monitor number.
/** Map type for storing and updating active cargo monitor numbers and their amounts. */
typedef btree::btree_map<CargoMonitorID, OverflowSafeInt32> CargoMonitorMap;
@ -63,7 +63,7 @@ inline CargoMonitorID EncodeCargoIndustryMonitor(CompanyID company, CargoID ctyp
assert(ctype < (1 << CCB_CARGO_TYPE_LENGTH));
assert(company < (1 << CCB_COMPANY_LENGTH));
uint32 ret = 0;
uint32_t ret = 0;
SB(ret, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH, ind);
SetBit(ret, CCB_IS_INDUSTRY_BIT);
SB(ret, CCB_CARGO_TYPE_START, CCB_CARGO_TYPE_LENGTH, ctype);
@ -83,7 +83,7 @@ inline CargoMonitorID EncodeCargoTownMonitor(CompanyID company, CargoID ctype, T
assert(ctype < (1 << CCB_CARGO_TYPE_LENGTH));
assert(company < (1 << CCB_COMPANY_LENGTH));
uint32 ret = 0;
uint32_t ret = 0;
SB(ret, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH, town);
SB(ret, CCB_CARGO_TYPE_START, CCB_CARGO_TYPE_LENGTH, ctype);
SB(ret, CCB_COMPANY_START, CCB_COMPANY_LENGTH, company);
@ -144,8 +144,8 @@ inline TownID DecodeMonitorTown(CargoMonitorID num)
void ClearCargoPickupMonitoring(CompanyID company = INVALID_OWNER);
void ClearCargoDeliveryMonitoring(CompanyID company = INVALID_OWNER);
int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring);
int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring);
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest = INVALID_INDUSTRY);
int32_t GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring);
int32_t GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring);
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32_t amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest = INVALID_INDUSTRY);
#endif /* CARGOMONITOR_H */

@ -28,7 +28,7 @@
CargoPacketPool _cargopacket_pool("CargoPacket");
INSTANTIATE_POOL_METHODS(CargoPacket)
btree::btree_map<uint64, Money> _cargo_packet_deferred_payments;
btree::btree_map<uint64_t, Money> _cargo_packet_deferred_payments;
void ClearCargoPacketDeferredPayments() {
_cargo_packet_deferred_payments.clear();
@ -36,10 +36,10 @@ void ClearCargoPacketDeferredPayments() {
void ChangeOwnershipOfCargoPacketDeferredPayments(Owner old_owner, Owner new_owner)
{
std::vector<std::pair<uint64, Money>> to_merge;
std::vector<std::pair<uint64_t, Money>> to_merge;
auto iter = _cargo_packet_deferred_payments.begin();
while (iter != _cargo_packet_deferred_payments.end()) {
uint64 k = iter->first;
uint64_t k = iter->first;
if ((CompanyID) GB(k, 24, 8) == old_owner) {
if (new_owner != INVALID_OWNER) {
SB(k, 24, 8, new_owner);
@ -55,9 +55,9 @@ void ChangeOwnershipOfCargoPacketDeferredPayments(Owner old_owner, Owner new_own
}
}
inline uint64 CargoPacketDeferredPaymentKey(CargoPacketID id, CompanyID cid, VehicleType type)
inline uint64_t CargoPacketDeferredPaymentKey(CargoPacketID id, CompanyID cid, VehicleType type)
{
return (((uint64) id) << 32) | (cid << 24) | (type << 22);
return (((uint64_t) id) << 32) | (cid << 24) | (type << 22);
}
template <typename F>
@ -194,7 +194,7 @@ CargoPacket *CargoPacket::Split(uint new_size)
this->feeder_share -= fs;
if (this->flags & CPF_HAS_DEFERRED_PAYMENT) {
std::vector<std::pair<uint64, Money>> to_add;
std::vector<std::pair<uint64_t, Money>> to_add;
IterateCargoPacketDeferredPayments(this->index, false, [&](Money &payment, CompanyID cid, VehicleType type) {
Money share = payment * new_size / static_cast<uint>(this->count);
payment -= share;
@ -220,7 +220,7 @@ void CargoPacket::Merge(CargoPacket *cp)
this->feeder_share += cp->feeder_share;
if (cp->flags & CPF_HAS_DEFERRED_PAYMENT) {
std::vector<std::pair<uint64, Money>> to_merge;
std::vector<std::pair<uint64_t, Money>> to_merge;
IterateCargoPacketDeferredPayments(cp->index, true, [&](Money &payment, CompanyID cid, VehicleType type) {
to_merge.push_back({ CargoPacketDeferredPaymentKey(this->index, cid, type), payment });
});

@ -23,7 +23,7 @@
#include "3rdparty/cpp-btree/btree_map.h"
/** Unique identifier for a single cargo packet. */
typedef uint32 CargoPacketID;
typedef uint32_t CargoPacketID;
struct CargoPacket;
/** Type of the pool for cargo packets for a little over 16 million packets. */
@ -57,14 +57,14 @@ private:
int32_t y;
};
uint16 count = 0; ///< The amount of cargo in this packet.
uint16 periods_in_transit = 0; ///< Amount of cargo aging periods this packet has been in transit.
uint16_t count = 0; ///< The amount of cargo in this packet.
uint16_t periods_in_transit = 0; ///< Amount of cargo aging periods this packet has been in transit.
Money feeder_share = 0; ///< Value of feeder pickup to be paid for on delivery of cargo.
TileIndex source_xy = INVALID_TILE; ///< The origin of the cargo.
Vector travelled = {0, 0}; ///< If cargo is in station: the vector from the unload tile to the source tile. If in vehicle: an intermediate value.
SourceID source_id = INVALID_SOURCE; ///< Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
SourceType source_type = SourceType::Industry; ///< Type of \c source_id.
uint8 flags = 0; ///< NOSAVE: temporary flags
uint8_t flags = 0; ///< NOSAVE: temporary flags
StationID first_station = INVALID_STATION; ///< The station where the cargo came from first.
StationID next_hop = INVALID_STATION; ///< Station where the cargo wants to go next.
@ -84,7 +84,7 @@ private:
friend void Load_CPDP();
public:
/** Maximum number of items in a single cargo packet. */
static const uint16 MAX_COUNT = UINT16_MAX;
static const uint16_t MAX_COUNT = UINT16_MAX;
CargoPacket();
CargoPacket(StationID first_station, uint16_t count, SourceType source_type, SourceID source_id);
@ -166,7 +166,7 @@ public:
* Gets the number of 'items' in this packet.
* @return Item count.
*/
inline uint16 Count() const
inline uint16_t Count() const
{
return this->count;
}
@ -201,7 +201,7 @@ public:
* it is capped at UINT16_MAX.
* @return Length this cargo has been in transit.
*/
inline uint16 GetPeriodsInTransit() const
inline uint16_t GetPeriodsInTransit() const
{
return this->periods_in_transit;
}
@ -318,10 +318,10 @@ public:
};
protected:
uint count; ///< Cache for the number of cargo entities.
uint64 cargo_periods_in_transit; ///< Cache for the sum of number of cargo aging periods in transit of each entity; comparable to man-hours.
uint count; ///< Cache for the number of cargo entities.
uint64_t cargo_periods_in_transit; ///< Cache for the sum of number of cargo aging periods in transit of each entity; comparable to man-hours.
Tcont packets; ///< The cargo packets in this list.
Tcont packets; ///< The cargo packets in this list.
void AddToCache(const CargoPacket *cp);
@ -364,7 +364,7 @@ public:
return this->count;
}
inline uint64 CargoPeriodsInTransit() const
inline uint64_t CargoPeriodsInTransit() const
{
return this->cargo_periods_in_transit;
}

@ -128,7 +128,7 @@ CargoID GetCargoIDByLabel(CargoLabel cl)
* @param bitnum 'bitnum' to find.
* @return First CargoID with the given bitnum, or #CT_INVALID if not found or if the provided \a bitnum is invalid.
*/
CargoID GetCargoIDByBitnum(uint8 bitnum)
CargoID GetCargoIDByBitnum(uint8_t bitnum)
{
if (bitnum == INVALID_CARGO_BITNUM) return CT_INVALID;
@ -209,7 +209,7 @@ void InitializeSortedCargoSpecs()
/* Count the number of standard cargos and fill the mask. */
_standard_cargo_mask = 0;
uint8 nb_standard_cargo = 0;
uint8_t nb_standard_cargo = 0;
for (const auto &cargo : _sorted_cargo_specs) {
if (cargo->classes & CC_SPECIAL) break;
nb_standard_cargo++;
@ -220,7 +220,7 @@ void InitializeSortedCargoSpecs()
_sorted_standard_cargo_specs = { _sorted_cargo_specs.data(), nb_standard_cargo };
}
uint64 CargoSpec::WeightOfNUnitsInTrain(uint32 n) const
uint64_t CargoSpec::WeightOfNUnitsInTrain(uint32_t n) const
{
if (this->is_freight) n *= _settings_game.vehicle.freight_trains;
return this->WeightOfNUnits(n);

@ -20,7 +20,7 @@
#include <vector>
/** Globally unique label of a cargo type. */
typedef uint32 CargoLabel;
typedef uint32_t CargoLabel;
/** Town growth effect when delivering cargo. */
enum TownEffect {
@ -55,29 +55,29 @@ static const byte INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invali
/** Specification of a cargo type. */
struct CargoSpec {
CargoLabel label; ///< Unique label of the cargo type.
uint8 bitnum{INVALID_CARGO_BITNUM}; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec.
uint8 legend_colour;
uint8 rating_colour;
uint8 weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
uint16 multiplier{0x100}; ///< Capacity multiplier for vehicles. (8 fractional bits)
uint16 classes; ///< Classes of this cargo type. @see CargoClass
int32 initial_payment; ///< Initial payment rate before inflation is applied.
uint8 transit_periods[2];
bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier).
TownEffect town_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
uint8 callback_mask; ///< Bitmask of cargo callbacks that have to be called
StringID name; ///< Name of this type of cargo.
StringID name_single; ///< Name of a single entity of this type of cargo.
StringID units_volume; ///< Name of a single unit of cargo of this type.
StringID quantifier; ///< Text for multiple units of cargo of this type.
StringID abbrev; ///< Two letter abbreviation for this cargo type.
SpriteID sprite; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain).
const struct GRFFile *grffile; ///< NewGRF where #group belongs to.
CargoLabel label; ///< Unique label of the cargo type.
uint8_t bitnum{INVALID_CARGO_BITNUM}; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec.
uint8_t legend_colour;
uint8_t rating_colour;
uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
uint16_t multiplier{0x100}; ///< Capacity multiplier for vehicles. (8 fractional bits)
uint16_t classes; ///< Classes of this cargo type. @see CargoClass
int32_t initial_payment; ///< Initial payment rate before inflation is applied.
uint8_t transit_periods[2];
bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier).
TownEffect town_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
uint8_t callback_mask; ///< Bitmask of cargo callbacks that have to be called
StringID name; ///< Name of this type of cargo.
StringID name_single; ///< Name of a single entity of this type of cargo.
StringID units_volume; ///< Name of a single unit of cargo of this type.
StringID quantifier; ///< Text for multiple units of cargo of this type.
StringID abbrev; ///< Two letter abbreviation for this cargo type.
SpriteID sprite; ///< Icon to display this cargo type, may be \c 0xFFF (which means to resolve an action123 chain).
const struct GRFFile *grffile; ///< NewGRF where #group belongs to.
const struct SpriteGroup *group;
Money current_payment;
@ -132,12 +132,12 @@ struct CargoSpec {
SpriteID GetCargoIcon() const;
inline uint64 WeightOfNUnits(uint32 n) const
inline uint64_t WeightOfNUnits(uint32_t n) const
{
return n * this->weight / 16u;
}
uint64 WeightOfNUnitsInTrain(uint32 n) const;
uint64_t WeightOfNUnitsInTrain(uint32_t n) const;
/**
* Iterator to iterate all valid CargoSpec
@ -193,7 +193,7 @@ extern CargoTypes _standard_cargo_mask;
void SetupCargoForClimate(LandscapeID l);
CargoID GetCargoIDByLabel(CargoLabel cl);
CargoID GetCargoIDByBitnum(uint8 bitnum);
CargoID GetCargoIDByBitnum(uint8_t bitnum);
CargoID GetDefaultCargoID(LandscapeID l, CargoType ct);
Dimension GetLargestCargoIconSize();

@ -45,7 +45,7 @@
* This variable is semantically a constant value, but because the cheat
* code requires to be able to write to the variable it is not constified.
*/
static int32 _money_cheat_amount = 10000000;
static int32_t _money_cheat_amount = 10000000;
/**
* Handle cheating of money.
@ -56,9 +56,9 @@ static int32 _money_cheat_amount = 10000000;
* @param p2 is -1 or +1 (down/up)
* @return Amount of money cheat.
*/
static int32 ClickMoneyCheat(int32 p1, int32 p2)
static int32_t ClickMoneyCheat(int32_t p1, int32_t p2)
{
DoCommandPEx(0, 0, 0, (uint64)(p2 * _money_cheat_amount), _network_server || _network_settings_access ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT);
DoCommandPEx(0, 0, 0, (uint64_t)(p2 * _money_cheat_amount), _network_server || _network_settings_access ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT);
return _money_cheat_amount;
}
@ -68,7 +68,7 @@ static int32 ClickMoneyCheat(int32 p1, int32 p2)
* @param p2 is -1 or +1 (down/up)
* @return The new company.
*/
static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
static int32_t ClickChangeCompanyCheat(int32_t p1, int32_t p2)
{
while ((uint)p1 < Company::GetPoolSize()) {
if (Company::IsValidID((CompanyID)p1)) {
@ -87,7 +87,7 @@ static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
* @param p2 unused
* @return New value allowing change of industry production.
*/
static int32 ClickSetProdCheat(int32 p1, int32 p2)
static int32_t ClickSetProdCheat(int32_t p1, int32_t p2)
{
_cheats.setup_prod.value = (p1 != 0);
InvalidateWindowClassesData(WC_INDUSTRY_VIEW);
@ -102,7 +102,7 @@ extern void EnginesMonthlyLoop();
* @param p2 +1 (increase) or -1 (decrease).
* @return New year.
*/
static int32 ClickChangeDateCheat(int32 p1, int32 p2)
static int32_t ClickChangeDateCheat(int32_t p1, int32_t p2)
{
/* Don't allow changing to an invalid year, or the current year. */
p1 = Clamp(p1, MIN_YEAR, MAX_YEAR);
@ -135,14 +135,14 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
* @return New value (or unchanged old value) of the maximum
* allowed heightlevel value.
*/
static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2)
static int32_t ClickChangeMaxHlCheat(int32_t p1, int32_t p2)
{
p1 = Clamp(p1, MIN_MAP_HEIGHT_LIMIT, MAX_MAP_HEIGHT_LIMIT);
/* Check if at least one mountain on the map is higher than the new value.
* If yes, disallow the change. */
for (TileIndex t = 0; t < MapSize(); t++) {
if ((int32)TileHeight(t) > p1) {
if ((int32_t)TileHeight(t) > p1) {
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
/* Return old, unchanged value */
return _settings_game.construction.map_height_limit;
@ -164,7 +164,7 @@ static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2)
* @param p1 The new value.
* @param p2 Change direction (+1, +1), \c 0 for boolean settings.
*/
typedef int32 CheckButtonClick(int32 p1, int32 p2);
typedef int32_t CheckButtonClick(int32_t p1, int32_t p2);
enum CheatNetworkMode {
CNM_ALL,
@ -282,7 +282,7 @@ struct CheatWindow : Window {
/* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(button_left, y + button_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
uint64 val = (uint64)ReadValue(ce->variable, SLE_UINT64);
uint64_t val = (uint64_t)ReadValue(ce->variable, SLE_UINT64);
SetDParam(0, val * 1000 >> 16);
SetDParam(1, 3);
break;
@ -297,7 +297,7 @@ struct CheatWindow : Window {
}
default: {
int32 val = (int32)ReadValue(ce->variable, ce->type);
int32_t val = (int32_t)ReadValue(ce->variable, ce->type);
/* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(button_left, y + button_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
@ -397,7 +397,7 @@ struct CheatWindow : Window {
if (btn >= lengthof(_cheats_ui)) return;
const CheatEntry *ce = &_cheats_ui[btn];
int value = (int32)ReadValue(ce->variable, ce->type);
int value = (int32_t)ReadValue(ce->variable, ce->type);
int oldvalue = value;
if (btn == CHT_CHANGE_DATE && x >= WidgetDimensions::scaled.hsep_wide * 2 + this->box.width + SETTING_BUTTON_WIDTH) {
@ -418,7 +418,7 @@ struct CheatWindow : Window {
return;
} else if (ce->type == SLF_ALLOW_CONTROL && x >= 20 + this->box.width + SETTING_BUTTON_WIDTH) {
clicked_widget = btn;
uint64 val = (uint64)ReadValue(ce->variable, SLE_UINT64);
uint64_t val = (uint64_t)ReadValue(ce->variable, SLE_UINT64);
SetDParam(0, val * 1000 >> 16);
SetDParam(1, 3);
StringID str = (btn == CHT_INFLATION_COST) ? STR_CHEAT_INFLATION_COST_QUERY_CAPT : STR_CHEAT_INFLATION_INCOME_QUERY_CAPT;
@ -445,10 +445,10 @@ struct CheatWindow : Window {
switch (ce->type) {
case SLF_ALLOW_CONTROL: {
/* Change inflation factors */
uint64 oldvalue = (uint64)ReadValue(ce->variable, SLE_UINT64);
uint64 value = oldvalue + (uint64)(get_arrow_button_value() << 16);
value = Clamp<uint64>(value, 1 << 16, MAX_INFLATION);
DoCommandP(0, (uint32)btn, (uint32)value, CMD_CHEAT_SETTING);
uint64_t oldvalue = (uint64_t)ReadValue(ce->variable, SLE_UINT64);
uint64_t value = oldvalue + (uint64_t)(get_arrow_button_value() << 16);
value = Clamp<uint64_t>(value, 1 << 16, MAX_INFLATION);
DoCommandP(0, (uint32_t)btn, (uint32_t)value, CMD_CHEAT_SETTING);
if (value != oldvalue) register_arrow_button_clicked();
break;
}
@ -470,9 +470,9 @@ struct CheatWindow : Window {
if (value != oldvalue) {
if (_networking || btn == CHT_STATION_RATING || btn == CHT_TOWN_RATING) {
if (btn != CHT_MONEY) DoCommandP(0, (uint32)btn, (uint32)value, CMD_CHEAT_SETTING);
if (btn != CHT_MONEY) DoCommandP(0, (uint32_t)btn, (uint32_t)value, CMD_CHEAT_SETTING);
} else {
WriteValue(ce->variable, ce->type, (int64)value);
WriteValue(ce->variable, ce->type, (int64_t)value);
}
}
@ -498,7 +498,7 @@ struct CheatWindow : Window {
char tmp_buffer[32];
strecpy(tmp_buffer, str, lastof(tmp_buffer));
str_replace_wchar(tmp_buffer, lastof(tmp_buffer), GetDecimalSeparatorChar(), '.');
DoCommandP(0, (uint32)clicked_widget, (uint32)Clamp<uint64>(atof(tmp_buffer) * 65536.0, 1 << 16, MAX_INFLATION), CMD_CHEAT_SETTING);
DoCommandP(0, (uint32_t)clicked_widget, (uint32_t)Clamp<uint64_t>(atof(tmp_buffer) * 65536.0, 1 << 16, MAX_INFLATION), CMD_CHEAT_SETTING);
return;
}
if (ce->mode == CNM_MONEY) {
@ -508,12 +508,12 @@ struct CheatWindow : Window {
}
if (_networking) return;
int oldvalue = (int32)ReadValue(ce->variable, ce->type);
int oldvalue = (int32_t)ReadValue(ce->variable, ce->type);
int value = atoi(str);
*ce->been_used = true;
value = ce->proc(value, value - oldvalue);
if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64_t)value);
this->SetDirty();
}
};

@ -80,7 +80,7 @@ inline SpriteID GetSpriteIDForRocksUsingOffset(const uint slope_to_sprite_offset
return ((HasGrfMiscBit(GMB_SECOND_ROCKY_TILE_SET) && (TileHash(x, y) & 1)) ? SPR_FLAT_ROCKY_LAND_2 : SPR_FLAT_ROCKY_LAND_1) + slope_to_sprite_offset;
}
bool DrawCustomSpriteIDForRocks(const TileInfo *ti, uint8 slope_to_sprite_offset, bool require_snow_flag)
bool DrawCustomSpriteIDForRocks(const TileInfo *ti, uint8_t slope_to_sprite_offset, bool require_snow_flag)
{
for (const GRFFile *grf : _new_landscape_rocks_grfs) {
if (require_snow_flag && !HasBit(grf->new_landscape_ctrl_flags, NLCF_ROCKS_DRAW_SNOWY_ENABLED)) continue;
@ -166,7 +166,7 @@ static void DrawTile_Clear(TileInfo *ti, DrawTileProcParams params)
case CLEAR_ROCKS:
if (!params.no_ground_tiles) {
uint8 slope_to_sprite_offset = SlopeToSpriteOffset(ti->tileh);
uint8_t slope_to_sprite_offset = SlopeToSpriteOffset(ti->tileh);
if (DrawCustomSpriteIDForRocks(ti, slope_to_sprite_offset, false)) break;
DrawGroundSprite(GetSpriteIDForRocksUsingOffset(slope_to_sprite_offset, ti->x, ti->y), PAL_NONE);
}
@ -181,7 +181,7 @@ static void DrawTile_Clear(TileInfo *ti, DrawTileProcParams params)
case CLEAR_SNOW:
if (!params.no_ground_tiles) {
uint8 slope_to_sprite_offset = SlopeToSpriteOffset(ti->tileh);
uint8_t slope_to_sprite_offset = SlopeToSpriteOffset(ti->tileh);
if (GetRawClearGround(ti->tile) == CLEAR_ROCKS && !_new_landscape_rocks_grfs.empty()) {
if (DrawCustomSpriteIDForRocks(ti, slope_to_sprite_offset, true)) break;
}
@ -401,7 +401,7 @@ void GenerateClearTile()
/* add rocky tiles */
i = gi;
do {
uint32 r = Random();
uint32_t r = Random();
tile = RandomTileSeed(r);
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);

@ -585,7 +585,7 @@ ClientID _cmd_client_id = INVALID_CLIENT_ID;
/**
* List of flags for a command log entry
*/
enum CommandLogEntryFlag : uint16 {
enum CommandLogEntryFlag : uint16_t {
CLEF_NONE = 0x00, ///< no flag is set
CLEF_CMD_FAILED = 0x01, ///< command failed
CLEF_GENERATING_WORLD = 0x02, ///< generating world
@ -602,27 +602,27 @@ enum CommandLogEntryFlag : uint16 {
};
DECLARE_ENUM_AS_BIT_SET(CommandLogEntryFlag)
extern uint32 _frame_counter;
extern uint32_t _frame_counter;
struct CommandLogEntry {
std::string text;
TileIndex tile;
uint32 p1;
uint32 p2;
uint32 cmd;
uint64 p3;
uint32_t p1;
uint32_t p2;
uint32_t cmd;
uint64_t p3;
Date date;
DateFract date_fract;
uint8 tick_skip_counter;
uint8_t tick_skip_counter;
CompanyID current_company;
CompanyID local_company;
CommandLogEntryFlag log_flags;
ClientID client_id;
uint32 frame_counter;
uint32_t frame_counter;
CommandLogEntry() { }
CommandLogEntry(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandLogEntryFlag log_flags, std::string text)
CommandLogEntry(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandLogEntryFlag log_flags, std::string text)
: text(text), tile(tile), p1(p1), p2(p2), cmd(cmd), p3(p3), date(_date), date_fract(_date_fract), tick_skip_counter(_tick_skip_counter),
current_company(_current_company), local_company(_local_company), log_flags(log_flags), client_id(_cmd_client_id), frame_counter(_frame_counter) { }
};
@ -734,7 +734,7 @@ char *DumpCommandLog(char *buffer, const char *last, std::function<char *(char *
* @param cmd The integer value of a command
* @return true if the command is valid (and got a CommandProc function)
*/
bool IsValidCommand(uint32 cmd)
bool IsValidCommand(uint32_t cmd)
{
cmd &= CMD_ID_MASK;
@ -748,7 +748,7 @@ bool IsValidCommand(uint32 cmd)
* @param cmd The integer value of the command
* @return The flags for this command
*/
CommandFlags GetCommandFlags(uint32 cmd)
CommandFlags GetCommandFlags(uint32_t cmd)
{
assert(IsValidCommand(cmd));
@ -762,7 +762,7 @@ CommandFlags GetCommandFlags(uint32 cmd)
* @param cmd The integer value of the command
* @return The name for this command
*/
const char *GetCommandName(uint32 cmd)
const char *GetCommandName(uint32_t cmd)
{
assert(IsValidCommand(cmd));
@ -774,7 +774,7 @@ const char *GetCommandName(uint32 cmd)
* @param cmd The command to check.
* @return True if the command is allowed while paused, false otherwise.
*/
bool IsCommandAllowedWhilePaused(uint32 cmd)
bool IsCommandAllowedWhilePaused(uint32_t cmd)
{
/* Lookup table for the command types that are allowed for a given pause level setting. */
static const int command_type_lookup[] = {
@ -829,7 +829,7 @@ private:
* @see CommandProc
* @return the cost
*/
CommandCost DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, DoCommandFlag flags, uint32 cmd, const char *text, const CommandAuxiliaryBase *aux_data)
CommandCost DoCommandEx(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, DoCommandFlag flags, uint32_t cmd, const char *text, const CommandAuxiliaryBase *aux_data)
{
SCOPE_INFO_FMT([=], "DoCommand: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, p3: " OTTD_PRINTFHEX64 ", flags: 0x%X, company: %s, cmd: 0x%X (%s)%s",
tile, TileX(tile), TileY(tile), p1, p2, p3, flags, scope_dumper().CompanyInfo(_current_company), cmd, GetCommandName(cmd), cmd_text_info_dumper().CommandTextInfo(text, aux_data));
@ -909,7 +909,7 @@ static void DebugLogCommandLogEntry(const CommandLogEntry &entry)
debug_print("command", buffer);
}
static void AppendCommandLogEntry(const CommandCost &res, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandLogEntryFlag log_flags, const char *text)
static void AppendCommandLogEntry(const CommandCost &res, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandLogEntryFlag log_flags, const char *text)
{
if (res.Failed()) log_flags |= CLEF_CMD_FAILED;
if (_generating_world) log_flags |= CLEF_GENERATING_WORLD;
@ -961,7 +961,7 @@ static void AppendCommandLogEntry(const CommandCost &res, TileIndex tile, uint32
* @param binary_length The length of binary data in text
* @return \c true if the command succeeded, else \c false.
*/
bool DoCommandPEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, const CommandAuxiliaryBase *aux_data, bool my_cmd)
bool DoCommandPEx(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback, const char *text, const CommandAuxiliaryBase *aux_data, bool my_cmd)
{
SCOPE_INFO_FMT([=], "DoCommandP: tile: %X (%d x %d), p1: 0x%X, p2: 0x%X, p3: 0x" OTTD_PRINTFHEX64 ", company: %s, cmd: 0x%X (%s), my_cmd: %d%s",
tile, TileX(tile), TileY(tile), p1, p2, p3, scope_dumper().CompanyInfo(_current_company), cmd, GetCommandName(cmd), my_cmd, cmd_text_info_dumper().CommandTextInfo(text, aux_data));
@ -1040,7 +1040,7 @@ bool DoCommandPEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, C
return res.Succeeded();
}
CommandCost DoCommandPScript(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, bool asynchronous, const CommandAuxiliaryBase *aux_data)
CommandCost DoCommandPScript(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, bool asynchronous, const CommandAuxiliaryBase *aux_data)
{
GameRandomSeedChecker random_state;
uint order_backup_update_counter = OrderBackup::GetUpdateCounter();
@ -1116,7 +1116,7 @@ void EnqueueDoCommandP(CommandContainer cmd)
* @param estimate_only whether to give only the estimate or also execute the command
* @return the command cost of this function.
*/
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, const CommandAuxiliaryBase *aux_data)
CommandCost DoCommandPInternal(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, const CommandAuxiliaryBase *aux_data)
{
/* Prevent recursion; it gives a mess over the network */
assert(_docommand_recursive == 0);
@ -1338,7 +1338,7 @@ void CommandCost::AddCost(const CommandCost &ret)
*/
void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers)
{
extern TemporaryStorageArray<int32, 0x110> _temp_store;
extern TemporaryStorageArray<int32_t, 0x110> _temp_store;
if (!this->aux_data) {
this->AllocAuxData();
@ -1355,12 +1355,12 @@ void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers)
std::string CommandCost::SummaryMessage(StringID cmd_msg) const
{
if (this->Succeeded()) {
return stdstr_fmt("Success: cost: " OTTD_PRINTF64, (int64) this->GetCost());
return stdstr_fmt("Success: cost: " OTTD_PRINTF64, (int64_t) this->GetCost());
} else {
const uint textref_stack_size = this->GetTextRefStackSize();
if (textref_stack_size > 0) StartTextRefStackUsage(this->GetTextRefStackGRF(), textref_stack_size, this->GetTextRefStack());
std::string buf = stdstr_fmt("Failed: cost: " OTTD_PRINTF64, (int64) this->GetCost());
std::string buf = stdstr_fmt("Failed: cost: " OTTD_PRINTF64, (int64_t) this->GetCost());
if (cmd_msg != 0) {
buf += ' ';
GetString(StringBuilder(buf), cmd_msg);
@ -1416,7 +1416,7 @@ void CommandCost::SetTile(TileIndex tile)
}
}
void CommandCost::SetResultData(uint32 result)
void CommandCost::SetResultData(uint32_t result)
{
this->flags |= CCIF_VALID_RESULT;

@ -18,12 +18,12 @@
#include <vector>
struct CommandDeserialisationBuffer : public BufferDeserialisationHelper<CommandDeserialisationBuffer> {
const uint8 *buffer;
const uint8_t *buffer;
size_t size;
size_t pos = 0;
bool error = false;
CommandDeserialisationBuffer(const uint8 *buffer, size_t size) : buffer(buffer), size(size) {}
CommandDeserialisationBuffer(const uint8_t *buffer, size_t size) : buffer(buffer), size(size) {}
const byte *GetDeserialisationBuffer() const { return this->buffer; }
size_t GetDeserialisationBufferSize() const { return this->size; }
@ -61,14 +61,14 @@ struct CommandAuxiliarySerialised : public CommandAuxiliaryBase {
return new CommandAuxiliarySerialised(*this);
}
virtual std::optional<span<const uint8>> GetDeserialisationSrc() const override { return span<const uint8>(this->serialised_data.data(), this->serialised_data.size()); }
virtual std::optional<span<const uint8_t>> GetDeserialisationSrc() const override { return span<const uint8_t>(this->serialised_data.data(), this->serialised_data.size()); }
virtual void Serialise(CommandSerialisationBuffer &buffer) const override { buffer.Send_binary(this->serialised_data.data(), this->serialised_data.size()); }
};
template <typename T>
struct CommandAuxiliarySerialisable : public CommandAuxiliaryBase {
virtual std::optional<span<const uint8>> GetDeserialisationSrc() const override { return {}; }
virtual std::optional<span<const uint8_t>> GetDeserialisationSrc() const override { return {}; }
CommandAuxiliaryBase *Clone() const override
{
@ -86,7 +86,7 @@ public:
inline CommandCost Load(const CommandAuxiliaryBase *base)
{
if (base == nullptr) return CMD_ERROR;
std::optional<span<const uint8>> deserialise_from = base->GetDeserialisationSrc();
std::optional<span<const uint8_t>> deserialise_from = base->GetDeserialisationSrc();
if (deserialise_from.has_value()) {
this->store = T();
CommandDeserialisationBuffer buffer(deserialise_from->begin(), deserialise_from->size());

@ -32,9 +32,9 @@ static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
*/
#define return_cmd_error(errcode) return CommandCost(errcode);
CommandCost DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, DoCommandFlag flags, uint32 cmd, const char *text = nullptr, const CommandAuxiliaryBase *aux_data = nullptr);
CommandCost DoCommandEx(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, DoCommandFlag flags, uint32_t cmd, const char *text = nullptr, const CommandAuxiliaryBase *aux_data = nullptr);
inline CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = nullptr)
inline CommandCost DoCommand(TileIndex tile, uint32_t p1, uint32_t p2, DoCommandFlag flags, uint32_t cmd, const char *text = nullptr)
{
return DoCommandEx(tile, p1, p2, 0, flags, cmd, text, 0);
}
@ -43,9 +43,9 @@ inline CommandCost DoCommand(const CommandContainer *container, DoCommandFlag fl
return DoCommandEx(container->tile, container->p1, container->p2, container->p3, flags, container->cmd & CMD_ID_MASK, container->text.c_str(), container->aux_data.get());
}
bool DoCommandPEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback = nullptr, const char *text = nullptr, const CommandAuxiliaryBase *aux_data = nullptr, bool my_cmd = true);
bool DoCommandPEx(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback = nullptr, const char *text = nullptr, const CommandAuxiliaryBase *aux_data = nullptr, bool my_cmd = true);
inline bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr, const char *text = nullptr, bool my_cmd = true)
inline bool DoCommandP(TileIndex tile, uint32_t p1, uint32_t p2, uint32_t cmd, CommandCallback *callback = nullptr, const char *text = nullptr, bool my_cmd = true)
{
return DoCommandPEx(tile, p1, p2, 0, cmd, callback, text, 0, my_cmd);
}
@ -55,18 +55,18 @@ inline bool DoCommandP(const CommandContainer *container, bool my_cmd = true)
return DoCommandPEx(container->tile, container->p1, container->p2, container->p3, container->cmd, container->callback, container->text.c_str(), container->aux_data.get(), my_cmd);
}
CommandCost DoCommandPScript(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, bool asynchronous, const CommandAuxiliaryBase *aux_data);
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, const CommandAuxiliaryBase *aux_data);
CommandCost DoCommandPScript(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, bool asynchronous, const CommandAuxiliaryBase *aux_data);
CommandCost DoCommandPInternal(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, const CommandAuxiliaryBase *aux_data);
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company, const CommandAuxiliaryBase *aux_data);
void NetworkSendCommand(TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd, CommandCallback *callback, const char *text, CompanyID company, const CommandAuxiliaryBase *aux_data);
extern Money _additional_cash_required;
bool IsValidCommand(uint32 cmd);
CommandFlags GetCommandFlags(uint32 cmd);
const char *GetCommandName(uint32 cmd);
bool IsValidCommand(uint32_t cmd);
CommandFlags GetCommandFlags(uint32_t cmd);
const char *GetCommandName(uint32_t cmd);
Money GetAvailableMoneyForCommand();
bool IsCommandAllowedWhilePaused(uint32 cmd);
bool IsCommandAllowedWhilePaused(uint32_t cmd);
/**
* Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags

@ -19,7 +19,7 @@
struct GRFFile;
enum CommandCostIntlFlags : uint8 {
enum CommandCostIntlFlags : uint8_t {
CCIF_NONE = 0,
CCIF_SUCCESS = 1 << 0,
CCIF_INLINE_EXTRA_MSG = 1 << 1,
@ -39,18 +39,18 @@ class CommandCost {
CommandCostIntlFlags flags; ///< Flags: see CommandCostIntlFlags
StringID message; ///< Warning message for when success is unset
union {
uint32 result = 0;
uint32_t result = 0;
StringID extra_message; ///< Additional warning message for when success is unset
TileIndex tile;
} inl;
struct CommandCostAuxiliaryData {
uint32 textref_stack[16] = {};
uint32_t textref_stack[16] = {};
const GRFFile *textref_stack_grffile = nullptr; ///< NewGRF providing the #TextRefStack content.
uint textref_stack_size = 0; ///< Number of uint32 values to put on the #TextRefStack for the error message.
uint textref_stack_size = 0; ///< Number of uint32_t values to put on the #TextRefStack for the error message.
StringID extra_message = INVALID_STRING_ID; ///< Additional warning message for when success is unset
TileIndex tile = INVALID_TILE;
uint32 result = 0;
uint32_t result = 0;
};
std::unique_ptr<CommandCostAuxiliaryData> aux_data;
@ -160,8 +160,8 @@ public:
}
/**
* Returns the number of uint32 values for the #TextRefStack of the error message.
* @return number of uint32 values.
* Returns the number of uint32_t values for the #TextRefStack of the error message.
* @return number of uint32_t values.
*/
uint GetTextRefStackSize() const
{
@ -170,9 +170,9 @@ public:
/**
* Returns a pointer to the values for the #TextRefStack of the error message.
* @return uint32 values for the #TextRefStack
* @return uint32_t values for the #TextRefStack
*/
const uint32 *GetTextRefStack() const
const uint32_t *GetTextRefStack() const
{
return this->aux_data != nullptr ? this->aux_data->textref_stack : nullptr;
}
@ -254,13 +254,13 @@ public:
return (this->flags & CCIF_VALID_RESULT);
}
uint32 GetResultData() const
uint32_t GetResultData() const
{
if (this->flags & CCIF_INLINE_RESULT) return this->inl.result;
return this->aux_data != nullptr ? this->aux_data->result : 0;
}
void SetResultData(uint32 result);
void SetResultData(uint32_t result);
};
/**
@ -651,8 +651,8 @@ struct CommandAuxiliaryBase;
* @param text Additional text
* @return The CommandCost of the command, which can be succeeded or failed.
*/
typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
typedef CommandCost CommandProcEx(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data);
typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text);
typedef CommandCost CommandProcEx(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, uint64_t p3, const char *text, const CommandAuxiliaryBase *aux_data);
/**
* Define a command with the flags which belongs to it.
@ -674,7 +674,7 @@ struct Command {
Command(CommandProcEx *procex, const char *name, CommandFlags flags, CommandType type)
: procex(procex), name(name), flags(flags | CMD_PROCEX), type(type) {}
inline CommandCost Execute(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, uint64 p3, const char *text, const CommandAuxiliaryBase *aux_data) const {
inline CommandCost Execute(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, uint64_t p3, const char *text, const CommandAuxiliaryBase *aux_data) const {
if (this->flags & CMD_PROCEX) {
return this->procex(tile, flags, p1, p2, p3, text, aux_data);
} else {
@ -697,7 +697,7 @@ struct Command {
* @param p3 Additional data of the command
* @see CommandProc
*/
typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint32 cmd);
typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t p2, uint64_t p3, uint32_t cmd);
#define MAX_CMD_TEXT_LENGTH 32000
@ -708,7 +708,7 @@ struct CommandAuxiliaryBase {
virtual CommandAuxiliaryBase *Clone() const = 0;
virtual std::optional<span<const uint8>> GetDeserialisationSrc() const = 0;
virtual std::optional<span<const uint8_t>> GetDeserialisationSrc() const = 0;
virtual void Serialise(CommandSerialisationBuffer &buffer) const = 0;
};
@ -740,16 +740,16 @@ private:
*/
struct CommandContainer {
TileIndex tile; ///< tile command being executed on.
uint32 p1; ///< parameter p1.
uint32 p2; ///< parameter p2.
uint32 cmd; ///< command being executed.
uint64 p3; ///< parameter p3. (here for alignment)
uint32_t p1; ///< parameter p1.
uint32_t p2; ///< parameter p2.
uint32_t cmd; ///< command being executed.
uint64_t p3; ///< parameter p3. (here for alignment)
CommandCallback *callback; ///< any callback function executed upon successful completion of the command.
std::string text; ///< possible text sent for name changes etc.
CommandAuxiliaryPtr aux_data; ///< Auxiliary command data
};
inline CommandContainer NewCommandContainerBasic(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr)
inline CommandContainer NewCommandContainerBasic(TileIndex tile, uint32_t p1, uint32_t p2, uint32_t cmd, CommandCallback *callback = nullptr)
{
return { tile, p1, p2, cmd, 0, callback, {}, nullptr };
}

@ -21,31 +21,31 @@
/** Statistics about the economy. */
struct CompanyEconomyEntry {
Money income; ///< The amount of income.
Money expenses; ///< The amount of expenses.
Money income; ///< The amount of income.
Money expenses; ///< The amount of expenses.
CargoArray delivered_cargo{}; ///< The amount of delivered cargo.
int32 performance_history; ///< Company score (scale 0-1000)
Money company_value; ///< The value of the company.
int32_t performance_history; ///< Company score (scale 0-1000)
Money company_value; ///< The value of the company.
};
struct CompanyInfrastructure {
uint32 road[ROADTYPE_END]; ///< Count of company owned track bits for each road type.
uint32 signal; ///< Count of company owned signals.
uint32 rail[RAILTYPE_END]; ///< Count of company owned track bits for each rail type.
uint32 water; ///< Count of company owned track bits for canals.
uint32 station; ///< Count of company owned station tiles.
uint32 airport; ///< Count of company owned airports.
uint32_t road[ROADTYPE_END]; ///< Count of company owned track bits for each road type.
uint32_t signal; ///< Count of company owned signals.
uint32_t rail[RAILTYPE_END]; ///< Count of company owned track bits for each rail type.
uint32_t water; ///< Count of company owned track bits for canals.
uint32_t station; ///< Count of company owned station tiles.
uint32_t airport; ///< Count of company owned airports.
/** Get total sum of all owned track bits. */
uint32 GetRailTotal() const
uint32_t GetRailTotal() const
{
uint32 total = 0;
uint32_t total = 0;
for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) total += this->rail[rt];
return total;
}
uint32 GetRoadTotal() const;
uint32 GetTramTotal() const;
uint32_t GetRoadTotal() const;
uint32_t GetTramTotal() const;
char *Dump(char *buffer, const char *last) const;
};
@ -63,12 +63,12 @@ extern CompanyPool _company_pool;
/** Statically loadable part of Company pool item */
struct CompanyProperties {
uint32 name_2; ///< Parameter of #name_1.
uint32_t name_2; ///< Parameter of #name_1.
StringID name_1; ///< Name of the company if the user did not change it.
std::string name; ///< Name of the company if the user changed it.
StringID president_name_1; ///< Name of the president if the user did not change it.
uint32 president_name_2; ///< Parameter of #president_name_1
uint32_t president_name_2; ///< Parameter of #president_name_1
std::string president_name; ///< Name of the president if the user changed it.
CompanyManagerFace face; ///< Face description of the president.
@ -92,14 +92,14 @@ struct CompanyProperties {
CompanyID bankrupt_last_asked; ///< Which company was most recently asked about buying it?
CompanyBankruptcyFlags bankrupt_flags; ///< bankruptcy flags
CompanyMask bankrupt_asked; ///< which companies were asked about buying it?
int16 bankrupt_timeout; ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company.
int16_t bankrupt_timeout; ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company.
Money bankrupt_value;
uint32 terraform_limit; ///< Amount of tileheights we can (still) terraform (times 65536).
uint32 clear_limit; ///< Amount of tiles we can (still) clear (times 65536).
uint32 tree_limit; ///< Amount of trees we can (still) plant (times 65536).
uint32 purchase_land_limit; ///< Amount of tiles we can (still) purchase (times 65536).
uint32 build_object_limit; ///< Amount of tiles we can (still) build objects on (times 65536).
uint32_t terraform_limit; ///< Amount of tileheights we can (still) terraform (times 65536).
uint32_t clear_limit; ///< Amount of tiles we can (still) clear (times 65536).
uint32_t tree_limit; ///< Amount of trees we can (still) plant (times 65536).
uint32_t purchase_land_limit; ///< Amount of tiles we can (still) purchase (times 65536).
uint32_t build_object_limit; ///< Amount of tiles we can (still) build objects on (times 65536).
/**
* If \c true, the company is (also) controlled by the computer (a NoAI program).
@ -127,7 +127,7 @@ struct CompanyProperties {
};
struct Company : CompanyPool::PoolItem<&_company_pool>, CompanyProperties {
Company(uint16 name_1 = 0, bool is_ai = false);
Company(uint16_t name_1 = 0, bool is_ai = false);
~Company();
RailTypes avail_railtypes; ///< Rail types available to this company.

@ -60,7 +60,7 @@ CompanyManagerFace _company_manager_face; ///< for company manager face storage
uint _cur_company_tick_index; ///< used to generate a name for one company that doesn't have a name yet per tick
CompanyMask _saved_PLYP_invalid_mask;
std::vector<uint8> _saved_PLYP_data;
std::vector<uint8_t> _saved_PLYP_data;
CompanyPool _company_pool("Company"); ///< Pool of companies.
INSTANTIATE_POOL_METHODS(Company)
@ -70,16 +70,16 @@ INSTANTIATE_POOL_METHODS(Company)
* @param name_1 Name of the company.
* @param is_ai A computer program is running for this company.
*/
Company::Company(uint16 name_1, bool is_ai)
Company::Company(uint16_t name_1, bool is_ai)
{
this->name_1 = name_1;
this->location_of_HQ = INVALID_TILE;
this->is_ai = is_ai;
this->terraform_limit = (uint32)_settings_game.construction.terraform_frame_burst << 16;
this->terraform_limit = (uint32_t)_settings_game.construction.terraform_frame_burst << 16;
this->clear_limit = _settings_game.construction.clear_frame_burst << 16;
this->tree_limit = (uint32)(uint32)_settings_game.construction.tree_frame_burst << 16;
this->purchase_land_limit = (uint32)_settings_game.construction.purchase_land_frame_burst << 16;
this->build_object_limit = (uint32)_settings_game.construction.build_object_frame_burst << 16;
this->tree_limit = (uint32_t)(uint32_t)_settings_game.construction.tree_frame_burst << 16;
this->purchase_land_limit = (uint32_t)_settings_game.construction.purchase_land_frame_burst << 16;
this->build_object_limit = (uint32_t)_settings_game.construction.build_object_frame_burst << 16;
std::fill(this->share_owners.begin(), this->share_owners.end(), INVALID_OWNER);
InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY);
@ -386,7 +386,7 @@ static void GenerateCompanyName(Company *c)
Town *t = ClosestTownFromTile(c->last_build_coordinate, UINT_MAX);
StringID str;
uint32 strp;
uint32_t strp;
std::string buffer;
if (t->name.empty() && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
@ -588,7 +588,7 @@ Company *DoStartupNewCompany(DoStartupNewCompanyFlag flags, CompanyID company)
_company_colours[c->index] = (Colours)c->colour;
/* Scale the initial loan based on the inflation rounded down to the loan interval. The maximum loan has already been inflation adjusted. */
c->money = c->current_loan = std::min<int64>((INITIAL_LOAN * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL, _economy.max_loan);
c->money = c->current_loan = std::min<int64_t>((INITIAL_LOAN * _economy.inflation_prices >> 16) / LOAN_INTERVAL * LOAN_INTERVAL, _economy.max_loan);
std::fill(c->share_owners.begin(), c->share_owners.end(), INVALID_OWNER);
@ -631,7 +631,7 @@ TimeoutTimer<TimerGameTick> _new_competitor_timeout(0, []() {
if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return;
/* count number of competitors */
uint8 n = 0;
uint8_t n = 0;
for (const Company *c : Company::Iterate()) {
if (c->is_ai) n++;
}
@ -730,7 +730,7 @@ static void HandleBankruptcyTakeover(Company *c)
if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
Company *best = nullptr;
int32 best_performance = -1;
int32_t best_performance = -1;
/* Ask the company with the highest performance history first */
for (Company *c2 : Company::Iterate()) {
@ -789,11 +789,11 @@ void OnTick_Companies(bool main_tick)
}
if (_new_competitor_timeout.HasFired() && _game_mode != GM_MENU && AI::CanStartNew()) {
int32 timeout = _settings_game.difficulty.competitors_interval * 60 * TICKS_PER_SECOND;
int32_t timeout = _settings_game.difficulty.competitors_interval * 60 * TICKS_PER_SECOND;
/* If the interval is zero, start as many competitors as needed then check every ~10 minutes if a company went bankrupt and needs replacing. */
if (timeout == 0) {
/* count number of competitors */
uint8 n = 0;
uint8_t n = 0;
for (const Company *cc : Company::Iterate()) {
if (cc->is_ai) n++;
}
@ -892,7 +892,7 @@ void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
CompanyID company_id = (CompanyID)GB(p1, 16, 8);
@ -1042,7 +1042,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
CompanyManagerFace cmf = (CompanyManagerFace)p2;
@ -1080,7 +1080,7 @@ void UpdateCompanyLiveries(Company *c)
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
Colours colour = Extract<Colours, 0, 8>(p2);
LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
@ -1193,7 +1193,7 @@ static bool IsUniqueCompanyName(const char *name)
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
bool reset = StrEmpty(text);
@ -1239,7 +1239,7 @@ static bool IsUniquePresidentName(const char *name)
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
bool reset = StrEmpty(text);
@ -1307,9 +1307,9 @@ CompanyID GetDefaultLocalCompany()
* Get total sum of all owned road bits.
* @return Combined total road road bits.
*/
uint32 CompanyInfrastructure::GetRoadTotal() const
uint32_t CompanyInfrastructure::GetRoadTotal() const
{
uint32 total = 0;
uint32_t total = 0;
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
if (RoadTypeIsRoad(rt)) total += this->road[rt];
}
@ -1320,9 +1320,9 @@ uint32 CompanyInfrastructure::GetRoadTotal() const
* Get total sum of all owned tram bits.
* @return Combined total of tram road bits.
*/
uint32 CompanyInfrastructure::GetTramTotal() const
uint32_t CompanyInfrastructure::GetTramTotal() const
{
uint32 total = 0;
uint32_t total = 0;
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
if (RoadTypeIsTram(rt)) total += this->road[rt];
}

@ -636,7 +636,7 @@ public:
/** Company livery colour scheme window. */
struct SelectCompanyLiveryWindow : public Window {
private:
uint32 sel;
uint32_t sel;
LiveryClass livery_class;
Dimension square;
uint rows;
@ -645,9 +645,9 @@ private:
std::vector<int> indents;
Scrollbar *vscroll;
void ShowColourDropDownMenu(uint32 widget)
void ShowColourDropDownMenu(uint32_t widget)
{
uint32 used_colours = 0;
uint32_t used_colours = 0;
const Livery *livery, *default_livery = nullptr;
bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
byte default_col = 0;
@ -1876,14 +1876,14 @@ struct CompanyInfrastructureWindow : Window
const Company *c = Company::Get((CompanyID)this->window_number);
Money total;
uint32 rail_total = c->infrastructure.GetRailTotal();
uint32_t rail_total = c->infrastructure.GetRailTotal();
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
if (HasBit(this->railtypes, rt)) total += RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total);
}
total += SignalMaintenanceCost(c->infrastructure.signal);
uint32 road_total = c->infrastructure.GetRoadTotal();
uint32 tram_total = c->infrastructure.GetTramTotal();
uint32_t road_total = c->infrastructure.GetRoadTotal();
uint32_t tram_total = c->infrastructure.GetTramTotal();
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
if (HasBit(this->roadtypes, rt)) total += RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total);
}
@ -1966,17 +1966,17 @@ struct CompanyInfrastructureWindow : Window
case WID_CI_COUNT: {
/* Find the maximum count that is displayed. */
uint32 max_val = 1000; // Some random number to reserve enough space.
uint32_t max_val = 1000; // Some random number to reserve enough space.
Money max_cost = 10000; // Some random number to reserve enough space.
uint32 rail_total = c->infrastructure.GetRailTotal();
uint32_t rail_total = c->infrastructure.GetRailTotal();
for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
max_val = std::max(max_val, c->infrastructure.rail[rt]);
max_cost = std::max(max_cost, RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
}
max_val = std::max(max_val, c->infrastructure.signal);
max_cost = std::max(max_cost, SignalMaintenanceCost(c->infrastructure.signal));
uint32 road_total = c->infrastructure.GetRoadTotal();
uint32 tram_total = c->infrastructure.GetTramTotal();
uint32_t road_total = c->infrastructure.GetRoadTotal();
uint32_t tram_total = c->infrastructure.GetTramTotal();
for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
max_val = std::max(max_val, c->infrastructure.road[rt]);
max_cost = std::max(max_cost, RoadMaintenanceCost(rt, c->infrastructure.road[rt], RoadTypeIsRoad(rt) ? road_total : tram_total));
@ -2102,7 +2102,7 @@ struct CompanyInfrastructureWindow : Window
case WID_CI_COUNT: {
/* Draw infrastructure count for each valid railtype. */
uint32 rail_total = c->infrastructure.GetRailTotal();
uint32_t rail_total = c->infrastructure.GetRailTotal();
for (const auto &rt : _sorted_railtypes) {
if (HasBit(this->railtypes, rt)) {
this->DrawCountLine(width, y, c->infrastructure.rail[rt], RailMaintenanceCost(rt, c->infrastructure.rail[rt], rail_total));
@ -2114,7 +2114,7 @@ struct CompanyInfrastructureWindow : Window
y += GetCharacterHeight(FS_NORMAL) + EXP_SPACING;
uint32 road_total = c->infrastructure.GetRoadTotal();
uint32_t road_total = c->infrastructure.GetRoadTotal();
for (const auto &rt : _sorted_roadtypes) {
if (HasBit(this->roadtypes, rt) && RoadTypeIsRoad(rt)) {
this->DrawCountLine(width, y, c->infrastructure.road[rt], RoadMaintenanceCost(rt, c->infrastructure.road[rt], road_total));
@ -2123,7 +2123,7 @@ struct CompanyInfrastructureWindow : Window
y += GetCharacterHeight(FS_NORMAL) + EXP_SPACING;
uint32 tram_total = c->infrastructure.GetTramTotal();
uint32_t tram_total = c->infrastructure.GetTramTotal();
for (const auto &rt : _sorted_roadtypes) {
if (HasBit(this->roadtypes, rt) && RoadTypeIsTram(rt)) {
this->DrawCountLine(width, y, c->infrastructure.road[rt], RoadMaintenanceCost(rt, c->infrastructure.road[rt], tram_total));

@ -129,7 +129,7 @@ inline void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFac
*/
inline void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8_t amount)
{
int8 val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount; // the new value for the cmfv
int8_t val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount; // the new value for the cmfv
/* scales the new value to the correct scope */
if (val >= _cmf_info[cmfv].valid_values[ge]) {

@ -50,10 +50,10 @@ template <> struct EnumPropsT<Owner> : MakeEnumPropsT<Owner, byte, OWNER_BEGIN,
typedef Owner CompanyID;
typedef uint16 CompanyMask;
typedef uint16_t CompanyMask;
struct Company;
typedef uint32 CompanyManagerFace; ///< Company manager face bits, info see in company_manager_face.h
typedef uint32_t CompanyManagerFace; ///< Company manager face bits, info see in company_manager_face.h
/** The reason why the company was removed. */
enum CompanyRemoveReason {

@ -174,7 +174,7 @@ void IConsoleError(const char *string)
* @param *arg the string to be converted
* @return Return true on success or false on failure
*/
bool GetArgumentInteger(uint32 *value, const char *arg)
bool GetArgumentInteger(uint32_t *value, const char *arg)
{
char *endptr;

@ -282,7 +282,7 @@ DEF_CONSOLE_CMD(ConResetTile)
}
if (argc == 2) {
uint32 result;
uint32_t result;
if (GetArgumentInteger(&result, argv[1])) {
DoClearSquare((TileIndex)result);
return true;
@ -321,7 +321,7 @@ DEF_CONSOLE_CMD(ConZoomToLevel)
return true;
case 2: {
uint32 level;
uint32_t level;
if (GetArgumentInteger(&level, argv[1])) {
/* In case ZOOM_LVL_MIN is more than 0, the next if statement needs to be amended.
* A simple check for less than ZOOM_LVL_MIN does not work here because we are
@ -370,7 +370,7 @@ DEF_CONSOLE_CMD(ConScrollToTile)
}
if (argc < 2) return false;
uint32 arg_index = 1;
uint32_t arg_index = 1;
bool instant = false;
if (strcmp(argv[arg_index], "instant") == 0) {
++arg_index;
@ -379,7 +379,7 @@ DEF_CONSOLE_CMD(ConScrollToTile)
switch (argc - arg_index) {
case 1: {
uint32 result;
uint32_t result;
if (GetArgumentInteger(&result, argv[arg_index])) {
if (result >= MapSize()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
@ -392,7 +392,7 @@ DEF_CONSOLE_CMD(ConScrollToTile)
}
case 2: {
uint32 x, y;
uint32_t x, y;
if (GetArgumentInteger(&x, argv[arg_index]) && GetArgumentInteger(&y, argv[arg_index + 1])) {
if (x >= MapSizeX() || y >= MapSizeY()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
@ -427,7 +427,7 @@ DEF_CONSOLE_CMD(ConHighlightTile)
return true;
case 2: {
uint32 result;
uint32_t result;
if (GetArgumentInteger(&result, argv[1])) {
if (result >= MapSize()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
@ -440,7 +440,7 @@ DEF_CONSOLE_CMD(ConHighlightTile)
}
case 3: {
uint32 x, y;
uint32_t x, y;
if (GetArgumentInteger(&x, argv[1]) && GetArgumentInteger(&y, argv[2])) {
if (x >= MapSizeX() || y >= MapSizeY()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
@ -1651,10 +1651,10 @@ DEF_CONSOLE_CMD(ConScreenShot)
if (argc > 7) return false;
ScreenshotType type = SC_VIEWPORT;
uint32 width = 0;
uint32 height = 0;
uint32_t width = 0;
uint32_t height = 0;
std::string name{};
uint32 arg_index = 1;
uint32_t arg_index = 1;
if (argc > arg_index) {
if (strcmp(argv[arg_index], "viewport") == 0) {
@ -1907,7 +1907,7 @@ DEF_CONSOLE_CMD(ConCompanies)
IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s' Year Founded: %d Money: " OTTD_PRINTF64 " Loan: " OTTD_PRINTF64 " Value: " OTTD_PRINTF64 " (T:%d, R:%d, P:%d, S:%d) %s",
c->index + 1, GetStringPtr(STR_COLOUR_DARK_BLUE + _company_colours[c->index]), company_name.c_str(),
c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
c->inaugurated_year, (int64_t)c->money, (int64_t)c->current_loan, (int64_t)CalculateCompanyValue(c),
c->group_all[VEH_TRAIN].num_vehicle,
c->group_all[VEH_ROAD].num_vehicle,
c->group_all[VEH_AIRCRAFT].num_vehicle,
@ -2512,7 +2512,7 @@ DEF_CONSOLE_CMD(ConDeleteVehicleID)
}
if (argc == 2) {
uint32 result;
uint32_t result;
if (GetArgumentInteger(&result, argv[1])) {
extern void ConsoleRemoveVehicle(VehicleID id);
ConsoleRemoveVehicle(result);
@ -2531,18 +2531,18 @@ DEF_CONSOLE_CMD(ConRunTileLoopTile)
}
if (argc >= 2) {
uint32 tile;
uint32_t tile;
if (!GetArgumentInteger(&tile, argv[1])) return false;
if (tile >= MapSize()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
return true;
}
uint32 count = 1;
uint32_t count = 1;
if (argc >= 3) {
if (!GetArgumentInteger(&count, argv[2])) return false;
}
for (uint32 i = 0; i < count; i++) {
for (uint32_t i = 0; i < count; i++) {
_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
}
return true;
@ -2758,22 +2758,22 @@ DEF_CONSOLE_CMD(ConDumpRoadTypes)
IConsolePrintF(CC_DEFAULT, " T = disallow tunnels");
IConsolePrintF(CC_DEFAULT, " c = disallow collisions with trains for vehicles of this type");
btree::btree_map<uint32, const GRFFile *> grfs;
btree::btree_map<uint32_t, const GRFFile *> grfs;
for (RoadType rt = ROADTYPE_BEGIN; rt < ROADTYPE_END; rt++) {
const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
if (rti->label == 0) continue;
uint32 grfid = 0;
uint32_t grfid = 0;
const GRFFile *grf = rti->grffile[ROTSG_GROUND];
if (grf == nullptr) {
uint32 str_grfid = GetStringGRFID(rti->strings.name);
uint32_t str_grfid = GetStringGRFID(rti->strings.name);
if (str_grfid != 0) {
extern GRFFile *GetFileByGRFID(uint32 grfid);
extern GRFFile *GetFileByGRFID(uint32_t grfid);
grf = GetFileByGRFID(grfid);
}
}
if (grf != nullptr) {
grfid = grf->grfid;
grfs.insert(std::pair<uint32, const GRFFile *>(grfid, grf));
grfs.insert(std::pair<uint32_t, const GRFFile *>(grfid, grf));
}
IConsolePrintF(CC_DEFAULT, " %02u %s %c%c%c%c, Flags: %c%c%c%c%c, Extra Flags: %c%c%c%c, GRF: %08X, %s",
(uint) rt,
@ -2816,22 +2816,22 @@ DEF_CONSOLE_CMD(ConDumpRailTypes)
IConsolePrintF(CC_DEFAULT, " p = signal graphics callback enabled for programmable pre-signals");
IConsolePrintF(CC_DEFAULT, " r = signal graphics callback restricted signal flag enabled");
btree::btree_map<uint32, const GRFFile *> grfs;
btree::btree_map<uint32_t, const GRFFile *> grfs;
for (RailType rt = RAILTYPE_BEGIN; rt < RAILTYPE_END; rt++) {
const RailTypeInfo *rti = GetRailTypeInfo(rt);
if (rti->label == 0) continue;
uint32 grfid = 0;
uint32_t grfid = 0;
const GRFFile *grf = rti->grffile[RTSG_GROUND];
if (grf == nullptr) {
uint32 str_grfid = GetStringGRFID(rti->strings.name);
uint32_t str_grfid = GetStringGRFID(rti->strings.name);
if (str_grfid != 0) {
extern GRFFile *GetFileByGRFID(uint32 grfid);
extern GRFFile *GetFileByGRFID(uint32_t grfid);
grf = GetFileByGRFID(grfid);
}
}
if (grf != nullptr) {
grfid = grf->grfid;
grfs.insert(std::pair<uint32, const GRFFile *>(grfid, grf));
grfs.insert(std::pair<uint32_t, const GRFFile *>(grfid, grf));
}
IConsolePrintF(CC_DEFAULT, " %02u %c%c%c%c, Flags: %c%c%c%c%c%c, Ctrl Flags: %c%c%c%c, GRF: %08X, %s",
(uint) rt,
@ -2869,10 +2869,10 @@ DEF_CONSOLE_CMD(ConDumpBridgeTypes)
IConsolePrintF(CC_DEFAULT, " t = not available to towns");
IConsolePrintF(CC_DEFAULT, " s = not available to scripts (AI/GS)");
btree::btree_set<uint32> grfids;
btree::btree_set<uint32_t> grfids;
for (BridgeType bt = 0; bt < MAX_BRIDGES; bt++) {
const BridgeSpec *spec = GetBridgeSpec(bt);
uint32 grfid = GetStringGRFID(spec->material);
uint32_t grfid = GetStringGRFID(spec->material);
if (grfid != 0) grfids.insert(grfid);
IConsolePrintF(CC_DEFAULT, " %02u Year: %7u, Min: %3u, Max: %5u, Flags: %02X, Ctrl Flags: %c%c%c%c, Pillars: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X, GRF: %08X, %s",
(uint) bt,
@ -2900,8 +2900,8 @@ DEF_CONSOLE_CMD(ConDumpBridgeTypes)
GetStringPtr(spec->material)
);
}
for (uint32 grfid : grfids) {
extern GRFFile *GetFileByGRFID(uint32 grfid);
for (uint32_t grfid : grfids) {
extern GRFFile *GetFileByGRFID(uint32_t grfid);
const GRFFile *grffile = GetFileByGRFID(grfid);
IConsolePrintF(CC_DEFAULT, " GRF: %08X = %s", BSWAP32(grfid), grffile ? grffile->filename.c_str() : "????");
}
@ -2928,22 +2928,22 @@ DEF_CONSOLE_CMD(ConDumpCargoTypes)
IConsolePrintF(CC_DEFAULT, " c = covered/sheltered");
IConsolePrintF(CC_DEFAULT, " S = special");
btree::btree_map<uint32, const GRFFile *> grfs;
btree::btree_map<uint32_t, const GRFFile *> grfs;
for (CargoID i = 0; i < NUM_CARGO; i++) {
const CargoSpec *spec = CargoSpec::Get(i);
if (!spec->IsValid()) continue;
uint32 grfid = 0;
uint32_t grfid = 0;
const GRFFile *grf = spec->grffile;
if (grf == nullptr) {
uint32 str_grfid = GetStringGRFID(spec->name);
uint32_t str_grfid = GetStringGRFID(spec->name);
if (str_grfid != 0) {
extern GRFFile *GetFileByGRFID(uint32 grfid);
extern GRFFile *GetFileByGRFID(uint32_t grfid);
grf = GetFileByGRFID(grfid);
}
}
if (grf != nullptr) {
grfid = grf->grfid;
grfs.insert(std::pair<uint32, const GRFFile *>(grfid, grf));
grfs.insert(std::pair<uint32_t, const GRFFile *>(grfid, grf));
}
IConsolePrintF(CC_DEFAULT, " %02u Bit: %2u, Label: %c%c%c%c, Callback mask: 0x%02X, Cargo class: %c%c%c%c%c%c%c%c%c%c%c, GRF: %08X, %s",
(uint) i,
@ -3009,7 +3009,7 @@ DEF_CONSOLE_CMD(ConDumpTile)
return true;
case 2: {
uint32 result;
uint32_t result;
if (GetArgumentInteger(&result, argv[1])) {
if (result >= MapSize()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
@ -3023,7 +3023,7 @@ DEF_CONSOLE_CMD(ConDumpTile)
}
case 3: {
uint32 x, y;
uint32_t x, y;
if (GetArgumentInteger(&x, argv[1]) && GetArgumentInteger(&y, argv[2])) {
if (x >= MapSizeX() || y >= MapSizeY()) {
IConsolePrint(CC_ERROR, "Tile does not exist");
@ -3090,14 +3090,14 @@ DEF_CONSOLE_CMD(ConDumpSignalStyles)
IConsolePrintF(CC_DEFAULT, " r = realistic braking only");
IConsolePrintF(CC_DEFAULT, " Extra aspects: %u", _extra_aspects);
btree::btree_map<uint32, const GRFFile *> grfs;
for (uint8 i = 0; i < _num_new_signal_styles; i++) {
btree::btree_map<uint32_t, const GRFFile *> grfs;
for (uint8_t i = 0; i < _num_new_signal_styles; i++) {
const NewSignalStyle &style = _new_signal_styles[i];
uint32 grfid = 0;
uint32_t grfid = 0;
if (style.grffile != nullptr) {
grfid = style.grffile->grfid;
grfs.insert(std::pair<uint32, const GRFFile *>(grfid, style.grffile));
grfs.insert(std::pair<uint32_t, const GRFFile *>(grfid, style.grffile));
}
IConsolePrintF(CC_DEFAULT, " %2u: GRF: %08X, Local: %2u, Extra aspects: %3u, Flags: %c%c%c%c%c%c%c, %s",
(uint) (i + 1),
@ -3236,7 +3236,7 @@ DEF_CONSOLE_CMD(ConViewportDebug)
return true;
}
extern uint32 _viewport_debug_flags;
extern uint32_t _viewport_debug_flags;
if (argc == 1) {
IConsolePrintF(CC_DEFAULT, "Viewport debug flags: %X", _viewport_debug_flags);
} else {
@ -3297,7 +3297,7 @@ DEF_CONSOLE_CMD(ConGfxDebug)
return true;
}
extern uint32 _gfx_debug_flags;
extern uint32_t _gfx_debug_flags;
if (argc == 1) {
IConsolePrintF(CC_DEFAULT, "Gfx debug flags: %X", _gfx_debug_flags);
} else {
@ -3549,7 +3549,7 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
if (started > 0) {
IConsolePrintF(CC_DEBUG, "Started profiling for GRFID%s %s", (started > 1) ? "s" : "", grfids.c_str());
if (argc >= 3) {
uint64 ticks = std::max(atoi(argv[2]), 1);
uint64_t ticks = std::max(atoi(argv[2]), 1);
NewGRFProfiler::StartTimer(ticks);
IConsolePrintF(CC_DEBUG, "Profiling will automatically stop after %u ticks.", (uint)ticks);
}
@ -3609,7 +3609,7 @@ DEF_CONSOLE_CMD(ConRailTypeMapColourCtl)
}
RailType rt = (RailType)atoi(argv[1]);
uint8 map_colour = atoi(argv[2]);
uint8_t map_colour = atoi(argv[2]);
if (rt >= RAILTYPE_END) return true;
extern RailTypeInfo _railtypes[RAILTYPE_END];

@ -40,7 +40,7 @@ static const uint ICON_BOTTOM_BORDERWIDTH = 12;
struct IConsoleLine {
std::string buffer; ///< The data to store.
TextColour colour; ///< The colour of the line.
uint16 time; ///< The amount of time the line is in the backlog.
uint16_t time; ///< The amount of time the line is in the backlog.
IConsoleLine() : buffer(), colour(TC_BEGIN), time(0)
{
@ -206,7 +206,7 @@ struct IConsoleWindow : Window
if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
}
EventState OnKeyPress(WChar key, uint16 keycode) override
EventState OnKeyPress(char32_t key, uint16_t keycode) override
{
if (_focused_window != this) return ES_NOT_HANDLED;
@ -485,8 +485,8 @@ static void IConsoleTabCompletion()
const char *cmdp = cmd_name;
while (true) {
const char *end = cmdp;
WChar a = Utf8Consume(cp);
WChar b = Utf8Consume(cmdp);
char32_t a = Utf8Consume(cp);
char32_t b = Utf8Consume(cmdp);
if (a == 0 || b == 0 || a != b) {
common_prefix.resize(end - cmd_name);
break;

@ -84,7 +84,7 @@ void IConsoleClearBuffer();
void IConsoleStdLibRegister();
/* Supporting functions */
bool GetArgumentInteger(uint32 *value, const char *arg);
bool GetArgumentInteger(uint32_t *value, const char *arg);
void IConsoleGUIInit();
void IConsoleGUIFree();

@ -14,7 +14,7 @@
#ifndef WITH_BITMATH_BUILTINS
const uint8 _ffb_64[64] = {
const uint8_t _ffb_64[64] = {
0, 0, 1, 0, 2, 0, 1, 0,
3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0,
@ -25,13 +25,13 @@ const uint8 _ffb_64[64] = {
3, 0, 1, 0, 2, 0, 1, 0,
};
uint8 FindFirstBit32(uint32 x)
uint8_t FindFirstBit32(uint32_t x)
{
if (x == 0) return 0;
/* The macro FIND_FIRST_BIT is better to use when your x is
not more than 128. */
uint8 pos = 0;
uint8_t pos = 0;
if ((x & 0x0000ffff) == 0) { x >>= 16; pos += 16; }
if ((x & 0x000000ff) == 0) { x >>= 8; pos += 8; }
@ -42,11 +42,11 @@ uint8 FindFirstBit32(uint32 x)
return pos;
}
uint8 FindFirstBit64(uint64 x)
uint8_t FindFirstBit64(uint64_t x)
{
if (x == 0) return 0;
if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit32(static_cast<uint32>(x));
return FindFirstBit32(static_cast<uint32>(x >> 32)) + 32;
if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit32(static_cast<uint32_t>(x));
return FindFirstBit32(static_cast<uint32_t>(x >> 32)) + 32;
}
#endif
@ -62,11 +62,11 @@ uint8 FindFirstBit64(uint64 x)
* @param x The value to search
* @return The position of the last bit set
*/
uint8 FindLastBit64(uint64 x)
uint8_t FindLastBit64(uint64_t x)
{
if (x == 0) return 0;
uint8 pos = 0;
uint8_t pos = 0;
if ((x & 0xffffffff00000000ULL) != 0) { x >>= 32; pos += 32; }
if ((x & 0x00000000ffff0000ULL) != 0) { x >>= 16; pos += 16; }

@ -31,7 +31,7 @@
* @return The selected bits, aligned to a LSB.
*/
template <typename T>
debug_inline constexpr static uint GB(const T x, const uint8 s, const uint8 n)
debug_inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
{
return (x >> s) & (((T)1U << n) - 1);
}
@ -103,7 +103,7 @@ inline T AB(T &x, const uint8_t s, const uint8_t n, const U i)
* @return True if the bit is set, false else.
*/
template <typename T>
debug_inline static bool HasBit(const T x, const uint8 y)
debug_inline static bool HasBit(const T x, const uint8_t y)
{
return (x & ((T)1U << y)) != 0;
}
@ -193,7 +193,7 @@ inline T ToggleBit(T &x, const uint8_t y)
#else
/** Lookup table to check which bit is set in a 6 bit variable */
extern const uint8 _ffb_64[64];
extern const uint8_t _ffb_64[64];
/**
* Returns the first non-zero bit in a 6-bit value (from right).
@ -216,7 +216,7 @@ extern const uint8 _ffb_64[64];
* @return The position of the first bit set, or 0 when value is 0
*/
template <typename T>
inline uint8 FindFirstBit(T value)
inline uint8_t FindFirstBit(T value)
{
static_assert(sizeof(T) <= sizeof(unsigned long long));
#ifdef WITH_BITMATH_BUILTINS
@ -230,11 +230,11 @@ inline uint8 FindFirstBit(T value)
return __builtin_ctzll(unsigned_value);
}
#else
if (sizeof(T) <= sizeof(uint32)) {
extern uint8 FindFirstBit32(uint32 x);
if (sizeof(T) <= sizeof(uint32_t)) {
extern uint8_t FindFirstBit32(uint32_t x);
return FindFirstBit32(value);
} else {
extern uint8 FindFirstBit64(uint64 x);
extern uint8_t FindFirstBit64(uint64_t x);
return FindFirstBit64(value);
}
#endif
@ -247,7 +247,7 @@ inline uint8 FindFirstBit(T value)
* @return The position of the last bit set, or 0 when value is 0
*/
template <typename T>
inline uint8 FindLastBit(T value)
inline uint8_t FindLastBit(T value)
{
static_assert(sizeof(T) <= sizeof(unsigned long long));
#ifdef WITH_BITMATH_BUILTINS
@ -261,7 +261,7 @@ inline uint8 FindLastBit(T value)
return __builtin_clzll(1) - __builtin_clzll(unsigned_value);
}
#else
extern uint8 FindLastBit64(uint64 x);
extern uint8_t FindLastBit64(uint64_t x);
return FindLastBit64(value);
#endif
}
@ -497,27 +497,27 @@ private:
#if defined(__APPLE__)
/* Make endian swapping use Apple's macros to increase speed
* (since it will use hardware swapping if available).
* Even though they should return uint16 and uint32, we get
* Even though they should return uint16_t and uint32_t, we get
* warnings if we don't cast those (why?) */
#define BSWAP64(x) ((uint64)CFSwapInt64((uint64)(x)))
#define BSWAP32(x) ((uint32)CFSwapInt32((uint32)(x)))
#define BSWAP16(x) ((uint16)CFSwapInt16((uint16)(x)))
#define BSWAP64(x) ((uint64_t)CFSwapInt64((uint64_t)(x)))
#define BSWAP32(x) ((uint32_t)CFSwapInt32((uint32_t)(x)))
#define BSWAP16(x) ((uint16_t)CFSwapInt16((uint16_t)(x)))
#elif defined(_MSC_VER)
/* MSVC has intrinsics for swapping, resulting in faster code */
#define BSWAP64(x) ((uint64)_byteswap_uint64((uint64)(x)))
#define BSWAP32(x) ((uint32)_byteswap_ulong((uint32)(x)))
#define BSWAP16(x) ((uint16)_byteswap_ushort((uint16)(x)))
#define BSWAP64(x) ((uint64_t)_byteswap_uint64((uint64_t)(x)))
#define BSWAP32(x) ((uint32_t)_byteswap_ulong((uint32_t)(x)))
#define BSWAP16(x) ((uint16_t)_byteswap_ushort((uint16_t)(x)))
#else
/**
* Perform a 64 bits endianness bitswap on x.
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint64 BSWAP64(uint64 x)
static inline uint64_t BSWAP64(uint64_t x)
{
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return (uint64)__builtin_bswap64((uint64)x);
return (uint64_t)__builtin_bswap64((uint64_t)x);
#else
return ((x >> 56) & 0xFFULL) | ((x >> 40) & 0xFF00ULL) | ((x >> 24) & 0xFF0000ULL) | ((x >> 8) & 0xFF000000ULL) |
((x << 8) & 0xFF00000000ULL) | ((x << 24) & 0xFF0000000000ULL) | ((x << 40) & 0xFF000000000000ULL) | ((x << 56) & 0xFF00000000000000ULL);
@ -530,11 +530,11 @@ private:
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint32 BSWAP32(uint32 x)
static inline uint32_t BSWAP32(uint32_t x)
{
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return (uint32)__builtin_bswap32((uint32)x);
return (uint32_t)__builtin_bswap32((uint32_t)x);
#else
return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
#endif /* __GNUC__ || __clang__ */
@ -545,11 +545,11 @@ private:
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint16 BSWAP16(uint16 x)
static inline uint16_t BSWAP16(uint16_t x)
{
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return (uint16)__builtin_bswap16((uint16)x);
return (uint16_t)__builtin_bswap16((uint16_t)x);
#else
return (x >> 8) | (x << 8);
#endif /* __GNUC__ || __clang__ */

@ -23,9 +23,9 @@
#endif /* RANDOM_DEBUG */
struct SimpleChecksum64 {
uint64 state = 0;
uint64_t state = 0;
void Update(uint64 input)
void Update(uint64_t input)
{
this->state = ROL(this->state, 1) ^ input ^ 0x123456789ABCDEF7ULL;
}
@ -33,7 +33,7 @@ struct SimpleChecksum64 {
extern SimpleChecksum64 _state_checksum;
inline void UpdateStateChecksum(uint64 input)
inline void UpdateStateChecksum(uint64_t input)
{
if (_networking) _state_checksum.Update(input);
}

@ -48,7 +48,7 @@
inline uint16_t ReadLE16Aligned(const void *x)
{
return FROM_LE16(*(const uint16*)x);
return FROM_LE16(*(const uint16_t*)x);
}
inline uint16_t ReadLE16Unaligned(const void *x)
@ -56,7 +56,7 @@ inline uint16_t ReadLE16Unaligned(const void *x)
#if OTTD_ALIGNMENT == 1
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
#else
return FROM_LE16(*(const uint16*)x);
return FROM_LE16(*(const uint16_t*)x);
#endif /* OTTD_ALIGNMENT == 1 */
}

@ -46,10 +46,10 @@ struct Dimension {
/** Padding dimensions to apply to each side of a Rect. */
struct RectPadding {
uint8 left;
uint8 top;
uint8 right;
uint8 bottom;
uint8_t left;
uint8_t top;
uint8_t right;
uint8_t bottom;
static const RectPadding zero;
@ -225,10 +225,10 @@ struct Rect {
};
struct Rect16 {
int16 left;
int16 top;
int16 right;
int16 bottom;
int16_t left;
int16_t top;
int16_t right;
int16_t bottom;
};
template <typename InT, typename OutT>

@ -14,7 +14,7 @@
* Simple 32 bit to 32 bit hash
* From MurmurHash3
*/
inline uint32 SimpleHash32(uint32 h)
inline uint32_t SimpleHash32(uint32_t h)
{
h ^= h >> 16;
h *= 0x85ebca6b;

@ -57,7 +57,7 @@ int GreatestCommonDivisor(int a, int b)
*/
int DivideApprox(int a, int b)
{
int random_like = (((int64) (a + b)) * ((int64) (a - b))) % b;
int random_like = (((int64_t) (a + b)) * ((int64_t) (a - b))) % b;
int remainder = a % b;
@ -75,10 +75,10 @@ int DivideApprox(int a, int b)
* @return Rounded integer square root.
* @note Algorithm taken from http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
*/
uint32 IntSqrt(uint32 num)
uint32_t IntSqrt(uint32_t num)
{
uint32 res = 0;
uint32 bit = 1UL << 30; // Second to top bit number.
uint32_t res = 0;
uint32_t bit = 1UL << 30; // Second to top bit number.
/* 'bit' starts at the highest power of four <= the argument. */
while (bit > num) bit >>= 2;
@ -105,10 +105,10 @@ uint32 IntSqrt(uint32 num)
* @return Rounded integer square root.
* @note Algorithm taken from http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
*/
uint32 IntSqrt64(uint64 num)
uint32_t IntSqrt64(uint64_t num)
{
uint64 res = 0;
uint64 bit = 1ULL << 62; // Second to top bit number.
uint64_t res = 0;
uint64_t bit = 1ULL << 62; // Second to top bit number.
/* 'bit' starts at the highest power of four <= the argument. */
while (bit > num) bit >>= 2;
@ -126,7 +126,7 @@ uint32 IntSqrt64(uint64 num)
/* Arithmetic rounding to nearest integer. */
if (num > res) res++;
return (uint32)res;
return (uint32_t)res;
}
/**
@ -135,10 +135,10 @@ uint32 IntSqrt64(uint64 num)
* @return Rounded integer square root.
* @note Algorithm taken from https://stackoverflow.com/a/56738014
*/
uint32 IntCbrt(uint64 num)
uint32_t IntCbrt(uint64_t num)
{
uint64 r0 = 1;
uint64 r1 = 0;
uint64_t r0 = 1;
uint64_t r1 = 0;
if (num == 0) return 0;
@ -160,23 +160,23 @@ uint32 IntCbrt(uint64 num)
}
while (r0 < r1);
return ((uint32) r1); /* floor(cbrt(x)); */
return ((uint32_t) r1); /* floor(cbrt(x)); */
}
/**
* Compress unsigned integer into 16 bits, in a way that increases dynamic range, at the expense of precision for large values
*/
uint16 RXCompressUint(uint32 num)
uint16_t RXCompressUint(uint32_t num)
{
if (num <= 0x100) return num;
if (num <= 0x7900) return 0x100 + ((num - 0x100) >> 3);
return std::min<uint32>(UINT16_MAX, 0x1000 + ((num - 0x7900) >> 6));
return std::min<uint32_t>(UINT16_MAX, 0x1000 + ((num - 0x7900) >> 6));
}
/**
* Inverse of RXCompressUint
*/
uint32 RXDecompressUint(uint16 num)
uint32_t RXDecompressUint(uint16_t num)
{
if (num > 0x1000) return ((num - 0x1000) << 6) + 0x7900;
if (num > 0x100) return ((num - 0x100) << 3) + 0x100;

@ -420,11 +420,11 @@ inline T DivTowardsPositiveInf(T a, T b)
return (a / b) + (a % b > 0 ? 1 : 0);
}
uint32 IntSqrt(uint32 num);
uint32 IntSqrt64(uint64 num);
uint32 IntCbrt(uint64 num);
uint32_t IntSqrt(uint32_t num);
uint32_t IntSqrt64(uint64_t num);
uint32_t IntCbrt(uint64_t num);
uint16 RXCompressUint(uint32 num);
uint32 RXDecompressUint(uint16 num);
uint16_t RXCompressUint(uint32_t num);
uint32_t RXDecompressUint(uint16_t num);
#endif /* MATH_FUNC_HPP */

@ -89,11 +89,11 @@ public:
/* Operators for addition and subtraction. */
inline constexpr OverflowSafeInt operator + (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result += other; return result; }
inline constexpr OverflowSafeInt operator + (const int other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
inline constexpr OverflowSafeInt operator + (const uint other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
inline constexpr OverflowSafeInt operator + (const int other) const { OverflowSafeInt result = *this; result += (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator + (const uint other) const { OverflowSafeInt result = *this; result += (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator - (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result -= other; return result; }
inline constexpr OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
inline constexpr OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
inline constexpr OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64_t)other; return result; }
inline constexpr OverflowSafeInt& operator ++ () { return *this += 1; }
inline constexpr OverflowSafeInt& operator -- () { return *this += -1; }
@ -134,14 +134,14 @@ public:
}
/* Operators for multiplication. */
inline constexpr OverflowSafeInt operator * (const int64 factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
inline constexpr OverflowSafeInt operator * (const int factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint16 factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const int64_t factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
inline constexpr OverflowSafeInt operator * (const int factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint16_t factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
/* Operators for division. */
inline constexpr OverflowSafeInt& operator /= (const int64 divisor) { this->m_value /= divisor; return *this; }
inline constexpr OverflowSafeInt& operator /= (const int64_t divisor) { this->m_value /= divisor; return *this; }
inline constexpr OverflowSafeInt operator / (const OverflowSafeInt& divisor) const { OverflowSafeInt result = *this; result /= divisor.m_value; return result; }
inline constexpr OverflowSafeInt operator / (const int divisor) const { OverflowSafeInt result = *this; result /= divisor; return result; }
inline constexpr OverflowSafeInt operator / (const uint divisor) const { OverflowSafeInt result = *this; result /= (int)divisor; return result; }
@ -179,11 +179,11 @@ public:
};
/* Sometimes we got int64 operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int64 a, const OverflowSafeInt<T> b) { return b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator - (const int64 a, const OverflowSafeInt<T> b) { return -b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator * (const int64 a, const OverflowSafeInt<T> b) { return b * a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const int64 a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
/* Sometimes we got int64_t operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int64_t a, const OverflowSafeInt<T> b) { return b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator - (const int64_t a, const OverflowSafeInt<T> b) { return -b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator * (const int64_t a, const OverflowSafeInt<T> b) { return b * a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const int64_t a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
/* Sometimes we got int operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int a, const OverflowSafeInt<T> b) { return b + a; }
@ -203,8 +203,8 @@ template <class T> inline constexpr OverflowSafeInt<T> operator - (const byte a
template <class T> inline constexpr OverflowSafeInt<T> operator * (const byte a, const OverflowSafeInt<T> b) { return b * (uint)a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const byte a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
typedef OverflowSafeInt<int64> OverflowSafeInt64;
typedef OverflowSafeInt<int32> OverflowSafeInt32;
typedef OverflowSafeInt<int64_t> OverflowSafeInt64;
typedef OverflowSafeInt<int32_t> OverflowSafeInt32;
/* Some basic "unit tests". Also has the bonus of confirming that constexpr is working. */
static_assert(OverflowSafeInt32(INT32_MIN) - 1 == OverflowSafeInt32(INT32_MIN));

@ -15,7 +15,7 @@
/**
* Pool-type container for POD data..
*/
template <typename PTR, size_t SIZE, uint N_PER_CHUNK, typename IDX = uint32>
template <typename PTR, size_t SIZE, uint N_PER_CHUNK, typename IDX = uint32_t>
class PodPool {
static_assert(SIZE >= sizeof(IDX));

@ -63,7 +63,7 @@ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index)
this->free_bitmap = ReallocT(this->free_bitmap, CeilDivT<size_t>(new_size, 64));
MemSetT(this->free_bitmap + CeilDivT<size_t>(this->size, 64), 0, CeilDivT<size_t>(new_size, 64) - CeilDivT<size_t>(this->size, 64));
if (new_size % 64 != 0) {
this->free_bitmap[new_size / 64] |= (~((uint64) 0)) << (new_size % 64);
this->free_bitmap[new_size / 64] |= (~((uint64_t) 0)) << (new_size % 64);
}
this->size = new_size;
@ -79,7 +79,7 @@ DEFINE_POOL_METHOD(inline size_t)::FindFirstFree()
size_t bitmap_end = CeilDivT<size_t>(this->first_unused, 64);
for (; bitmap_index < bitmap_end; bitmap_index++) {
uint64 available = ~this->free_bitmap[bitmap_index];
uint64_t available = ~this->free_bitmap[bitmap_index];
if (available == 0) continue;
return (bitmap_index * 64) + FindFirstBit(available);
}

@ -80,7 +80,7 @@ private:
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
/* Ensure Tmax_size is within the bounds of Tindex. */
static_assert((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static_assert((uint64_t)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static constexpr size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside
@ -96,7 +96,7 @@ struct Pool : PoolBase {
bool cleaning; ///< True if cleaning pool (deleting all items)
Titem **data; ///< Pointer to array of pointers to Titem
uint64 *free_bitmap; ///< Pointer to free bitmap
uint64_t *free_bitmap; ///< Pointer to free bitmap
Pool(const char *name);
void CleanPool() override;

@ -28,10 +28,10 @@ Randomizer _random, _interactive_random;
* Generate the next pseudo random number
* @return the random number
*/
uint32 Randomizer::Next()
uint32_t Randomizer::Next()
{
const uint32 s = this->state[0];
const uint32 t = this->state[1];
const uint32_t s = this->state[0];
const uint32_t t = this->state[1];
this->state[0] = s + ROR(t ^ 0x1234567F, 7) + 1;
return this->state[1] = ROR(s, 3) - 1;
@ -43,16 +43,16 @@ uint32 Randomizer::Next()
* @param limit Limit of the range to be generated from.
* @return Random number in [0,\a limit)
*/
uint32 Randomizer::Next(uint32 limit)
uint32_t Randomizer::Next(uint32_t limit)
{
return ((uint64)this->Next() * (uint64)limit) >> 32;
return ((uint64_t)this->Next() * (uint64_t)limit) >> 32;
}
/**
* (Re)set the state of the random number generator.
* @param seed the new state
*/
void Randomizer::SetSeed(uint32 seed)
void Randomizer::SetSeed(uint32_t seed)
{
this->state[0] = seed;
this->state[1] = seed;
@ -62,14 +62,14 @@ void Randomizer::SetSeed(uint32 seed)
* (Re)set the state of the random number generators.
* @param seed the new state
*/
void SetRandomSeed(uint32 seed)
void SetRandomSeed(uint32_t seed)
{
_random.SetSeed(seed);
_interactive_random.SetSeed(seed * 0x1234567);
}
#ifdef RANDOM_DEBUG
uint32 DoRandom(int line, const char *file)
uint32_t DoRandom(int line, const char *file)
{
if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) {
DEBUG(random, 0, "%s; %04x; %02x; %s:%d", debug_date_dumper().HexDate(), _frame_counter, (byte)_current_company, file, line);
@ -78,8 +78,8 @@ uint32 DoRandom(int line, const char *file)
return _random.Next();
}
uint32 DoRandomRange(uint32 limit, int line, const char *file)
uint32_t DoRandomRange(uint32_t limit, int line, const char *file)
{
return ((uint64)DoRandom(line, file) * (uint64)limit) >> 32;
return ((uint64_t)DoRandom(line, file) * (uint64_t)limit) >> 32;
}
#endif /* RANDOM_DEBUG */

@ -22,11 +22,11 @@
*/
struct Randomizer {
/** The state of the randomizer */
uint32 state[2];
uint32_t state[2];
uint32 Next();
uint32 Next(uint32 limit);
void SetSeed(uint32 seed);
uint32_t Next();
uint32_t Next(uint32_t limit);
void SetSeed(uint32_t seed);
};
extern Randomizer _random; ///< Random used in the game state calculations
extern Randomizer _interactive_random; ///< Random used everywhere else, where it does not (directly) influence the game state
@ -73,18 +73,18 @@ public:
}
};
void SetRandomSeed(uint32 seed);
void SetRandomSeed(uint32_t seed);
#ifdef RANDOM_DEBUG
# ifdef __APPLE__
# define OTTD_Random() DoRandom(__LINE__, __FILE__)
# else
# define Random() DoRandom(__LINE__, __FILE__)
# endif
uint32 DoRandom(int line, const char *file);
uint32_t DoRandom(int line, const char *file);
# define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
uint32 DoRandomRange(uint32 limit, int line, const char *file);
uint32_t DoRandomRange(uint32_t limit, int line, const char *file);
#else
static inline uint32 Random()
static inline uint32_t Random()
{
return _random.Next();
}
@ -96,7 +96,7 @@ void SetRandomSeed(uint32 seed);
* @param limit Limit for the range to be picked from.
* @return A random number in [0,\a limit).
*/
static inline uint32 RandomRange(uint32 limit)
static inline uint32_t RandomRange(uint32_t limit)
{
return _random.Next(limit);
}
@ -130,7 +130,7 @@ inline uint32_t InteractiveRandomRange(uint32_t limit)
inline bool Chance16I(const uint a, const uint b, const uint32_t r)
{
assert(b != 0);
return (((uint16)r * b + b / 2) >> 16) < a;
return (((uint16_t)r * b + b / 2) >> 16) < a;
}
/**

@ -26,14 +26,14 @@ template <class T>
class ring_buffer
{
std::unique_ptr<byte, FreeDeleter> data;
uint32 head = 0;
uint32 count = 0;
uint32 mask = (uint32)-1;
uint32_t head = 0;
uint32_t count = 0;
uint32_t mask = (uint32_t)-1;
static uint32 round_up_size(uint32 size)
static uint32_t round_up_size(uint32_t size)
{
if (size <= 4) return 4;
uint8 bit = FindLastBit(size - 1);
uint8_t bit = FindLastBit(size - 1);
return 1 << (bit + 1);
}
@ -43,15 +43,15 @@ class ring_buffer
protected:
const ring_buffer *ring = nullptr;
uint32 pos = 0;
uint32_t pos = 0;
ring_buffer_iterator_base() {}
ring_buffer_iterator_base(const ring_buffer *ring, uint32 pos)
ring_buffer_iterator_base(const ring_buffer *ring, uint32_t pos)
: ring(ring), pos(pos) {}
public:
uint32 debug_raw_position() const { return this->pos; }
uint32_t debug_raw_position() const { return this->pos; }
};
public:
@ -68,7 +68,7 @@ public:
: ring_buffer_iterator_base(other.ring, other.pos) {}
private:
ring_buffer_iterator(const ring_buffer *ring, uint32 pos)
ring_buffer_iterator(const ring_buffer *ring, uint32_t pos)
: ring_buffer_iterator_base(ring, pos) {}
void next()
@ -92,9 +92,9 @@ public:
void move(std::ptrdiff_t delta)
{
if (REVERSE) {
this->pos -= (uint32)delta;
this->pos -= (uint32_t)delta;
} else {
this->pos += (uint32)delta;
this->pos += (uint32_t)delta;
}
}
@ -185,9 +185,9 @@ public:
{
dbg_assert(this->ring == other.ring);
if (REVERSE) {
return (int32)(other.pos - this->pos);
return (int32_t)(other.pos - this->pos);
} else {
return (int32)(this->pos - other.pos);
return (int32_t)(this->pos - other.pos);
}
}
};
@ -207,11 +207,11 @@ public:
template <typename U>
void construct_from(const U &other)
{
uint32 cap = round_up_size((uint32)other.size());
uint32_t cap = round_up_size((uint32_t)other.size());
this->data.reset(MallocT<byte>(cap * sizeof(T)));
this->mask = cap - 1;
this->head = 0;
this->count = (uint32)other.size();
this->count = (uint32_t)other.size();
byte *ptr = this->data.get();
for (const T &item : other) {
new (ptr) T(item);
@ -247,7 +247,7 @@ public:
this->clear();
if (!other.empty()) {
if (other.size() > this->capacity()) {
uint32 cap = round_up_size(other.count);
uint32_t cap = round_up_size(other.count);
this->data.reset(MallocT<byte>(cap * sizeof(T)));
this->mask = cap - 1;
}
@ -332,9 +332,9 @@ public:
}
private:
void reallocate(uint32 new_cap)
void reallocate(uint32_t new_cap)
{
const uint32 cap = round_up_size(new_cap);
const uint32_t cap = round_up_size(new_cap);
byte *new_buf = MallocT<byte>(cap * sizeof(T));
byte *pos = new_buf;
for (T &item : *this) {
@ -347,22 +347,22 @@ private:
this->data.reset(new_buf);
}
void *raw_ptr_at_pos(uint32 idx) const
void *raw_ptr_at_pos(uint32_t idx) const
{
return this->data.get() + (sizeof(T) * (idx & this->mask));
}
void *raw_ptr_at_offset(uint32 idx) const
void *raw_ptr_at_offset(uint32_t idx) const
{
return this->raw_ptr_at_pos(this->head + idx);
}
T *ptr_at_pos(uint32 idx) const
T *ptr_at_pos(uint32_t idx) const
{
return static_cast<T *>(this->raw_ptr_at_pos(idx));
}
T *ptr_at_offset(uint32 idx) const
T *ptr_at_offset(uint32_t idx) const
{
return static_cast<T *>(this->raw_ptr_at_offset(idx));
}
@ -511,15 +511,15 @@ public:
}
private:
uint32 setup_insert(uint32 pos, uint32 num)
uint32_t setup_insert(uint32_t pos, uint32_t num)
{
if (this->count + num > (uint32)this->capacity()) {
if (this->count + num > (uint32_t)this->capacity()) {
/* grow container */
const uint32 cap = round_up_size(this->count + num);
const uint32_t cap = round_up_size(this->count + num);
byte *new_buf = MallocT<byte>(cap * sizeof(T));
byte *write_to = new_buf;
const uint32 end = this->head + this->count;
for (uint32 idx = this->head; idx != end; idx++) {
const uint32_t end = this->head + this->count;
for (uint32_t idx = this->head; idx != end; idx++) {
if (idx == pos) {
/* gap for inserted items */
write_to += num * sizeof(T);
@ -529,7 +529,7 @@ private:
item.~T();
write_to += sizeof(T);
}
uint32 res = pos - this->head;
uint32_t res = pos - this->head;
this->mask = cap - 1;
this->head = 0;
this->count += num;
@ -548,17 +548,17 @@ private:
/* middle, move data */
if (pos - this->head < (this->count / 2)) {
/* closer to the beginning, shuffle those backwards */
const uint32 new_head = this->head - num;
const uint32 insert_start = pos - num;
for (uint32 idx = new_head; idx != this->head; idx++) {
const uint32_t new_head = this->head - num;
const uint32_t insert_start = pos - num;
for (uint32_t idx = new_head; idx != this->head; idx++) {
/* Move construct to move backwards into uninitialised region */
new (this->raw_ptr_at_pos(idx)) T(std::move(*(this->ptr_at_pos(idx + num))));
}
for (uint32 idx = this->head; idx != insert_start; idx++) {
for (uint32_t idx = this->head; idx != insert_start; idx++) {
/* Move assign to move backwards in initialised region */
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx + num));
}
for (uint32 idx = insert_start; idx != pos; idx++) {
for (uint32_t idx = insert_start; idx != pos; idx++) {
/* Destruct to leave space for inserts */
this->ptr_at_pos(idx)->~T();
}
@ -567,18 +567,18 @@ private:
return insert_start;
} else {
/* closer to the end, shuffle those forwards */
const uint32 last_inserted = pos + num - 1;
const uint32 last = this->head + this->count - 1;
const uint32 new_last = last + num;
for (uint32 idx = new_last; idx != last; idx--) {
const uint32_t last_inserted = pos + num - 1;
const uint32_t last = this->head + this->count - 1;
const uint32_t new_last = last + num;
for (uint32_t idx = new_last; idx != last; idx--) {
/* Move construct to move forwards into uninitialised region */
new (this->raw_ptr_at_pos(idx)) T(std::move(*(this->ptr_at_pos(idx - num))));
}
for (uint32 idx = last; idx != last_inserted; idx--) {
for (uint32_t idx = last; idx != last_inserted; idx--) {
/* Move assign to move forwards in initialised region */
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx - num));
}
for (uint32 idx = last_inserted; idx != pos; idx--) {
for (uint32_t idx = last_inserted; idx != pos; idx--) {
/* Destruct to leave space for inserts */
this->ptr_at_pos(idx)->~T();
}
@ -594,7 +594,7 @@ public:
{
dbg_assert(pos.ring == this);
uint32 new_pos = this->setup_insert(pos.pos, 1);
uint32_t new_pos = this->setup_insert(pos.pos, 1);
new (this->raw_ptr_at_pos(new_pos)) T(std::forward<Args>(args)...);
return iterator(this, new_pos);
}
@ -615,8 +615,8 @@ public:
dbg_assert(pos.ring == this);
const uint32 new_pos_start = this->setup_insert(pos.pos, (uint32)count);
uint32 new_pos = new_pos_start;
const uint32_t new_pos_start = this->setup_insert(pos.pos, (uint32_t)count);
uint32_t new_pos = new_pos_start;
for (size_t i = 0; i != count; i++) {
new (this->raw_ptr_at_pos(new_pos)) T(value);
++new_pos;
@ -631,8 +631,8 @@ public:
dbg_assert(pos.ring == this);
const uint32 new_pos_start = this->setup_insert(pos.pos, (uint32)std::distance(first, last));
uint32 new_pos = new_pos_start;
const uint32_t new_pos_start = this->setup_insert(pos.pos, (uint32_t)std::distance(first, last));
uint32_t new_pos = new_pos_start;
for (auto iter = first; iter != last; ++iter) {
new (this->raw_ptr_at_pos(new_pos)) T(*iter);
++new_pos;
@ -646,11 +646,11 @@ public:
}
private:
uint32 do_erase(uint32 pos, uint32 num)
uint32_t do_erase(uint32_t pos, uint32_t num)
{
if (pos == this->head) {
/* erase from beginning */
for (uint32 i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
this->ptr_at_pos(pos + i)->~T();
}
this->head += num;
@ -658,19 +658,19 @@ private:
return this->head;
} else if (pos + num == this->head + this->count) {
/* erase from end */
for (uint32 i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
this->ptr_at_pos(pos + i)->~T();
}
this->count -= num;
return pos;
} else if (pos - this->head < this->head + this->count - (pos + num)) {
/* closer to the beginning, shuffle beginning forwards to fill gap */
const uint32 new_head = this->head + num;
const uint32 erase_end = pos + num;
for (uint32 idx = erase_end - 1; idx != new_head - 1; idx--) {
const uint32_t new_head = this->head + num;
const uint32_t erase_end = pos + num;
for (uint32_t idx = erase_end - 1; idx != new_head - 1; idx--) {
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx - num));
}
for (uint32 idx = new_head - 1; idx != this->head - 1; idx--) {
for (uint32_t idx = new_head - 1; idx != this->head - 1; idx--) {
this->ptr_at_pos(idx)->~T();
}
this->head = new_head;
@ -678,12 +678,12 @@ private:
return pos + num;
} else {
/* closer to the end, shuffle end backwards to fill gap */
const uint32 current_end = this->head + this->count;
const uint32 new_end = current_end - num;
for (uint32 idx = pos; idx != new_end; idx++) {
const uint32_t current_end = this->head + this->count;
const uint32_t new_end = current_end - num;
for (uint32_t idx = pos; idx != new_end; idx++) {
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx + num));
}
for (uint32 idx = new_end; idx != current_end; idx++) {
for (uint32_t idx = new_end; idx != current_end; idx++) {
this->ptr_at_pos(idx)->~T();
}
this->count -= num;
@ -712,24 +712,24 @@ public:
{
if (new_cap <= this->capacity()) return;
this->reallocate((uint32)new_cap);
this->reallocate((uint32_t)new_cap);
}
void resize(size_t new_size)
{
if (new_size < this->size()) {
for (uint32 i = (uint32)new_size; i != this->count; i++) {
for (uint32_t i = (uint32_t)new_size; i != this->count; i++) {
this->ptr_at_offset(i)->~T();
}
} else if (new_size > this->size()) {
if (new_size > this->capacity()) {
this->reallocate((uint32)new_size);
this->reallocate((uint32_t)new_size);
}
for (uint32 i = this->count; i != (uint32)new_size; i++) {
for (uint32_t i = this->count; i != (uint32_t)new_size; i++) {
new (this->raw_ptr_at_offset(i)) T();
}
}
this->count = (uint32)new_size;
this->count = (uint32_t)new_size;
}
void shrink_to_fit()
@ -737,7 +737,7 @@ public:
if (this->empty()) {
this->clear();
this->data.reset();
this->mask = (uint32)-1;
this->mask = (uint32_t)-1;
} else if (round_up_size(this->count) < this->capacity()) {
this->reallocate(this->count);
}
@ -745,12 +745,12 @@ public:
T &operator[](size_t index)
{
return *this->ptr_at_offset((uint32)index);
return *this->ptr_at_offset((uint32_t)index);
}
const T &operator[](size_t index) const
{
return *this->ptr_at_offset((uint32)index);
return *this->ptr_at_offset((uint32_t)index);
}
};

@ -23,13 +23,13 @@
/*
* The next couple of functions make sure we can send
* uint8, uint16, uint32 and uint64 endian-safe
* uint8_t, uint16_t, uint32_t and uint64_t endian-safe
* over the network. The least significant bytes are
* sent first.
*
* So 0x01234567 would be sent as 67 45 23 01.
*
* A bool is sent as a uint8 where zero means false
* A bool is sent as a uint8_t where zero means false
* and non-zero means true.
*/
@ -46,7 +46,7 @@ void BufferSend_bool(std::vector<byte> &buffer, size_t limit, bool data)
* Package a 8 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint8(std::vector<byte> &buffer, size_t limit, uint8 data)
void BufferSend_uint8(std::vector<byte> &buffer, size_t limit, uint8_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.emplace_back(data);
@ -56,12 +56,12 @@ void BufferSend_uint8(std::vector<byte> &buffer, size_t limit, uint8 data)
* Package a 16 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16 data)
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.insert(buffer.end(), {
(uint8)GB(data, 0, 8),
(uint8)GB(data, 8, 8),
(uint8_t)GB(data, 0, 8),
(uint8_t)GB(data, 8, 8),
});
}
@ -69,14 +69,14 @@ void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16 data)
* Package a 32 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32 data)
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.insert(buffer.end(), {
(uint8)GB(data, 0, 8),
(uint8)GB(data, 8, 8),
(uint8)GB(data, 16, 8),
(uint8)GB(data, 24, 8),
(uint8_t)GB(data, 0, 8),
(uint8_t)GB(data, 8, 8),
(uint8_t)GB(data, 16, 8),
(uint8_t)GB(data, 24, 8),
});
}
@ -84,18 +84,18 @@ void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32 data)
* Package a 64 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64 data)
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.insert(buffer.end(), {
(uint8)GB(data, 0, 8),
(uint8)GB(data, 8, 8),
(uint8)GB(data, 16, 8),
(uint8)GB(data, 24, 8),
(uint8)GB(data, 32, 8),
(uint8)GB(data, 40, 8),
(uint8)GB(data, 48, 8),
(uint8)GB(data, 56, 8),
(uint8_t)GB(data, 0, 8),
(uint8_t)GB(data, 8, 8),
(uint8_t)GB(data, 16, 8),
(uint8_t)GB(data, 24, 8),
(uint8_t)GB(data, 32, 8),
(uint8_t)GB(data, 40, 8),
(uint8_t)GB(data, 48, 8),
(uint8_t)GB(data, 56, 8),
});
}
@ -147,8 +147,8 @@ void BufferSend_buffer(std::vector<byte> &buffer, size_t limit, const byte *data
assert(size <= UINT16_MAX);
assert(BufferCanWriteToPacket(buffer, limit, size + 2));
buffer.insert(buffer.end(), {
(uint8)GB(size, 0, 8),
(uint8)GB(size, 8, 8),
(uint8_t)GB(size, 0, 8),
(uint8_t)GB(size, 8, 8),
});
buffer.insert(buffer.end(), data, data + size);
}

@ -20,10 +20,10 @@
#include <limits>
void BufferSend_bool (std::vector<byte> &buffer, size_t limit, bool data);
void BufferSend_uint8 (std::vector<byte> &buffer, size_t limit, uint8 data);
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16 data);
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32 data);
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64 data);
void BufferSend_uint8 (std::vector<byte> &buffer, size_t limit, uint8_t data);
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16_t data);
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32_t data);
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64_t data);
void BufferSend_string(std::vector<byte> &buffer, size_t limit, const std::string_view data);
size_t BufferSend_binary_until_full(std::vector<byte> &buffer, size_t limit, const byte *begin, const byte *end);
void BufferSend_binary(std::vector<byte> &buffer, size_t limit, const byte *data, const size_t size);
@ -37,25 +37,25 @@ struct BufferSerialisationHelper {
BufferSend_bool(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint8(uint8 data)
void Send_uint8(uint8_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint8(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint16(uint16 data)
void Send_uint16(uint16_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint16(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint32(uint32 data)
void Send_uint32(uint32_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint32(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint64(uint64 data)
void Send_uint64(uint64_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint64(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
@ -130,9 +130,9 @@ public:
* Read a 8 bits integer from the packet.
* @return The read data.
*/
uint8 Recv_uint8()
uint8_t Recv_uint8()
{
uint8 n;
uint8_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
@ -146,16 +146,16 @@ public:
* Read a 16 bits integer from the packet.
* @return The read data.
*/
uint16 Recv_uint16()
uint16_t Recv_uint16()
{
uint16 n;
uint16_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
n = (uint16)this->GetBuffer()[pos++];
n += (uint16)this->GetBuffer()[pos++] << 8;
n = (uint16_t)this->GetBuffer()[pos++];
n += (uint16_t)this->GetBuffer()[pos++] << 8;
return n;
}
@ -163,18 +163,18 @@ public:
* Read a 32 bits integer from the packet.
* @return The read data.
*/
uint32 Recv_uint32()
uint32_t Recv_uint32()
{
uint32 n;
uint32_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
n = (uint32)this->GetBuffer()[pos++];
n += (uint32)this->GetBuffer()[pos++] << 8;
n += (uint32)this->GetBuffer()[pos++] << 16;
n += (uint32)this->GetBuffer()[pos++] << 24;
n = (uint32_t)this->GetBuffer()[pos++];
n += (uint32_t)this->GetBuffer()[pos++] << 8;
n += (uint32_t)this->GetBuffer()[pos++] << 16;
n += (uint32_t)this->GetBuffer()[pos++] << 24;
return n;
}
@ -182,22 +182,22 @@ public:
* Read a 64 bits integer from the packet.
* @return The read data.
*/
uint64 Recv_uint64()
uint64_t Recv_uint64()
{
uint64 n;
uint64_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
n = (uint64)this->GetBuffer()[pos++];
n += (uint64)this->GetBuffer()[pos++] << 8;
n += (uint64)this->GetBuffer()[pos++] << 16;
n += (uint64)this->GetBuffer()[pos++] << 24;
n += (uint64)this->GetBuffer()[pos++] << 32;
n += (uint64)this->GetBuffer()[pos++] << 40;
n += (uint64)this->GetBuffer()[pos++] << 48;
n += (uint64)this->GetBuffer()[pos++] << 56;
n = (uint64_t)this->GetBuffer()[pos++];
n += (uint64_t)this->GetBuffer()[pos++] << 8;
n += (uint64_t)this->GetBuffer()[pos++] << 16;
n += (uint64_t)this->GetBuffer()[pos++] << 24;
n += (uint64_t)this->GetBuffer()[pos++] << 32;
n += (uint64_t)this->GetBuffer()[pos++] << 40;
n += (uint64_t)this->GetBuffer()[pos++] << 48;
n += (uint64_t)this->GetBuffer()[pos++] << 56;
return n;
}
@ -269,13 +269,13 @@ public:
* @param size The size of the data.
* @return The view of the data.
*/
span<const uint8> Recv_binary_view(size_t size)
span<const uint8_t> Recv_binary_view(size_t size)
{
if (!this->CanRecvBytes(size, true)) return {};
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
span<const uint8> view { &this->GetBuffer()[pos], size };
span<const uint8_t> view { &this->GetBuffer()[pos], size };
pos += (decltype(pos)) size;
return view;
@ -286,9 +286,9 @@ public:
* @param size The size of the data.
* @return The binary buffer.
*/
std::vector<uint8> Recv_binary(size_t size)
std::vector<uint8_t> Recv_binary(size_t size)
{
span<const uint8> view = this->Recv_binary_view(size);
span<const uint8_t> view = this->Recv_binary_view(size);
return { view.begin(), view.end() };
}
@ -297,14 +297,14 @@ public:
* Returns a view of a length-prefixed binary buffer from the packet.
* @return The binary buffer.
*/
span<const uint8> Recv_buffer_view()
span<const uint8_t> Recv_buffer_view()
{
uint16 length = this->Recv_uint16();
uint16_t length = this->Recv_uint16();
if (!this->CanRecvBytes(length, true)) return {};
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
span<const uint8> buffer { &this->GetBuffer()[pos], length };
span<const uint8_t> buffer { &this->GetBuffer()[pos], length };
pos += length;
return buffer;
@ -314,9 +314,9 @@ public:
* Reads a length-prefixed binary buffer from the packet.
* @return The binary buffer.
*/
std::vector<uint8> Recv_buffer()
std::vector<uint8_t> Recv_buffer()
{
span<const uint8> view = this->Recv_buffer_view();
span<const uint8_t> view = this->Recv_buffer_view();
return { view.begin(), view.end() };
}

@ -19,7 +19,7 @@
#if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE)
#include <intrin.h>
#include <windows.h>
uint64 ottd_rdtsc()
uint64_t ottd_rdtsc()
{
#if defined(_M_ARM)
return __rdpmccntr64();
@ -34,20 +34,20 @@ uint64 ottd_rdtsc()
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
#if (defined(__i386__) || defined(__x86_64__)) && !defined(RDTSC_AVAILABLE)
uint64 ottd_rdtsc()
uint64_t ottd_rdtsc()
{
uint32 high, low;
uint32_t high, low;
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
return ((uint64)high << 32) | low;
return ((uint64_t)high << 32) | low;
}
# define RDTSC_AVAILABLE
#endif
/* rdtsc for AARCH64. Use GCC syntax */
#if defined(__aarch64__) && !defined(RDTSC_AVAILABLE)
uint64 ottd_rdtsc()
uint64_t ottd_rdtsc()
{
uint64 val;
uint64_t val;
asm volatile("mrs %0, cntvct_el0" : "=r" (val));
return val;
}
@ -56,9 +56,9 @@ uint64 ottd_rdtsc()
/* rdtsc for PPC which has this not */
#if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE)
uint64 ottd_rdtsc()
uint64_t ottd_rdtsc()
{
uint32 high = 0, high2 = 0, low;
uint32_t high = 0, high2 = 0, low;
/* PPC does not have rdtsc, so we cheat by reading the two 32-bit time-counters
* it has, 'Move From Time Base (Upper)'. Since these are two reads, in the
* very unlikely event that the lower part overflows to the upper part while we
@ -72,14 +72,14 @@ uint64 ottd_rdtsc()
: "=r" (high), "=r" (low), "=r" (high2)
: "0" (high), "2" (high2)
);
return ((uint64)high << 32) | low;
return ((uint64_t)high << 32) | low;
}
# define RDTSC_AVAILABLE
#endif
/* rdtsc for MCST Elbrus 2000 */
#if defined(__e2k__) && !defined(RDTSC_AVAILABLE)
uint64 ottd_rdtsc()
uint64_t ottd_rdtsc()
{
uint64_t dst;
# pragma asm_inline
@ -91,7 +91,7 @@ uint64 ottd_rdtsc()
#if defined(__EMSCRIPTEN__) && !defined(RDTSC_AVAILABLE)
/* On emscripten doing TIC/TOC would be ill-advised */
uint64 ottd_rdtsc() {return 0;}
uint64_t ottd_rdtsc() {return 0;}
# define RDTSC_AVAILABLE
#endif
@ -99,7 +99,7 @@ uint64 ottd_rdtsc() {return 0;}
* you just won't be able to profile your code with TIC()/TOC() */
#if !defined(RDTSC_AVAILABLE)
#warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC"
uint64 ottd_rdtsc() {return 0;}
uint64_t ottd_rdtsc() {return 0;}
#endif

@ -14,7 +14,7 @@
* Get the tick counter from the CPU (high precision timing).
* @return The count.
*/
uint64 ottd_rdtsc();
uint64_t ottd_rdtsc();
/**
* Get the CPUID information from the CPU.

@ -215,7 +215,7 @@ char *CrashLog::LogOpenTTDVersion(char *buffer, const char *last) const
*/
char *CrashLog::LogConfiguration(char *buffer, const char *last) const
{
auto pathfinder_name = [](uint8 pf) -> const char * {
auto pathfinder_name = [](uint8_t pf) -> const char * {
switch (pf) {
case VPF_NPF: return "NPF";
case VPF_YAPF: return "YAPF";
@ -560,7 +560,7 @@ char *CrashLog::FillCrashLog(char *buffer, const char *last)
buffer = this->TryCrashLogFaultSection(buffer, last, "network sync", [](CrashLog *self, char *buffer, const char *last) -> char * {
if (IsGameThread() && _record_sync_records && !_network_sync_records.empty()) {
uint total = 0;
for (uint32 count : _network_sync_record_counts) {
for (uint32_t count : _network_sync_record_counts) {
total += count;
}
NetworkSyncRecordEvents event = NSRE_BEGIN;
@ -648,7 +648,7 @@ char *CrashLog::FillDesyncCrashLog(char *buffer, const char *last, const DesyncE
buffer += seprintf(buffer, last, "%s\n", info.desync_frame_info.c_str());
}
extern uint32 _frame_counter;
extern uint32_t _frame_counter;
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i, %i) (DL: %u), %08X\n",
_cur_date_ymd.year, _cur_date_ymd.month + 1, _cur_date_ymd.day, _date_fract, _tick_skip_counter, _settings_game.economy.day_length_factor, _frame_counter);
@ -661,8 +661,8 @@ char *CrashLog::FillDesyncCrashLog(char *buffer, const char *last, const DesyncE
if (!_network_server) {
extern Date _last_sync_date;
extern DateFract _last_sync_date_fract;
extern uint8 _last_sync_tick_skip_counter;
extern uint32 _last_sync_frame_counter;
extern uint8_t _last_sync_tick_skip_counter;
extern uint32_t _last_sync_frame_counter;
YearMonthDay ymd = ConvertDateToYMD(_last_sync_date);
buffer += seprintf(buffer, last, "Last sync at: %i-%02i-%02i (%i, %i), %08X\n",
@ -713,7 +713,7 @@ char *CrashLog::FillInconsistencyLog(char *buffer, const char *last, const Incon
buffer += WriteScopeLog(buffer, last);
#endif
extern uint32 _frame_counter;
extern uint32_t _frame_counter;
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i, %i) (DL: %u), %08X\n",
_cur_date_ymd.year, _cur_date_ymd.month + 1, _cur_date_ymd.day, _date_fract, _tick_skip_counter, _settings_game.economy.day_length_factor, _frame_counter);
@ -726,8 +726,8 @@ char *CrashLog::FillInconsistencyLog(char *buffer, const char *last, const Incon
if (_networking && !_network_server) {
extern Date _last_sync_date;
extern DateFract _last_sync_date_fract;
extern uint8 _last_sync_tick_skip_counter;
extern uint32 _last_sync_frame_counter;
extern uint8_t _last_sync_tick_skip_counter;
extern uint32_t _last_sync_frame_counter;
YearMonthDay ymd = ConvertDateToYMD(_last_sync_date);
buffer += seprintf(buffer, last, "Last sync at: %i-%02i-%02i (%i, %i), %08X\n",

@ -119,9 +119,9 @@ byte GetNewgrfCurrencyIdConverted(byte grfcurr_id)
* get a mask of the allowed currencies depending on the year
* @return mask of currencies
*/
uint64 GetMaskOfAllowedCurrencies()
uint64_t GetMaskOfAllowedCurrencies()
{
uint64 mask = 0LL;
uint64_t mask = 0LL;
uint i;
for (i = 0; i < CURRENCY_END; i++) {

@ -70,7 +70,7 @@ enum Currencies {
/** Specification of a currency. */
struct CurrencySpec {
uint16 rate; ///< The conversion rate compared to the base currency.
uint16_t rate; ///< The conversion rate compared to the base currency.
std::string separator; ///< The thousands separator for this currency.
Year to_euro; ///< %Year of switching to the Euro. May also be #CF_NOEURO or #CF_ISEURO.
std::string prefix; ///< Prefix to apply when formatting money in this currency.
@ -90,7 +90,7 @@ struct CurrencySpec {
CurrencySpec() = default;
CurrencySpec(uint16 rate, const char *separator, Year to_euro, const char *prefix, const char *suffix, const char *code, byte symbol_pos, StringID name) :
CurrencySpec(uint16_t rate, const char *separator, Year to_euro, const char *prefix, const char *suffix, const char *code, byte symbol_pos, StringID name) :
rate(rate), separator(separator), to_euro(to_euro), prefix(prefix), suffix(suffix), code(code), symbol_pos(symbol_pos), name(name)
{
}
@ -102,7 +102,7 @@ extern CurrencySpec _currency_specs[CURRENCY_END];
#define _custom_currency (_currency_specs[CURRENCY_CUSTOM])
#define _currency ((const CurrencySpec*)&_currency_specs[GetGameSettings().locale.currency])
uint64 GetMaskOfAllowedCurrencies();
uint64_t GetMaskOfAllowedCurrencies();
void CheckSwitchToEuro();
void ResetCurrencies(bool preserve_custom = true);
byte GetNewgrfCurrencyIdConverted(byte grfcurr_id);

@ -26,19 +26,19 @@
#include "safeguards.h"
YearMonthDay _cur_date_ymd; ///< Current date as YearMonthDay struct
Date _date; ///< Current date in days (day counter)
DateFract _date_fract; ///< Fractional part of the day.
uint64 _tick_counter; ///< Ever incrementing tick counter for setting off various events
uint8 _tick_skip_counter; ///< Counter for ticks, when only vehicles are moving and nothing else happens
uint64 _scaled_tick_counter; ///< Tick counter in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks; ///< Date as ticks in daylength-scaled ticks
YearMonthDay _cur_date_ymd; ///< Current date as YearMonthDay struct
Date _date; ///< Current date in days (day counter)
DateFract _date_fract; ///< Fractional part of the day.
uint64_t _tick_counter; ///< Ever incrementing tick counter for setting off various events
uint8_t _tick_skip_counter; ///< Counter for ticks, when only vehicles are moving and nothing else happens
uint64_t _scaled_tick_counter; ///< Tick counter in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks; ///< Date as ticks in daylength-scaled ticks
DateTicksScaled _scaled_date_ticks_offset; ///< Offset to add when generating _scaled_date_ticks
uint32 _quit_after_days; ///< Quit after this many days of run time
uint32_t _quit_after_days; ///< Quit after this many days of run time
YearMonthDay _game_load_cur_date_ymd;
DateFract _game_load_date_fract;
uint8 _game_load_tick_skip_counter;
uint8_t _game_load_tick_skip_counter;
extern void ClearOutOfDateSignalSpeedRestrictions();
@ -46,12 +46,12 @@ void CheckScaledDateTicksWrap()
{
DateTicksScaledDelta tick_adjust = 0;
auto get_tick_adjust = [&](DateTicksScaled target) {
int32 rounding = _settings_time.time_in_minutes * 1440;
int32_t rounding = _settings_time.time_in_minutes * 1440;
return target.AsDelta() - (target.base() % rounding);
};
if (_scaled_date_ticks >= ((int64)1 << 60)) {
if (_scaled_date_ticks >= ((int64_t)1 << 60)) {
tick_adjust = get_tick_adjust(_scaled_date_ticks);
} else if (_scaled_date_ticks <= -((int64)1 << 60)) {
} else if (_scaled_date_ticks <= -((int64_t)1 << 60)) {
tick_adjust = -get_tick_adjust(-(_scaled_date_ticks.base()));
} else {
return;
@ -104,11 +104,11 @@ void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks)
void SetScaledTickVariables()
{
_scaled_date_ticks = ((int64)(DateToDateTicks(_date, _date_fract).base()) * _settings_game.economy.day_length_factor) + _tick_skip_counter + _scaled_date_ticks_offset;
_scaled_date_ticks = ((int64_t)(DateToDateTicks(_date, _date_fract).base()) * _settings_game.economy.day_length_factor) + _tick_skip_counter + _scaled_date_ticks_offset;
}
#define M(a, b) ((a << 5) | b)
static const uint16 _month_date_from_year_day[] = {
static const uint16_t _month_date_from_year_day[] = {
M( 0, 1), M( 0, 2), M( 0, 3), M( 0, 4), M( 0, 5), M( 0, 6), M( 0, 7), M( 0, 8), M( 0, 9), M( 0, 10), M( 0, 11), M( 0, 12), M( 0, 13), M( 0, 14), M( 0, 15), M( 0, 16), M( 0, 17), M( 0, 18), M( 0, 19), M( 0, 20), M( 0, 21), M( 0, 22), M( 0, 23), M( 0, 24), M( 0, 25), M( 0, 26), M( 0, 27), M( 0, 28), M( 0, 29), M( 0, 30), M( 0, 31),
M( 1, 1), M( 1, 2), M( 1, 3), M( 1, 4), M( 1, 5), M( 1, 6), M( 1, 7), M( 1, 8), M( 1, 9), M( 1, 10), M( 1, 11), M( 1, 12), M( 1, 13), M( 1, 14), M( 1, 15), M( 1, 16), M( 1, 17), M( 1, 18), M( 1, 19), M( 1, 20), M( 1, 21), M( 1, 22), M( 1, 23), M( 1, 24), M( 1, 25), M( 1, 26), M( 1, 27), M( 1, 28), M( 1, 29),
M( 2, 1), M( 2, 2), M( 2, 3), M( 2, 4), M( 2, 5), M( 2, 6), M( 2, 7), M( 2, 8), M( 2, 9), M( 2, 10), M( 2, 11), M( 2, 12), M( 2, 13), M( 2, 14), M( 2, 15), M( 2, 16), M( 2, 17), M( 2, 18), M( 2, 19), M( 2, 20), M( 2, 21), M( 2, 22), M( 2, 23), M( 2, 24), M( 2, 25), M( 2, 26), M( 2, 27), M( 2, 28), M( 2, 29), M( 2, 30), M( 2, 31),
@ -140,7 +140,7 @@ enum DaysTillMonth {
};
/** Number of days to pass from the first day in the year before reaching the first of a month. */
static const uint16 _accum_days_for_month[] = {
static const uint16_t _accum_days_for_month[] = {
ACCUM_JAN, ACCUM_FEB, ACCUM_MAR, ACCUM_APR,
ACCUM_MAY, ACCUM_JUN, ACCUM_JUL, ACCUM_AUG,
ACCUM_SEP, ACCUM_OCT, ACCUM_NOV, ACCUM_DEC,
@ -160,7 +160,7 @@ YearMonthDay ConvertDateToYMD(Date date)
/* There are 97 leap years in 400 years */
Year yr = 400 * (date.base() / (DAYS_IN_YEAR * 400 + 97));
int rem = date.base() % (DAYS_IN_YEAR * 400 + 97);
uint16 x;
uint16_t x;
if (rem >= DAYS_IN_YEAR * 100 + 25) {
/* There are 25 leap years in the first 100 years after
@ -270,7 +270,7 @@ static void OnNewYear()
LinkGraphSchedule::instance.ShiftDates(-days_this_year);
ShiftOrderDates(-days_this_year);
ShiftVehicleDates(-days_this_year);
_scaled_date_ticks_offset += ((int64)days_this_year) * (DAY_TICKS * _settings_game.economy.day_length_factor);
_scaled_date_ticks_offset += ((int64_t)days_this_year) * (DAY_TICKS * _settings_game.economy.day_length_factor);
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
* all of them if the date is set back, else those messages will hang for ever */
@ -369,7 +369,7 @@ void IncreaseDate()
if (new_year) OnNewYear();
}
const char *debug_date_dumper::HexDate(Date date, DateFract date_fract, uint8 tick_skip_counter)
const char *debug_date_dumper::HexDate(Date date, DateFract date_fract, uint8_t tick_skip_counter)
{
seprintf(this->buffer, lastof(this->buffer), "date{%08x; %02x; %02x}", date.base(), date_fract, tick_skip_counter);
return this->buffer;

@ -17,16 +17,16 @@
extern YearMonthDay _cur_date_ymd;
extern Date _date;
extern DateFract _date_fract;
extern uint64 _tick_counter;
extern uint8 _tick_skip_counter;
extern uint64 _scaled_tick_counter;
extern uint64_t _tick_counter;
extern uint8_t _tick_skip_counter;
extern uint64_t _scaled_tick_counter;
extern DateTicksScaled _scaled_date_ticks;
extern DateTicksScaled _scaled_date_ticks_offset;
extern uint32 _quit_after_days;
extern uint32_t _quit_after_days;
extern YearMonthDay _game_load_cur_date_ymd;
extern DateFract _game_load_date_fract;
extern uint8 _game_load_tick_skip_counter;
extern uint8_t _game_load_tick_skip_counter;
void SetDate(Date date, DateFract fract, bool preserve_scaled_ticks = true);
YearMonthDay ConvertDateToYMD(Date date);
@ -57,7 +57,7 @@ inline Date ScaledDateTicksToDate(DateTicksScaled ticks)
inline DateTicksScaled DateToScaledDateTicks(Date date)
{
return ((int64)date.base() * DAY_TICKS * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset.base();
return ((int64_t)date.base() * DAY_TICKS * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset.base();
}
inline DateTicks ScaledDateTicksToDateTicks(DateTicksScaled ticks)
@ -67,7 +67,7 @@ inline DateTicks ScaledDateTicksToDateTicks(DateTicksScaled ticks)
inline DateTicksScaled DateTicksToScaledDateTicks(DateTicks date_ticks)
{
return ((int64)date_ticks.base() * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset.base();
return ((int64_t)date_ticks.base() * _settings_game.economy.day_length_factor) + _scaled_date_ticks_offset.base();
}
/**
@ -101,7 +101,7 @@ inline DateTicks NowDateTicks()
}
struct debug_date_dumper {
const char *HexDate(Date date, DateFract date_fract, uint8 tick_skip_counter);
const char *HexDate(Date date, DateFract date_fract, uint8_t tick_skip_counter);
inline const char *HexDate() { return this->HexDate(_date, _date_fract, _tick_skip_counter); }

@ -61,7 +61,7 @@ struct SetDateWindow : Window {
this->date.year = Clamp(this->date.year, min_year, max_year);
}
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
{
Point pt = { this->parent->left + this->parent->width / 2 - sm_width / 2, this->parent->top + this->parent->height / 2 - sm_height / 2 };
return pt;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save