Sirikata
|
00001 /* Sirikata 00002 * Utility.hpp 00003 * 00004 * Copyright (c) 2010, Behram Mistree 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are 00009 * met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the name of Sirikata nor the names of its contributors may 00017 * be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00021 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00023 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00024 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #include <sirikata/core/util/Platform.hpp> 00034 #include <iostream> 00035 #include <iomanip> 00036 #include <string> 00037 #if SIRIKATA_PLATFORM != SIRIKATA_PLATFORM_WINDOWS 00038 #include <stdint.h> 00039 #endif 00040 00041 #ifndef __UTILITY_HPP__ 00042 #define __UTILITY_HPP__ 00043 00044 #define PI 3.14159 00045 00046 #define DEGREES_TO_RADIANS PI/180.0 00047 00048 namespace Sirikata 00049 { 00050 00051 00052 typedef int64 ObjID; 00053 typedef int BlockID; 00054 typedef int64 CacheTimeMS; 00055 00056 00057 const static int NullVecIndex = -1; 00058 const static BlockID NullBlockID = -1; 00059 const static ObjID NullObjID = -1; 00060 00061 const static CacheTimeMS TIME_MS_INFINITY_TIME = 10000000; //not really infinity, but will do for our purposes for now. 00062 const int TIMEVAL_SECOND_TO_US = 1000000; 00063 CacheTimeMS convertTimeToAge(const struct timeval& tv); 00064 00065 double getUniform(double min, double max); 00066 double getUniform(); 00067 double b_abval(double a); 00068 double mdifftime(const struct timeval &newest, const struct timeval& oldest); 00069 double normalGaussianPDF(double val); 00070 00071 double mavg(double a, double b); 00072 float mavg(float a, float b); 00073 00074 double findScalingAutoRange(double target, double meterRange, double (*fallOffFunction)(double radius, double scaling)); 00075 float findScalingAutoRange(float target, float meterRange, float (*fallOffFunction)(float radius, float scaling)); 00076 double findScaling(double target,double low, double high, double meterRange, double (*fallOffFunction)(double radius, double scaling)); 00077 float findScaling(float target,float low, float high, float meterRange, float (*fallOffFunction)(float radius, float scaling)); 00078 00079 enum ObjType {NullObjType, OBJ_TYPE_STATIC, OBJ_TYPE_MOBILE_RANDOM, OBJ_TYPE_QUAKE_TRACE, OBJ_TYPE_SL_TRACE}; 00080 00081 } 00082 00083 #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_WINDOWS 00084 #define PTR_AS_INT(X) ((uint64)X) 00085 #else 00086 #define PTR_AS_INT(X) ((uintptr_t)X) 00087 #endif 00088 00089 #endif