mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
This commit is contained in:
parent
d73d12ae8a
commit
45ca3b6336
4
gfx.c
4
gfx.c
@ -1755,8 +1755,8 @@ void RedrawScreenRect(int left, int top, int right, int bottom)
|
||||
void DrawDirtyBlocks(void)
|
||||
{
|
||||
byte *b = _dirty_blocks;
|
||||
const int w = (_screen.width + 63) & ~63;
|
||||
const int h = (_screen.height + 7) & ~7;
|
||||
const int w = ALIGN(_screen.width, 64);
|
||||
const int h = ALIGN(_screen.height, 8);
|
||||
int x;
|
||||
int y;
|
||||
|
||||
|
6
macros.h
6
macros.h
@ -158,6 +158,12 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
|
||||
#define ROL(x, n) ((x) << (n) | (x) >> (sizeof(x) * 8 - (n)))
|
||||
#define ROR(x, n) ((x) >> (n) | (x) << (sizeof(x) * 8 - (n)))
|
||||
|
||||
/**
|
||||
* Return the smallest multiple of n equal or greater than x
|
||||
* @note n must be a power of 2
|
||||
*/
|
||||
#define ALIGN(x, n) (((x) + (n) - 1) & ~((n) - 1))
|
||||
|
||||
/* IS_INT_INSIDE = filter for ascii-function codes like BELL and so on [we need an special filter here later] */
|
||||
static inline bool IsValidAsciiChar(byte key)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
|
||||
if (f == NULL) return false;
|
||||
|
||||
// each scanline must be aligned on a 32bit boundary
|
||||
padw = (w + 3) & ~3;
|
||||
padw = ALIGN(w, 4);
|
||||
|
||||
// setup the file header
|
||||
bfh.type = TO_LE16('MB');
|
||||
|
@ -50,7 +50,7 @@ static void *pool_alloc(SettingsMemoryPool **pool, uint size)
|
||||
uint pos;
|
||||
SettingsMemoryPool *p = *pool;
|
||||
|
||||
size = (size + 3) & ~3; // align everything to a 32 bit boundary
|
||||
size = ALIGN(size, 4); // align everything to a 32 bit boundary
|
||||
|
||||
// first check if there's memory in the next pool
|
||||
if (p->next && p->next->pos + size <= p->next->size) {
|
||||
|
@ -536,7 +536,7 @@ static bool AllocateDibSection(int w, int h)
|
||||
return false;
|
||||
|
||||
_screen.width = w;
|
||||
_screen.pitch = (w + 3) & ~0x3;
|
||||
_screen.pitch = ALIGN(w, 4);
|
||||
_screen.height = h;
|
||||
|
||||
if (_wnd.alloced_bits) {
|
||||
@ -549,7 +549,7 @@ static bool AllocateDibSection(int w, int h)
|
||||
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
|
||||
if (_wnd.double_size) {
|
||||
w = (w + 3) & ~0x3;
|
||||
w = ALIGN(w, 4);
|
||||
_wnd.alloced_bits = _wnd.buffer_bits = malloc(w * h);
|
||||
w *= 2;
|
||||
h *= 2;
|
||||
|
Loading…
Reference in New Issue
Block a user