common_types.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (C) 2005-2012 Gekko Emulator
  3. *
  4. * @file common_types.h
  5. * @author ShizZy <shizzy247@gmail.com>
  6. * @date 2012-02-11
  7. * @brief Common types used throughout the project
  8. *
  9. * @section LICENSE
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details at
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * Official project repository can be found at:
  22. * http://code.google.com/p/gekko-gc-emu/
  23. */
  24. #pragma once
  25. #include <cmath>
  26. #include <cstdint>
  27. #include <cstdlib>
  28. typedef std::uint8_t u8; ///< 8-bit unsigned byte
  29. typedef std::uint16_t u16; ///< 16-bit unsigned short
  30. typedef std::uint32_t u32; ///< 32-bit unsigned word
  31. typedef std::uint64_t u64; ///< 64-bit unsigned int
  32. typedef std::int8_t s8; ///< 8-bit signed byte
  33. typedef std::int16_t s16; ///< 16-bit signed short
  34. typedef std::int32_t s32; ///< 32-bit signed word
  35. typedef std::int64_t s64; ///< 64-bit signed int
  36. typedef float f32; ///< 32-bit floating point
  37. typedef double f64; ///< 64-bit floating point
  38. /// Union for fast 16-bit type casting
  39. union t16 {
  40. u8 _u8[2]; ///< 8-bit unsigned char(s)
  41. u16 _u16; ///< 16-bit unsigned shorts(s)
  42. };
  43. /// Union for fast 32-bit type casting
  44. union t32 {
  45. f32 _f32; ///< 32-bit floating point(s)
  46. u32 _u32; ///< 32-bit unsigned int(s)
  47. s32 _s32; ///< 32-bit signed int(s)
  48. u16 _u16[2]; ///< 16-bit unsigned shorts(s)
  49. u8 _u8[4]; ///< 8-bit unsigned char(s)
  50. };
  51. /// Union for fast 64-bit type casting
  52. union t64 {
  53. f64 _f64; ///< 64-bit floating point
  54. u64 _u64; ///< 64-bit unsigned long
  55. f32 _f32[2]; ///< 32-bit floating point(s)
  56. u32 _u32[2]; ///< 32-bit unsigned int(s)
  57. s32 _s32[2]; ///< 32-bit signed int(s)
  58. u16 _u16[4]; ///< 16-bit unsigned shorts(s)
  59. u8 _u8[8]; ///< 8-bit unsigned char(s)
  60. };
  61. namespace Common {
  62. /// Rectangle data structure
  63. class Rect {
  64. public:
  65. Rect(int x0=0, int y0=0, int x1=0, int y1=0) {
  66. x0_ = x0;
  67. y0_ = y0;
  68. x1_ = x1;
  69. y1_ = y1;
  70. }
  71. ~Rect() { }
  72. int x0_; ///< Rect top left X-coordinate
  73. int y0_; ///< Rect top left Y-coordinate
  74. int x1_; ///< Rect bottom left X-coordinate
  75. int y1_; ///< Rect bottom right Y-coordinate
  76. inline u32 width() const { return std::abs(x1_ - x0_); }
  77. inline u32 height() const { return std::abs(y1_ - y0_); }
  78. inline bool operator == (const Rect& val) const {
  79. return (x0_ == val.x0_ && y0_ == val.y0_ && x1_ == val.x1_ && y1_ == val.y1_);
  80. }
  81. };
  82. }