25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

commandstack.h 3.2 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  5. // (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. #pragma once
  12. //
  13. // The CommandStack struct
  14. // ------------------
  15. //
  16. namespace lol
  17. {
  18. //Utility struct to convert command code to pseudo-bytecode
  19. struct CommandStack
  20. {
  21. private:
  22. array<int, int, int> m_commands;
  23. array<float> m_floats;
  24. array<int> m_ints;
  25. int m_f_cur;
  26. int m_i_cur;
  27. public:
  28. //GET/SET exec
  29. int GetCmdNb() { return m_commands.count(); }
  30. int GetCmd(int i)
  31. {
  32. ASSERT(0 <= i && i < m_commands.count());
  33. m_f_cur = m_commands[i].m2;
  34. m_i_cur = m_commands[i].m3;
  35. return m_commands[i].m1;
  36. }
  37. //cmd storage
  38. void AddCmd(int cmd) { m_commands.push(cmd, m_floats.count(), m_ints.count()); }
  39. //GETTER
  40. inline float F() { return m_floats[m_f_cur++]; }
  41. inline int I() { return m_ints[m_i_cur++]; }
  42. inline int E() { return I(); }
  43. inline bool B() { return !!I(); }
  44. inline vec2 V2() { vec2 v(F()); v.y = F(); return v; }
  45. inline vec3 V3() { vec3 v(V2(), 0.f); v.z = F(); return v; }
  46. inline vec4 V4() { vec4 v(V3(), 0.f); v.w = F(); return v; }
  47. inline ivec2 IV2() { ivec2 v(I()); v.y = I(); return v; }
  48. inline ivec3 IV3() { ivec3 v(IV2(), 0); v.z = I(); return v; }
  49. inline ivec4 IV4() { ivec4 v(IV3(), 0); v.w = I(); return v; }
  50. // Alternate getters
  51. inline void GetValue(float &f) { f = F(); }
  52. inline void GetValue(int &i) { i = I(); }
  53. inline void GetValue(bool &b) { b = B(); }
  54. inline void GetValue(vec2 &v2) { v2 = V2(); }
  55. inline void GetValue(vec3 &v3) { v3 = V3(); }
  56. inline void GetValue(vec4 &v4) { v4 = V4(); }
  57. inline void GetValue(ivec2 &iv2) { iv2 = IV2(); }
  58. inline void GetValue(ivec3 &iv3) { iv3 = IV3(); }
  59. inline void GetValue(ivec4 &iv4) { iv4 = IV4(); }
  60. // For Safe Enum
  61. template<class DEF> inline
  62. void GetValue(SafeEnum<DEF> &i) { i = typename DEF::Type(I()); }
  63. //SETTER
  64. CommandStack &operator<<(int i) { m_ints << i; return *this; }
  65. CommandStack &operator<<(float f) { m_floats << f; return *this; }
  66. CommandStack &operator<<(bool b) { return (*this << (int)b); }
  67. CommandStack &operator<<(vec2 v) { return (*this << v.x << v.y); }
  68. CommandStack &operator<<(vec3 v) { return (*this << v.xy << v.z); }
  69. CommandStack &operator<<(vec4 v) { return (*this << v.xyz << v.w); }
  70. CommandStack &operator<<(ivec2 iv) { return (*this << iv.x << iv.y); }
  71. CommandStack &operator<<(ivec3 iv) { return (*this << iv.xy << iv.z); }
  72. CommandStack &operator<<(ivec4 iv) { return (*this << iv.xyz << iv.w); }
  73. // For Safe Enum
  74. template<class DEF> inline
  75. CommandStack &operator<<(SafeEnum<DEF> &i) { return *this << i.ToScalar(); }
  76. };
  77. } /* namespace lol */