2014-04-05 21:22:36 +02:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2005-2012 Gekko Emulator
|
|
|
|
*
|
|
|
|
* @file common_types.h
|
|
|
|
* @author ShizZy <shizzy247@gmail.com>
|
|
|
|
* @date 2012-02-11
|
|
|
|
* @brief Common types used throughout the project
|
|
|
|
*
|
|
|
|
* @section LICENSE
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details at
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* Official project repository can be found at:
|
|
|
|
* http://code.google.com/p/gekko-gc-emu/
|
|
|
|
*/
|
2013-09-05 02:17:46 +02:00
|
|
|
|
2014-11-19 09:49:13 +01:00
|
|
|
#pragma once
|
2013-09-05 02:17:46 +02:00
|
|
|
|
2014-08-17 19:45:50 +02:00
|
|
|
#include <cmath>
|
2014-10-23 02:43:15 +02:00
|
|
|
#include <cstdint>
|
2015-01-05 16:05:28 +01:00
|
|
|
#include <cstdlib>
|
2014-04-05 21:47:55 +02:00
|
|
|
|
2014-10-23 02:43:15 +02:00
|
|
|
typedef std::uint8_t u8; ///< 8-bit unsigned byte
|
|
|
|
typedef std::uint16_t u16; ///< 16-bit unsigned short
|
|
|
|
typedef std::uint32_t u32; ///< 32-bit unsigned word
|
|
|
|
typedef std::uint64_t u64; ///< 64-bit unsigned int
|
2013-09-05 02:17:46 +02:00
|
|
|
|
2014-10-23 02:43:15 +02:00
|
|
|
typedef std::int8_t s8; ///< 8-bit signed byte
|
|
|
|
typedef std::int16_t s16; ///< 16-bit signed short
|
|
|
|
typedef std::int32_t s32; ///< 32-bit signed word
|
|
|
|
typedef std::int64_t s64; ///< 64-bit signed int
|
2013-09-05 02:17:46 +02:00
|
|
|
|
2014-10-23 02:43:15 +02:00
|
|
|
typedef float f32; ///< 32-bit floating point
|
|
|
|
typedef double f64; ///< 64-bit floating point
|
2014-04-05 21:22:36 +02:00
|
|
|
|
|
|
|
/// Union for fast 16-bit type casting
|
|
|
|
union t16 {
|
2014-11-19 10:02:05 +01:00
|
|
|
u8 _u8[2]; ///< 8-bit unsigned char(s)
|
|
|
|
u16 _u16; ///< 16-bit unsigned shorts(s)
|
2014-04-05 21:22:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Union for fast 32-bit type casting
|
|
|
|
union t32 {
|
|
|
|
f32 _f32; ///< 32-bit floating point(s)
|
|
|
|
u32 _u32; ///< 32-bit unsigned int(s)
|
|
|
|
s32 _s32; ///< 32-bit signed int(s)
|
|
|
|
u16 _u16[2]; ///< 16-bit unsigned shorts(s)
|
|
|
|
u8 _u8[4]; ///< 8-bit unsigned char(s)
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Union for fast 64-bit type casting
|
|
|
|
union t64 {
|
|
|
|
f64 _f64; ///< 64-bit floating point
|
|
|
|
u64 _u64; ///< 64-bit unsigned long
|
|
|
|
f32 _f32[2]; ///< 32-bit floating point(s)
|
|
|
|
u32 _u32[2]; ///< 32-bit unsigned int(s)
|
|
|
|
s32 _s32[2]; ///< 32-bit signed int(s)
|
|
|
|
u16 _u16[4]; ///< 16-bit unsigned shorts(s)
|
|
|
|
u8 _u8[8]; ///< 8-bit unsigned char(s)
|
|
|
|
};
|
|
|
|
|
2014-09-07 20:51:10 +02:00
|
|
|
namespace Common {
|
2014-04-05 21:22:36 +02:00
|
|
|
/// Rectangle data structure
|
2014-05-20 02:57:35 +02:00
|
|
|
class Rect {
|
2014-04-05 21:22:36 +02:00
|
|
|
public:
|
2014-05-20 02:57:35 +02:00
|
|
|
Rect(int x0=0, int y0=0, int x1=0, int y1=0) {
|
2014-04-05 21:22:36 +02:00
|
|
|
x0_ = x0;
|
|
|
|
y0_ = y0;
|
|
|
|
x1_ = x1;
|
|
|
|
y1_ = y1;
|
|
|
|
}
|
2014-05-20 02:57:35 +02:00
|
|
|
~Rect() { }
|
2014-04-05 21:22:36 +02:00
|
|
|
|
|
|
|
int x0_; ///< Rect top left X-coordinate
|
|
|
|
int y0_; ///< Rect top left Y-coordinate
|
|
|
|
int x1_; ///< Rect bottom left X-coordinate
|
|
|
|
int y1_; ///< Rect bottom right Y-coordinate
|
|
|
|
|
2015-01-05 16:05:28 +01:00
|
|
|
inline u32 width() const { return std::abs(x1_ - x0_); }
|
|
|
|
inline u32 height() const { return std::abs(y1_ - y0_); }
|
2014-04-05 21:22:36 +02:00
|
|
|
|
2014-05-20 02:57:35 +02:00
|
|
|
inline bool operator == (const Rect& val) const {
|
2014-04-05 21:22:36 +02:00
|
|
|
return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_);
|
|
|
|
}
|
|
|
|
};
|
2014-05-20 02:57:35 +02:00
|
|
|
}
|