enginePrimitives.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _ENGINEPRIMITIVES_H_
  23. #define _ENGINEPRIMITIVES_H_
  24. #ifndef _ENGINETYPES_H_
  25. #include "console/engineTypes.h"
  26. #endif
  27. #include "math/mPlane.h"
  28. #include "math/mPolyhedron.h"
  29. /// @file
  30. /// Definitions for the core primitive types used in the
  31. /// exposed engine API.
  32. DECLARE_PRIMITIVE_R( bool );
  33. DECLARE_PRIMITIVE_R(S8);
  34. DECLARE_PRIMITIVE_R(U8);
  35. DECLARE_PRIMITIVE_R(S16);
  36. DECLARE_PRIMITIVE_R(U16);
  37. DECLARE_PRIMITIVE_R(S32);
  38. DECLARE_PRIMITIVE_R(U32);
  39. DECLARE_PRIMITIVE_R(F32);
  40. DECLARE_PRIMITIVE_R(F64);
  41. DECLARE_PRIMITIVE_R(U64);
  42. DECLARE_PRIMITIVE_R(S64);
  43. DECLARE_PRIMITIVE_R(void*);
  44. DECLARE_PRIMITIVE_R(bool*);
  45. DECLARE_PRIMITIVE_R(U8*);
  46. DECLARE_PRIMITIVE_R(S32*);
  47. DECLARE_PRIMITIVE_R(U32*);
  48. DECLARE_PRIMITIVE_R(F32*);
  49. DECLARE_PRIMITIVE_R(Point3F*);
  50. DECLARE_PRIMITIVE_R(PlaneF*);
  51. DECLARE_PRIMITIVE_R(PolyhedronData::Edge*);
  52. DECLARE_PRIMITIVE_R(const char**);
  53. //FIXME: this allows String to be used as a struct field type
  54. // String is special in the way its data is exchanged through the API. Through
  55. // calls, strings are passed as plain, null-terminated UTF-8 character strings.
  56. // In addition, strings passed back as return values from engine API functions
  57. // are considered to be owned by the API layer itself. The rule here is that such
  58. // a string is only valid until the next API call is made. Usually, control layers
  59. // will immediately copy and convert strings to their own string type.
  60. _DECLARE_TYPE_R(String);
  61. template<>
  62. struct EngineTypeTraits< String > : public _EnginePrimitiveTypeTraits< String >
  63. {
  64. typedef const UTF8* ArgumentValueType;
  65. typedef const UTF8* ReturnValueType;
  66. //FIXME: this needs to be sorted out; for now, we store default value literals in ASCII
  67. typedef const char* DefaultArgumentValueStoreType;
  68. static const UTF8* ReturnValue( const String& str )
  69. {
  70. static String sTemp;
  71. sTemp = str;
  72. return sTemp.utf8();
  73. }
  74. };
  75. // For struct fields, String cannot be used directly but "const UTF16*" must be used
  76. // instead. Make sure this works with the template machinery by redirecting the type
  77. // back to String.
  78. template<> struct EngineTypeTraits< const UTF16* > : public EngineTypeTraits< String > {};
  79. template<> inline const EngineTypeInfo* TYPE< const UTF16* >() { return TYPE< String >(); }
  80. inline const EngineTypeInfo* TYPE( const UTF16*& ) { return TYPE< String >(); }
  81. // Temp support for allowing const char* to remain in the API functions as long as we
  82. // still have the console system around. When that is purged, these definitions should
  83. // be deleted and all const char* uses be replaced with String.
  84. _DECLARE_TYPE_R(const UTF8*);
  85. template<>
  86. struct EngineTypeTraits< const UTF8* > : public _EnginePrimitiveTypeTraits< const UTF8* >
  87. {
  88. static const UTF8* ReturnValue(const String& str)
  89. {
  90. static String sTemp;
  91. sTemp = str;
  92. return sTemp.utf8();
  93. }
  94. };
  95. #endif // !_ENGINEPRIMITIVES_H_