Blender V2.61 - r43446
|
00001 00004 /* Copyright (c) 1999, Not a Number / NeoGeo b.v. 00005 * 00006 * All rights reserved. 00007 * 00008 * Contact: info@blender.org 00009 * Information: http://www.blender.org 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions 00013 * are met: 00014 * 1. Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright 00017 * notice, this list of conditions and the following disclaimer in the 00018 * documentation and/or other materials provided with the distribution. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00024 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00025 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00026 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00027 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00028 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00029 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 */ 00032 00033 #ifndef UTIL_H 00034 #define UTIL_H 00035 00036 #include <sys/types.h> 00037 #include <stdlib.h> 00038 #include <string.h> 00039 #include "externdef.h" 00040 00041 #ifndef NULL 00042 #define NULL 0 00043 #endif 00044 00045 #ifndef FALSE 00046 #define FALSE 0 00047 #endif 00048 00049 #ifndef TRUE 00050 #define TRUE 1 00051 #endif 00052 00053 #ifndef ulong 00054 #define ulong unsigned long 00055 #endif 00056 00057 #ifndef ushort 00058 #define ushort unsigned short 00059 #endif 00060 00061 #ifndef uchar 00062 #define uchar unsigned char 00063 #endif 00064 00065 #ifndef uint 00066 #define uint unsigned int 00067 #endif 00068 00069 #define MIN2(x,y) ( (x)<(y) ? (x) : (y) ) 00070 #define MIN3(x,y,z) MIN2( MIN2((x),(y)) , (z) ) 00071 #define MIN4(x,y,z,a) MIN2( MIN2((x),(y)) , MIN2((z),(a)) ) 00072 00073 #define MAX2(x,y) ( (x)>(y) ? (x) : (y) ) 00074 #define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) ) 00075 #define MAX4(x,y,z,a) MAX2( MAX2((x),(y)) , MAX2((z),(a)) ) 00076 00077 #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } 00078 00079 #define ABS(x) ((x) < 0 ? -(x) : (x)) 00080 #define FLOOR(x) ((int)(x) - ((x) < 0 && (x) != (int)(x))) 00081 #define CEIL(x) ((int)(x) + ((x) > 0 && (x) != (int)(x))) 00082 #define STEP(a,b) ( (a)>(b) ? (1) : (0) ) 00083 #define CLAMP(val, low, high) ((val>high)?high:((val<low)?low:val)) 00084 #define LERP(t,x0,x1) ((x0) + (t)*((x1)-(x0))) 00085 #define PULSE(a,b,x) (STEP((a),(x)) - STEP((b),(x))) 00086 #define BOXSTEP(a,b,x) CLAMP(((x)-(a))/((b)-(a)),0,1) 00087 00088 #define PRINT(d, var1) printf(# var1 ":%" # d "\n", var1) 00089 #define PRINT2(d, e, var1, var2) printf(# var1 ":%" # d " " # var2 ":%" # e "\n", var1, var2) 00090 #define PRINT3(d, e, f, var1, var2, var3) printf(# var1 ":%" # d " " # var2 ":%" # e " " # var3 ":%" # f "\n", var1, var2, var3) 00091 #define PRINT4(d, e, f, g, var1, var2, var3, var4) printf(# var1 ":%" # d " " # var2 ":%" # e " " # var3 ":%" # f " " # var4 ":%" # g "\n", var1, var2, var3, var4) 00092 00093 LIBEXPORT void *mallocN(int len, char *str); 00094 LIBEXPORT void *callocN(int len, char *str); 00095 LIBEXPORT short freeN(void *vmemh); 00096 00097 LIBEXPORT void *mallocT(int len, char *str); 00098 LIBEXPORT void *callocT(int len, char *str); 00099 LIBEXPORT void freeT(void *vmemh); 00100 00101 #endif /* UTIL_H */ 00102