ccUtils.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /****************************************************************************
  2. Copyright (c) 2010 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  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 FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #pragma once
  23. #include <vector>
  24. #include <string>
  25. #include "base/ccMacros.h"
  26. /** @file ccUtils.h
  27. Misc free functions
  28. */
  29. NS_CC_BEGIN
  30. namespace
  31. {
  32. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
  33. #include <winsock.h>
  34. extern "C" int gettimeofday(struct timeval * val, void *);
  35. #endif
  36. }
  37. /*
  38. utils::nextPOT function is licensed under the same license that is used in Texture2D.m.
  39. */
  40. /** Returns the Next Power of Two value.
  41. Examples:
  42. - If "value" is 15, it will return 16.
  43. - If "value" is 16, it will return 16.
  44. - If "value" is 17, it will return 32.
  45. @param value The value to get next power of two.
  46. @return Returns the next power of two value.
  47. @since v0.99.5
  48. */
  49. namespace utils
  50. {
  51. CC_DLL int nextPOT(int x);
  52. /** Same to ::atof, but strip the string, remain 7 numbers after '.' before call atof.
  53. * Why we need this? Because in android c++_static, atof ( and std::atof ) is unsupported for numbers have long decimal part and contain
  54. * several numbers can approximate to 1 ( like 90.099998474121094 ), it will return inf. This function is used to fix this bug.
  55. * @param str The string be to converted to double.
  56. * @return Returns converted value of a string.
  57. */
  58. CC_DLL double atof(const char* str);
  59. /** Get current exact time, accurate to nanoseconds.
  60. * @return Returns the time in seconds since the Epoch.
  61. */
  62. CC_DLL double gettime();
  63. /**
  64. * Get current time in milliseconds, accurate to nanoseconds
  65. *
  66. * @return Returns the time in milliseconds since the Epoch.
  67. */
  68. CC_DLL long long getTimeInMilliseconds();
  69. }
  70. NS_CC_END